Install Shield Script Summary (Invoke Api,com,bat)

Source: Internet
Author: User
Tags rar
Install Shield Script Summary (Invoke Api,com,bat)
Boss asked me to package the current project (Web project) on the basis of the previous packaging program. The basic requirement is this, with the project including the required control, build the virtual directory. If the user can configure a row on SQL Server, or install the SQLExpress in the package (if the user is configured to fail to connect and to determine if SQL Server is not installed within the machine, install package sqlexpress), a week's work has been done to share the learning. Grammar mainly look at that tutorial can be, function directly F1

Basic information:
INSTALLSHIELDX installation of the production of essays. rar
Installshieldjc.rar

Then InstallShield and help, recommend it to the official forum http://community.installshield.com/

1. Invoke WinAPI method with InstallShield script
such as to obtain the user name of the machine login. Msdn
GetUserName

The getusername function retrieves the name of the user associated with the current thread.

Use the GetUserNameEx function to retrieve the user name in a specified format. Additional information is provided by the <?xml:namespace prefix = mshelp/> iadsadsysteminfo.

BOOL GetUserName (
LPTSTR ,
Lpdword
);
.......
Dll Requires Advapi32.dll.
Unicode

Implemented as Getusernamew (Unicode) and GetUserNameA (ANSI). Note This Unicode support on Windows me/98/95 requires Microsoft Layer for Unicode.

.......
Reference to the function type declaration in the installshieldjc.rar corresponding to the WINAPI in the API function signature, the following declaration is used: prototype BOOL Advapi32.getusernamea (BYREF STRING, BYREF number);
function Onbegin ()
STRING strLogonUser;
Number Numlogonuser
Begin
// .
Numlogonuser = 255;
GetUserNameA (strLogonUser, Numlogonuser);
MessageBox (strlogonuser,information);
// .
End

2. Invoke other COM with InstallShield script
Example 1: Using DOM
Prototype Writeconfig (STRING);
function Writeconfig (info)
STRING FileName;
OBJECT Configdoc, Child1,child2;
Begin
Set Configdoc = Cocreateobject ("MSXML". DOMDocument ");
FileName = INSTALLDIR ^ "Oceswebs//web.config";
MessageBox (filename,information);
If Configdoc.load (fileName) Then
Set child1 = Configdoc.selectsinglenode ("//configuration/appsettings/add[@key = ' connectionstringforprovince ']/@ Value ");
Set child2 = Configdoc.selectsinglenode ("//configuration/connectionstrings/add[@name = ' Connectionstringforprovince ']/@connectionString ");
Child1.text = info;
Child2.text = info;

MessageBox (child.text,information);
Else
MessageBox ("web.config config file not found", information);
endif
Configdoc.save (FileName);
Set configdoc = Nothing;
End; Use Set Configdoc = Cocreateobject ("MSXML". DOMDocument "); After creating an object, you can easily manipulate XML through XPath
Example 2: Using ADO:

Test Database connection Methods
Parameters: SERVERNAME, server name
dbname, database name
Dbuser User Name
PWD, login password
Athmode login mode 0 for SQL login mode, 1 for Windows Verify login mode
return value-1, cannot connect to SQL Server
Return value 0 connection to SQL Server but no this database
return value 1 Connect SQL Server coexist in this database
#ifndef CONNDB
#define CONNDB 1
Prototype CONNDB (String,string,string,string,number);
function number Conndb (Servername,dbname,dbuser,pwd,athmode)
OBJECT oadocnn, oadors;
STRING svcnn, Svsql;
Number Nvreturn, Nvsize, Nvfilehandle;
STRING Svresult, szpath, szFileName, Svbuffer, sztmp;
STRING Gssqlserver, Gssqluid, Gssqlpass, Gssqldbname;
BOOL Gbwindowslogin;
Begin

Gssqlserver = "192.168.75.80";
Gssqldbname= "Solotemp";
Gssqluid = "sa";
Gssqlpass = "Iflyecl";
Gssqlserver = SERVERNAME;
Gssqldbname = dbname;
Gssqluid = Dbuser;
Gssqlpass = PWD;
Gbwindowslogin = Athmode;

if (Gbwindowslogin = TRUE) Then
SVCNN = "provider=sqloledb.1;integrated security=sspi; Persist Security Info=false; User id= ";
SVCNN = svcnn + Gssqluid + "; Initial catalog=master;data source=" + gssqlserver;
Else
SVCNN = "Provider=SQLOLEDB.1; Password= "+ Gssqlpass +"; Persist Security info=true; User id= ";
SVCNN = svcnn + Gssqluid + "; Initial catalog=master;data source=" + gssqlserver;
endif
Login to the master database

Try
Set oadocnn = CreateObject ("ADODB. Connection ");
Catch
MessageBox ("Error:" + Err.Description, WARNING);
Nvreturn =-1;
return nvreturn;
Endcatch;

Oadocnn.connectiontimeout = 32;
Oadocnn.commandtimeout = 8;
Oadocnn.cursorlocation = 3; adUseClient
Try
Oadocnn.open (SVCNN);
Catch
MessageBox ("Error:" + Err.Description, WARNING);
Nvreturn =-1;
return nvreturn;
Endcatch;
Oadocnn.commandtimeout = 8;
Oadocnn.cursorlocation = 3; adUseClient

adOpenDynamic =2, adOpenForwardOnly =0
adLockReadOnly =1, adLockOptimistic =3

Svsql = "SELECT * from sysdatabases where [name] = N '" + gssqldbname + "'";
MessageBox (svsql,information);
Set oadors = Oadocnn.execute (Svsql);
if (! Oadors.bof) Then
MessageBox ("Database" + Gssqldbname + "exists", WARNING);
Nvreturn = 1;
Else
MessageBox ("Database" + gssqldbname + "does not exists,go in to creat it", information);
Nvreturn = 0;
endif
Set oadors = NULL;

Oadocnn.close ();
Set oadocnn = NULL;
return nvreturn;

End 3. Call Batch bat:
SMSG = "Excute Configure file and SQL.";
Sdshowmsg (SMSG, TRUE);
result = result + launchappandwait (INSTALLDIR ^ "Component//config.bat", "", laaw_option_wait | Laaw_option_hidden);
sCmdLine = sServerName + "/" "+ susername+"/"/" "+ spwd+"/"";
result = result + launchappandwait (INSTALLDIR ^ "Component//setup2.bat", scmdline,laaw_option_wait | Laaw_option_hidden);
Sdsho

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.