installshield安装程序,包括Mysql初始化、安装jre、配置环境变量、简单注册码生成

C代码
////////////////////////////////////////////////////////////////////////////////  
//                                                                             
//  File Name: Setup.rul                                                    
//                                                                             
//  Description: InstallShield script                                         
//                                                                             
//  Comments: This script was generated based on the selections you made in  
//            the Project Wizard.  Refer to the help topic entitled "Modify       
//            the script that the Project Wizard generates" for information  
//    on possible next steps.  
//  
/////////////////////////////////////////////an///////////////////////////////////  
 
// Include header files  
     
#include "ifx.h"  
     
////////////////////// string defines ////////////////////////////  
//////////////////// installation declarations ///////////////////  
// ----- DLL function prototypes -----  
 
    // your DLL function prototypes  
 
// ---- script function prototypes -----  
 
    // your script function prototypes  
    // your global variables  
   
NUMBER volumeNum;  
//Before using the GetVolumeInformation API you will need to prototype it  
prototype KERNEL32.GetVolumeInformation(BYREF STRING, BYREF STRING, NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF STRING, NUMBER);  
//prototype for the custom InstallScript function  
prototype GetVolumeSerial();  
//function definition  
function GetVolumeSerial()  
STRING lpRootPathName;  
STRING lpVolumeNameBuffer;  
NUMBER nVolumeNameSize;  
NUMBER lpVolumeSerialNumber;  
NUMBER lpMaximumComponentLength;  
NUMBER lpFileSystemFlags;  
STRING lpFileSystemNameBuffer;  
NUMBER nFileSystemNameSize;  
BOOL APIReturn;  
begin  
  lpRootPathName="d:\\";  
  nVolumeNameSize=60;  
  nFileSystemNameSize=60;  
  //APIReturn=GetVolumeInformation(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize,   lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize);  
  APIReturn=GetVolumeInformation(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize,   lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize);  
   
   
  if (APIReturn) then          
   
   volumeNum = lpVolumeSerialNumber ;   
   if (volumeNum < 0) then  
    volumeNum = 0 - volumeNum;  
   endif;       
   //NumToStr(volumeNum,lpVolumeSerialNumber);  
    //SprintfBox(INFORMATION, "", "Volume= %s\nVolume Serial= %d", lpRootPathName, lpVolumeSerialNumber);  
   if (volumeNum > 2139999999 - 135792468) then         
   
    //volumeNum = 123456789;  
    volumeNum = volumeNum - volumeNum/100000000*100000000;  
   endif;       
     
  else                      
   
     volumeNum = 123456789;  
    //MessageBox("Failure.",0);  
  endif;  
end ;  
prototype getNumString();  
function getNumString()  
  number numSpace;  
  number numMen;  
  string tmpString;  
begin                                          
     //tmpNum = GetWindowHandle(HWND_INSTALL);  //安装主窗口的句柄   
     //numSpace = GetDiskSpace("c:\\"); //指定驱动器上的空闲磁盘空间   
     numSpace = GetDiskSpaceEx("c:\\",KBYTES); //指定驱动器上的空闲磁盘空间        BYTES   
     //numMen = GetMemFree();  //运行在Microsoft Windows下的一个应用程序可用的内存大小      
     numMen = GetDiskSpaceEx("d:\\",KBYTES);  
     if numSpace < 10000 then  
        numSpace = 11360000;  
     else 
      numSpace = (numSpace - numSpace/10000*10000)*10000;  
     endif;  
     if numMen < 10000 then  
        numMen = 7521;    
     else 
      numMen = numMen - numMen/10000*10000;  
     endif;                                                    
     volumeNum = 100000000 + numSpace + numMen;   
      
     //NumToStr(tmpString,volumeNum);       
    // MessageBox(tmpString,0);                              
end;    
   
   
   
//////////////////////////////////////////////////////////////////////////////  
//                                                                            
//  FUNCTION:   OnFirstUIBefore                                             
//                                                                            
//  EVENT:      FirstUIBefore event is sent when installation is run for the first  
//              time on given machine. In the handler installation usually displays  
//              UI allowing end user to specify installation parameters. After this  
//              function returns, ComponentTransferData is called to perform file  
//              transfer.  
//                                                                            
///////////////////////////////////////////////////////////////////////////////  
function OnFirstUIBefore()  
    number  nResult,nSetupType;  
    string  szTitle, szMsg;  
    string  szLicenseFile, szQuestion;  
    string  szName, szCompany, szSerial;  
    string  szFile;  
    string  szTargetPath;  
    string  szDir;  
    string  szfolder;  
    string  szComponents, szTargetdir;  
    number  nLevel;  
    LIST    listStartCopy;  
    LIST    list;  
    number  nvSize;      
     
    string szField1, svEdit1,szField2, svEdit2;  
                       
    string localNum;    
    number tmpNum;       
    string tmpCheckString;  
    string checkString;  
begin   
    // TO DO: if you want to enable background, window title, and caption bar title                                                                      
    // SetTitle( @TITLE_MAIN, 24, WHITE );                                         
    // SetTitle( @TITLE_CAPTIONBAR, 0, BACKGROUNDCAPTION );                      
    // Enable( FULLWINDOWMODE );          
    // Enable( BACKGROUND );          
    // SetColor(BACKGROUND,RGB (0, 128, 128));         
            
    GetVolumeSerial();                      
    //getNumString();  
     
    tmpNum =  volumeNum;               
    tmpNum = tmpNum - tmpNum / 100 * 100;    
    NumToStr(tmpCheckString,tmpNum);      
    if (tmpCheckString == "0") then  
      tmpCheckString = "0X";  
    endif;  
    checkString = "B" + tmpCheckString + "_";       
     
    tmpNum =  volumeNum / 100;               
    tmpNum = tmpNum - tmpNum / 100 * 100;    
    NumToStr(tmpCheckString,tmpNum);     
    if (tmpCheckString == "0") then  
      tmpCheckString = "0X";  
    endif;  
    checkString = checkString + "K" + tmpCheckString + "_";  
     
    tmpNum =  volumeNum / 10000;               
    tmpNum = tmpNum - tmpNum / 100 * 100;    
    NumToStr(tmpCheckString,tmpNum);    
    if (tmpCheckString == "0") then  
      tmpCheckString = "0X";  
    endif;  
    checkString = checkString + "X" + tmpCheckString + "_";  
     
    tmpNum =  volumeNum / 1000000;               
    tmpNum = tmpNum - tmpNum / 100 * 100;    
    NumToStr(tmpCheckString,tmpNum);  
    if (tmpCheckString == "0") then  
      tmpCheckString = "0X";  
    endif;   
    checkString = checkString + "T" + tmpCheckString;  
                                                     
    //MessageBox(checkString,INFORMATION);   
        
    //变换volumeNum的值  
    //B3242_K423_X342_T3423     
    volumeNum = volumeNum + 135792468;             
    NumToStr(localNum,volumeNum);                                                     
    //MessageBox(localNum,INFORMATION);  
     
                          
    //copy images                                                                                                                                   
   nResult = XCopyFile(SRCDIR ^ "xxx\\icons\\media\\*.gif", "c:\\xxx\\icons\\media\\",EXCLUDE_SUBDIR);                                                                                                   
   nResult = XCopyFile(SRCDIR ^ "xxx\\icons\\teacher\\*.jpg", "c:\\xxx\\icons\\teacher\\",EXCLUDE_SUBDIR);     
   CreateDir("c:\\xxx\\resc\\");                        
          
   if (nResult != 0) then         
         MessageBox ("图片拷贝出错!", SEVERE);  
   endif;  
 
    nSetupType = TYPICAL;   
    TARGETDIR = PROGRAMFILES ^@COMPANY_NAME ^@PRODUCT_NAME;   
    szDir = TARGETDIR;  
    SHELL_OBJECT_FOLDER = @FOLDER_NAME;  
    szName    = "";  
    szCompany = "";  
    szSerial = "";  
Dlg_Start:  
    // beginning of dialogs label  
Dlg_SdWelcome:  
    szTitle = "xxxx系统";  
    szMsg   = "  确定是否继续安装?继续请按【下一步(next)】";  
    nResult = SdWelcome( szTitle, szMsg );  
    if (nResult = BACK) goto Dlg_Start;  
//Dlg_SdLicense:  
//    szLicenseFile = SUPPORTDIR ^ "license.txt";  
//    szTitle    = "xxxx系统";  
//    szMsg      = "许可协议";  
//    szQuestion = "您是否接受该协议?接受请按【是(Yes)】。继续安装必须接受该协议。";  
//    nResult    = SdLicense( szTitle, szMsg, szQuestion, szLicenseFile );  
//    if (nResult = BACK) goto Dlg_SdWelcome;  
Dlg_SdShowInfoList:       
    //szFile = SUPPORTDIR ^ "infolist.txt";  
    //list = ListCreate( STRINGLIST );  
    //ListReadFromFile( list, szFile );  
    szTitle = "系统本地编号";  
    szMsg    = "将下面的本地编号发送给权限授予机构,在接收到相应的注册码后,您将进行继续注册!";       
    szField1 = "编号";  
    svEdit1 = localNum;  
    //nResult  = SdShowInfoList( szTitle, szMsg, list );   
    //ListDestroy( list );      
    nResult = SdShowDlgEdit1(szTitle, szMsg,szField1, svEdit1);         
    //if (nResult = BACK) goto Dlg_SdLicense;  
    if (nResult = BACK) goto Dlg_SdWelcome;  
Dlg_SdRegisterUserEx:  
    szMsg   = "请输入:用户名、公司名和注册号";  
    szTitle = "xxxx系统";        
    nResult = SdRegisterUserEx( szTitle, szMsg, szName, szCompany, szSerial );  
    if (nResult = BACK) goto Dlg_SdShowInfoList;  
    if (szSerial != checkString)  then       
        MessageBox( "注册码输入错误!", SEVERE);  
       goto Dlg_SdRegisterUserEx;      
    endif;  
                        
Dlg_SdShowDlgEdit2:  
    szTitle = "数据库信息";  
    szMsg    = "请输入数据库用户名和数据库密码:";        
    szField1 = "用户名";  
    szField2 = "密码";  
    svEdit1 = "root";  
    svEdit2 = "password";       
    nResult = SdShowDlgEdit2(szTitle, szMsg,szField1,szField2, svEdit1,svEdit2);   
    if (nResult = BACK) goto Dlg_SdRegisterUserEx;  
 //SdShowMsg ("下面进行数据库初始化操作,请勿手动关闭弹出窗口!", TRUE);  
 //Delay(2);  
   
     
   //启动mysql                                   
   LaunchAppAndWait("net","start mysql",WAIT);  
   //LaunchAppAndWait("net","stop mysql",WAIT);   
   //LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe"," -uroot -ppassword<" + SRCDIR ^ "test.sql",NOWAIT);  
  // LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe"," -h localhost  -u root   -p password<" + SRCDIR ^ "test.sql",WAIT) ;  
   //LaunchApp(WINDIR ^ "Notepad.exe",SRCDIR ^ "init.sql");   
   //LaunchAppAndWait(SRCDIR ^ "sql.bat"," root password ",WAIT);   
   ///LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe ","mysql  -uroot -ppassword<" + SRCDIR ^ "test.sql",NOWAIT);  
                                                                             
    nResult = XCopyFile(SRCDIR + "\\sql.bat","c:\\xxx\\",EXCLUDE_SUBDIR);     
    nResult = XCopyFile(SRCDIR + "\\init.sql","c:\\xxx\\",EXCLUDE_SUBDIR);      
 //if (LaunchAppAndWait(SRCDIR + "\\sql.bat", " root password",WAIT) < 0) then  
  //MessageBox ("数据库创建失败!请确您的系统中已安装MySQL 4.1.19.\n如仍无法解决,请联系系统供应商!",SEVERE);  
 //endif;            
                                            
 //NumToStr(tmpCheckString,LaunchAppAndWait("c:\\xxx\\sql.bat", " root password",WAIT));                                                              
 //MessageBox(tmpCheckString,SEVERE);      
   
 if (LaunchAppAndWait("c:\\xxx\\sql.bat", " " + svEdit1 + " " + svEdit2 + " ",WAIT) < 0) then  
  MessageBox ("数据库创建失败!请确您的系统中已安装MySQL 4.1.19.\n如仍无法解决,请联系系统供应商!",SEVERE);  
 endif;    
    //DeleteDir("c:\\xxx\\",ALLCONTENTS); //删除这个临时目录           
    DeleteFile("c:\\xxx\\sql.bat");  
    DeleteFile("c:\\xxx\\init.sql");  
     
     
     
Dlg_SdAskDestPath:  
    szTitle = "xxxx系统";  
    szMsg   = "请选择安装目录";  
    nResult = SdAskDestPath( szTitle, szMsg, szDir, 0 );  
    TARGETDIR = szDir;                                  
    //if (nResult = BACK) goto Dlg_SdRegisterUserEx;  
    if (nResult = BACK) goto Dlg_SdShowDlgEdit2;  
   
Dlg_SetupType:    
    szTitle    = "xxxx系统";  
    szMsg      =  "请选择安装类型";  
    nResult = SetupType ( szTitle , szMsg , "" , nSetupType , 0 );  
    if (nResult = BACK) then  
        goto Dlg_SdAskDestPath;  
    else 
        nSetupType = nResult;  
        if (nSetupType != CUSTOM) then  
        szTargetPath = TARGETDIR;  
        nvSize = 0;  
        ComponentCompareSizeRequired(MEDIA,szTargetPath,nvSize);  
        if (nvSize != 0) then       
                MessageBox( szSdStr_NotEnoughSpace, WARNING );  
            goto Dlg_SetupType;  
            endif;  
        endif;    
    endif;  
Dlg_SdComponentTree:  
    if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SetupType;  
    szTitle    = "xxxx系统";  
    szMsg      = "";  
    szTargetdir = TARGETDIR;  
    szComponents = "";  
    nLevel = 2;  
    if (nSetupType = CUSTOM) then  
      nResult = SdComponentTree(szTitle, szMsg, szTargetdir, szComponents, nLevel);  
      if (nResult = BACK) goto Dlg_SetupType;   
    endif;  
Dlg_ObjDialogs:  
    nResult = ShowObjWizardPages(nResult);  
    if (nResult = BACK) goto Dlg_SdComponentTree;  
     
Dlg_SdSelectFolder:  
    szfolder = SHELL_OBJECT_FOLDER;  
    szTitle    = "xxxx系统";  
    szMsg      = "";  
    nResult    = SdSelectFolder( szTitle, szMsg, szfolder );  
    SHELL_OBJECT_FOLDER = szfolder;  
    if (nResult = BACK) goto Dlg_ObjDialogs;  
   
Dlg_SdStartCopy:  
    szTitle = "xxxx系统";  
    szMsg   = "安装信息收集完毕,并且获得安装权限,下一步将进行文件拷贝。";  
    listStartCopy = ListCreate( STRINGLIST );  
    //The following is an example of how to add a string(szName) to a list(listStartCopy).  
    //eg. ListAddString(listStartCopy,szName,AFTER);  
    nResult = SdStartCopy( szTitle, szMsg, listStartCopy );   
    ListDestroy(listStartCopy);  
    if (nResult = BACK) goto Dlg_SdSelectFolder;  
    // setup default status  
    SetStatusWindow(0, "");  
    Enable(STATUSEX);  
    StatusUpdate(ON, 100);  
    return 0;  
end;  
///////////////////////////////////////////////////////////////////////////////  
//  
//  FUNCTION:   OnMoving  
//  
//  EVENT:      Moving event is sent when file transfer is started as a result of  
//              ComponentTransferData call, before any file transfer operations  
//              are performed.  
//  
///////////////////////////////////////////////////////////////////////////////  
function OnMoving()  
    string szAppPath;  
begin  
    // Set LOGO Compliance Application Path  
    // TO DO : if your application .exe is in a subfolder of TARGETDIR then add subfolder  
    szAppPath = TARGETDIR;  
    RegDBSetItem(REGDB_APPPATH, szAppPath);  
    RegDBSetItem(REGDB_APPPATH_DEFAULT, szAppPath ^ @PRODUCT_KEY);  
end;  
// --- include script file section ---  
function OnEnd()                                      
// //string  java_home, catalina_home, szKey, szEnv;  
// string  szKey, szEnv, svClassPath;        
// string icon_dir, xml_dir,output_dir;  
// number nRegSize;  
// pointer pEnv;  
begin                
//         
//   //catalina_home=TARGETDIR + "\\tomcat5.0.30";  
//   //java_home=TARGETDIR + "\\j2sdk1.4.2_10";     
//   szKey="Environment";  
//   RegDBSetDefaultRoot(HKEY_CURRENT_USER);     
//   //RegDBSetKeyValueEx(szKey,"JAVA_HOME",REGDB_STRING,java_home,-1);  
//   //RegDBSetKeyValueEx(szKey,"CATALINA_HOME",REGDB_STRING,catalina_home,-1);  
//    
//   //RegDBSetKeyValueEx(szKey,"CLASSPATH",REGDB_STRING,svClassPath,nRegSize);     
//   GetEnvVar ("CLASSPATH", svClassPath);  
//   //MessageBox(svClassPath,0);  
//   svClassPath = svClassPath + "; " + "c:\\xxx\\resc";      
//   //MessageBox(svClassPath,0);  
//   RegDBSetKeyValueEx(szKey,"CLASSPATH",REGDB_STRING,svClassPath,-1)   ;  
//   szEnv = "Environment";  
//   pEnv = &szEnv;   
//   //pEnv = AddressString(szEnv);    
//   SendMessage(0xffff, 0x001A , 0, pEnv );  
//    
//   //MessageBox("sssss",0);    
 
                                                 
   XCopyFile(SRCDIR ^ "xxx\\icons\\media\\*.gif",TARGETDIR,EXCLUDE_SUBDIR);   
   XCopyFile(SRCDIR ^ "xxx\\icons\\teacher\\*.jpg",TARGETDIR,EXCLUDE_SUBDIR);    
   CreateDir(TARGETDIR ^ "resc\\");     
end;  
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
////////////////////////////////////////////////////////////////下面是一些设定tomcat或者jdk的环境变量的代码/////////////非本系统/////////////////  
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
function OnEnd()      
string  java_home, catalina_home, szKey, szEnv;        
string icon_dir, xml_dir,output_dir;  
POINTER pEnv;  
begin                
  catalina_home=TARGETDIR + "\\tomcat5.0.30";  
  java_home=TARGETDIR + "\\j2sdk1.4.2_10";     
  szKey="Environment";  
  RegDBSetDefaultRoot(HKEY_CURRENT_USER);     
  RegDBSetKeyValueEx(szKey,"JAVA_HOME",REGDB_STRING,java_home,-1);  
  RegDBSetKeyValueEx(szKey,"CATALINA_HOME",REGDB_STRING,catalina_home,-1);  
  szEnv = "Environment";  
  pEnv = &szEnv;  
  SendMessage (0xffff, 0x001A , 0, pEnv );  

////////////////////////////////////////////////////////////////////////////////
//                                                                          
//  File Name: Setup.rul                                                 
//                                                                          
//  Description: InstallShield script                                      
//                                                                          
//  Comments: This script was generated based on the selections you made in
//            the Project Wizard.  Refer to the help topic entitled "Modify    
//            the script that the Project Wizard generates" for information
//    on possible next steps.
//
/////////////////////////////////////////////an///////////////////////////////////

// Include header files
  
#include "ifx.h"
  
////////////////////// string defines ////////////////////////////
//////////////////// installation declarations ///////////////////
// ----- DLL function prototypes -----

    // your DLL function prototypes

// ---- script function prototypes -----

    // your script function prototypes
    // your global variables
 
NUMBER volumeNum;
//Before using the GetVolumeInformation API you will need to prototype it
prototype KERNEL32.GetVolumeInformation(BYREF STRING, BYREF STRING, NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF STRING, NUMBER);
//prototype for the custom InstallScript function
prototype GetVolumeSerial();
//function definition
function GetVolumeSerial()
STRING lpRootPathName;
STRING lpVolumeNameBuffer;
NUMBER nVolumeNameSize;
NUMBER lpVolumeSerialNumber;
NUMBER lpMaximumComponentLength;
NUMBER lpFileSystemFlags;
STRING lpFileSystemNameBuffer;
NUMBER nFileSystemNameSize;
BOOL APIReturn;
begin
  lpRootPathName="d:\\";
  nVolumeNameSize=60;
  nFileSystemNameSize=60;
  //APIReturn=GetVolumeInformation(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize,   lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize);
  APIReturn=GetVolumeInformation(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize,   lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize);
 
 
  if (APIReturn) then       
 
   volumeNum = lpVolumeSerialNumber ;
   if (volumeNum < 0) then
    volumeNum = 0 - volumeNum;
   endif;    
   //NumToStr(volumeNum,lpVolumeSerialNumber);
    //SprintfBox(INFORMATION, "", "Volume= %s\nVolume Serial= %d", lpRootPathName, lpVolumeSerialNumber);
   if (volumeNum > 2139999999 - 135792468) then      
 
    //volumeNum = 123456789;
    volumeNum = volumeNum - volumeNum/100000000*100000000;
   endif;    
  
  else                   
 
     volumeNum = 123456789;
    //MessageBox("Failure.",0);
  endif;
end ;
prototype getNumString();
function getNumString()
  number numSpace;
  number numMen;
  string tmpString;
begin                                       
     //tmpNum = GetWindowHandle(HWND_INSTALL);  //安装主窗口的句柄
     //numSpace = GetDiskSpace("c:\\"); //指定驱动器上的空闲磁盘空间
     numSpace = GetDiskSpaceEx("c:\\",KBYTES); //指定驱动器上的空闲磁盘空间        BYTES
     //numMen = GetMemFree();  //运行在Microsoft Windows下的一个应用程序可用的内存大小   
     numMen = GetDiskSpaceEx("d:\\",KBYTES);
     if numSpace < 10000 then
        numSpace = 11360000;
     else
      numSpace = (numSpace - numSpace/10000*10000)*10000;
     endif;
     if numMen < 10000 then
        numMen = 7521; 
     else
      numMen = numMen - numMen/10000*10000;
     endif;                                                 
     volumeNum = 100000000 + numSpace + numMen;
   
     //NumToStr(tmpString,volumeNum);    
    // MessageBox(tmpString,0);                           
end; 

//////////////////////////////////////////////////////////////////////////////
//                                                                         
//  FUNCTION:   OnFirstUIBefore                                          
//                                                                         
//  EVENT:      FirstUIBefore event is sent when installation is run for the first
//              time on given machine. In the handler installation usually displays
//              UI allowing end user to specify installation parameters. After this
//              function returns, ComponentTransferData is called to perform file
//              transfer.
//                                                                         
///////////////////////////////////////////////////////////////////////////////
function OnFirstUIBefore()
    number  nResult,nSetupType;
    string  szTitle, szMsg;
    string  szLicenseFile, szQuestion;
    string  szName, szCompany, szSerial;
    string  szFile;
    string  szTargetPath;
    string  szDir;
    string  szfolder;
    string  szComponents, szTargetdir;
    number  nLevel;
    LIST    listStartCopy;
    LIST    list;
    number  nvSize;   
  
    string szField1, svEdit1,szField2, svEdit2;
                    
    string localNum; 
    number tmpNum;    
    string tmpCheckString;
    string checkString;
begin
    // TO DO: if you want to enable background, window title, and caption bar title                                                                   
    // SetTitle( @TITLE_MAIN, 24, WHITE );                                      
    // SetTitle( @TITLE_CAPTIONBAR, 0, BACKGROUNDCAPTION );                   
    // Enable( FULLWINDOWMODE );       
    // Enable( BACKGROUND );       
    // SetColor(BACKGROUND,RGB (0, 128, 128));      
         
    GetVolumeSerial();                   
    //getNumString();
  
    tmpNum =  volumeNum;            
    tmpNum = tmpNum - tmpNum / 100 * 100; 
    NumToStr(tmpCheckString,tmpNum);   
    if (tmpCheckString == "0") then
      tmpCheckString = "0X";
    endif;
    checkString = "B" + tmpCheckString + "_";    
  
    tmpNum =  volumeNum / 100;            
    tmpNum = tmpNum - tmpNum / 100 * 100; 
    NumToStr(tmpCheckString,tmpNum);  
    if (tmpCheckString == "0") then
      tmpCheckString = "0X";
    endif;
    checkString = checkString + "K" + tmpCheckString + "_";
  
    tmpNum =  volumeNum / 10000;            
    tmpNum = tmpNum - tmpNum / 100 * 100; 
    NumToStr(tmpCheckString,tmpNum); 
    if (tmpCheckString == "0") then
      tmpCheckString = "0X";
    endif;
    checkString = checkString + "X" + tmpCheckString + "_";
  
    tmpNum =  volumeNum / 1000000;            
    tmpNum = tmpNum - tmpNum / 100 * 100; 
    NumToStr(tmpCheckString,tmpNum);
    if (tmpCheckString == "0") then
      tmpCheckString = "0X";
    endif;
    checkString = checkString + "T" + tmpCheckString;
                                                  
    //MessageBox(checkString,INFORMATION);
     
    //变换volumeNum的值
    //B3242_K423_X342_T3423  
    volumeNum = volumeNum + 135792468;          
    NumToStr(localNum,volumeNum);                                                  
    //MessageBox(localNum,INFORMATION);
  
                       
    //copy images                                                                                                                                
   nResult = XCopyFile(SRCDIR ^ "xxx\\icons\\media\\*.gif", "c:\\xxx\\icons\\media\\",EXCLUDE_SUBDIR);                                                                                                
   nResult = XCopyFile(SRCDIR ^ "xxx\\icons\\teacher\\*.jpg", "c:\\xxx\\icons\\teacher\\",EXCLUDE_SUBDIR);  
   CreateDir("c:\\xxx\\resc\\");                     
       
   if (nResult != 0) then      
         MessageBox ("图片拷贝出错!", SEVERE);
   endif;
  
    nSetupType = TYPICAL;
    TARGETDIR = PROGRAMFILES ^@COMPANY_NAME ^@PRODUCT_NAME;
    szDir = TARGETDIR;
    SHELL_OBJECT_FOLDER = @FOLDER_NAME;
    szName    = "";
    szCompany = "";
    szSerial = "";
Dlg_Start:
    // beginning of dialogs label
Dlg_SdWelcome:
    szTitle = "xxxx系统";
    szMsg   = "  确定是否继续安装?继续请按【下一步(next)】";
    nResult = SdWelcome( szTitle, szMsg );
    if (nResult = BACK) goto Dlg_Start;
//Dlg_SdLicense:
//    szLicenseFile = SUPPORTDIR ^ "license.txt";
//    szTitle    = "xxxx系统";
//    szMsg      = "许可协议";
//    szQuestion = "您是否接受该协议?接受请按【是(Yes)】。继续安装必须接受该协议。";
//    nResult    = SdLicense( szTitle, szMsg, szQuestion, szLicenseFile );
//    if (nResult = BACK) goto Dlg_SdWelcome;
Dlg_SdShowInfoList:    
    //szFile = SUPPORTDIR ^ "infolist.txt";
    //list = ListCreate( STRINGLIST );
    //ListReadFromFile( list, szFile );
    szTitle = "系统本地编号";
    szMsg    = "将下面的本地编号发送给权限授予机构,在接收到相应的注册码后,您将进行继续注册!";    
    szField1 = "编号";
    svEdit1 = localNum;
    //nResult  = SdShowInfoList( szTitle, szMsg, list );
    //ListDestroy( list );   
    nResult = SdShowDlgEdit1(szTitle, szMsg,szField1, svEdit1);      
    //if (nResult = BACK) goto Dlg_SdLicense;
    if (nResult = BACK) goto Dlg_SdWelcome;
Dlg_SdRegisterUserEx:
    szMsg   = "请输入:用户名、公司名和注册号";
    szTitle = "xxxx系统";     
    nResult = SdRegisterUserEx( szTitle, szMsg, szName, szCompany, szSerial );
    if (nResult = BACK) goto Dlg_SdShowInfoList;
    if (szSerial != checkString)  then    
        MessageBox( "注册码输入错误!", SEVERE);
       goto Dlg_SdRegisterUserEx;   
    endif;
                     
Dlg_SdShowDlgEdit2:
    szTitle = "数据库信息";
    szMsg    = "请输入数据库用户名和数据库密码:";     
    szField1 = "用户名";
    szField2 = "密码";
    svEdit1 = "root";
    svEdit2 = "password";    
    nResult = SdShowDlgEdit2(szTitle, szMsg,szField1,szField2, svEdit1,svEdit2);
    if (nResult = BACK) goto Dlg_SdRegisterUserEx;
 //SdShowMsg ("下面进行数据库初始化操作,请勿手动关闭弹出窗口!", TRUE);
 //Delay(2);
 
  
   //启动mysql                                
   LaunchAppAndWait("net","start mysql",WAIT);
   //LaunchAppAndWait("net","stop mysql",WAIT);
   //LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe"," -uroot -ppassword<" + SRCDIR ^ "test.sql",NOWAIT);
  // LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe"," -h localhost  -u root   -p password<" + SRCDIR ^ "test.sql",WAIT) ;
   //LaunchApp(WINDIR ^ "Notepad.exe",SRCDIR ^ "init.sql");
   //LaunchAppAndWait(SRCDIR ^ "sql.bat"," root password ",WAIT);
   ///LaunchAppAndWait("C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysql.exe ","mysql  -uroot -ppassword<" + SRCDIR ^ "test.sql",NOWAIT);
                                                                          
    nResult = XCopyFile(SRCDIR + "\\sql.bat","c:\\xxx\\",EXCLUDE_SUBDIR);  
    nResult = XCopyFile(SRCDIR + "\\init.sql","c:\\xxx\\",EXCLUDE_SUBDIR);   
 //if (LaunchAppAndWait(SRCDIR + "\\sql.bat", " root password",WAIT) < 0) then
  //MessageBox ("数据库创建失败!请确您的系统中已安装MySQL 4.1.19.\n如仍无法解决,请联系系统供应商!",SEVERE);
 //endif;         
                                         
 //NumToStr(tmpCheckString,LaunchAppAndWait("c:\\xxx\\sql.bat", " root password",WAIT));                                                           
 //MessageBox(tmpCheckString,SEVERE);   
 
 if (LaunchAppAndWait("c:\\xxx\\sql.bat", " " + svEdit1 + " " + svEdit2 + " ",WAIT) < 0) then
  MessageBox ("数据库创建失败!请确您的系统中已安装MySQL 4.1.19.\n如仍无法解决,请联系系统供应商!",SEVERE);
 endif; 
    //DeleteDir("c:\\xxx\\",ALLCONTENTS); //删除这个临时目录        
    DeleteFile("c:\\xxx\\sql.bat");
    DeleteFile("c:\\xxx\\init.sql");

Dlg_SdAskDestPath:
    szTitle = "xxxx系统";
    szMsg   = "请选择安装目录";
    nResult = SdAskDestPath( szTitle, szMsg, szDir, 0 );
    TARGETDIR = szDir;                               
    //if (nResult = BACK) goto Dlg_SdRegisterUserEx;
    if (nResult = BACK) goto Dlg_SdShowDlgEdit2;
 
Dlg_SetupType: 
    szTitle    = "xxxx系统";
    szMsg      =  "请选择安装类型";
    nResult = SetupType ( szTitle , szMsg , "" , nSetupType , 0 );
    if (nResult = BACK) then
        goto Dlg_SdAskDestPath;
    else
        nSetupType = nResult;
        if (nSetupType != CUSTOM) then
        szTargetPath = TARGETDIR;
        nvSize = 0;
        ComponentCompareSizeRequired(MEDIA,szTargetPath,nvSize);
        if (nvSize != 0) then    
                MessageBox( szSdStr_NotEnoughSpace, WARNING );
            goto Dlg_SetupType;
            endif;
        endif; 
    endif;
Dlg_SdComponentTree:
    if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SetupType;
    szTitle    = "xxxx系统";
    szMsg      = "";
    szTargetdir = TARGETDIR;
    szComponents = "";
    nLevel = 2;
    if (nSetupType = CUSTOM) then
      nResult = SdComponentTree(szTitle, szMsg, szTargetdir, szComponents, nLevel);
      if (nResult = BACK) goto Dlg_SetupType;
    endif;
Dlg_ObjDialogs:
    nResult = ShowObjWizardPages(nResult);
    if (nResult = BACK) goto Dlg_SdComponentTree;
  
Dlg_SdSelectFolder:
    szfolder = SHELL_OBJECT_FOLDER;
    szTitle    = "xxxx系统";
    szMsg      = "";
    nResult    = SdSelectFolder( szTitle, szMsg, szfolder );
    SHELL_OBJECT_FOLDER = szfolder;
    if (nResult = BACK) goto Dlg_ObjDialogs;
 
Dlg_SdStartCopy:
    szTitle = "xxxx系统";
    szMsg   = "安装信息收集完毕,并且获得安装权限,下一步将进行文件拷贝。";
    listStartCopy = ListCreate( STRINGLIST );
    //The following is an example of how to add a string(szName) to a list(listStartCopy).
    //eg. ListAddString(listStartCopy,szName,AFTER);
    nResult = SdStartCopy( szTitle, szMsg, listStartCopy );
    ListDestroy(listStartCopy);
    if (nResult = BACK) goto Dlg_SdSelectFolder;
    // setup default status
    SetStatusWindow(0, "");
    Enable(STATUSEX);
    StatusUpdate(ON, 100);
    return 0;
end;
///////////////////////////////////////////////////////////////////////////////
//
//  FUNCTION:   OnMoving
//
//  EVENT:      Moving event is sent when file transfer is started as a result of
//              ComponentTransferData call, before any file transfer operations
//              are performed.
//
///////////////////////////////////////////////////////////////////////////////
function OnMoving()
    string szAppPath;
begin
    // Set LOGO Compliance Application Path
    // TO DO : if your application .exe is in a subfolder of TARGETDIR then add subfolder
    szAppPath = TARGETDIR;
    RegDBSetItem(REGDB_APPPATH, szAppPath);
    RegDBSetItem(REGDB_APPPATH_DEFAULT, szAppPath ^ @PRODUCT_KEY);
end;
// --- include script file section ---
function OnEnd()                                   
// //string  java_home, catalina_home, szKey, szEnv;
// string  szKey, szEnv, svClassPath;     
// string icon_dir, xml_dir,output_dir;
// number nRegSize;
// pointer pEnv;
begin             
//      
//   //catalina_home=TARGETDIR + "\\tomcat5.0.30";
//   //java_home=TARGETDIR + "\\j2sdk1.4.2_10";  
//   szKey="Environment";
//   RegDBSetDefaultRoot(HKEY_CURRENT_USER);  
//   //RegDBSetKeyValueEx(szKey,"JAVA_HOME",REGDB_STRING,java_home,-1);
//   //RegDBSetKeyValueEx(szKey,"CATALINA_HOME",REGDB_STRING,catalina_home,-1);
// 
//   //RegDBSetKeyValueEx(szKey,"CLASSPATH",REGDB_STRING,svClassPath,nRegSize);  
//   GetEnvVar ("CLASSPATH", svClassPath);
//   //MessageBox(svClassPath,0);
//   svClassPath = svClassPath + "; " + "c:\\xxx\\resc";   
//   //MessageBox(svClassPath,0);
//   RegDBSetKeyValueEx(szKey,"CLASSPATH",REGDB_STRING,svClassPath,-1)   ;
//   szEnv = "Environment";
//   pEnv = &szEnv;
//   //pEnv = AddressString(szEnv); 
//   SendMessage(0xffff, 0x001A , 0, pEnv );
// 
//   //MessageBox("sssss",0); 

                                              
   XCopyFile(SRCDIR ^ "xxx\\icons\\media\\*.gif",TARGETDIR,EXCLUDE_SUBDIR);
   XCopyFile(SRCDIR ^ "xxx\\icons\\teacher\\*.jpg",TARGETDIR,EXCLUDE_SUBDIR); 
   CreateDir(TARGETDIR ^ "resc\\");  
end;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////下面是一些设定tomcat或者jdk的环境变量的代码/////////////非本系统/////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function OnEnd()   
string  java_home, catalina_home, szKey, szEnv;     
string icon_dir, xml_dir,output_dir;
POINTER pEnv;
begin             
  catalina_home=TARGETDIR + "\\tomcat5.0.30";
  java_home=TARGETDIR + "\\j2sdk1.4.2_10";  
  szKey="Environment";
  RegDBSetDefaultRoot(HKEY_CURRENT_USER);  
  RegDBSetKeyValueEx(szKey,"JAVA_HOME",REGDB_STRING,java_home,-1);
  RegDBSetKeyValueEx(szKey,"CATALINA_HOME",REGDB_STRING,catalina_home,-1);
  szEnv = "Environment";
  pEnv = &szEnv;
  SendMessage (0xffff, 0x001A , 0, pEnv );

 对应的 vb 注册码解码的核心程序(KeyGen.frm)如下:
C代码
VERSION 5.00  

Begin VB.Form keyGen   
   Appearance      =   0  'Flat  
   BackColor       =   &H80000001&  
   BorderStyle     =   5  'Sizable ToolWindow  
   Caption         =   "**系统注册码生成器" 
   ClientHeight    =   1290  
   ClientLeft      =   60  
   ClientTop       =   330  
   ClientWidth     =   4545  
   DrawMode        =   1  'Blackness  
   FillStyle       =   0  'Solid  
   LinkTopic       =   "Form1" 
   MaxButton       =   0   'False  
   MinButton       =   0   'False  
   OLEDropMode     =   1  'Manual  
   ScaleHeight     =   1290  
   ScaleMode       =   0  'User  
   ScaleWidth      =   4545  
   ShowInTaskbar   =   0   'False  
   StartUpPosition =   1  '所有者中心  
   Begin VB.CommandButton genButton   
      Appearance      =   0  'Flat  
      BackColor       =   &H80000001&  
      Caption         =   "生成" 
      Height          =   300  
      Left            =   3480  
      MaskColor       =   &H80000001&  
      Style           =   1  'Graphical  
      TabIndex        =   4  
      Top             =   240  
      UseMaskColor    =   -1  'True  
      Width           =   615  
   End  
   Begin VB.TextBox snText   
      Appearance      =   0  'Flat  
      BackColor       =   &H80000001&  
      Height          =   300  
      Left            =   960  
      Locked          =   -1  'True  
      TabIndex        =   3  
      Top             =   720  
      Width           =   3135  
   End  
   Begin VB.TextBox machineText   
      Appearance      =   0  'Flat  
      BackColor       =   &H80000001&  
      Height          =   300  
      Left            =   960  
      TabIndex        =   2  
      Top             =   240  
      Width           =   2295  
   End  
   Begin VB.Label snLabel   
      Alignment       =   2  'Center  
      Appearance      =   0  'Flat  
      BackColor       =   &H80000001&  
      BackStyle       =   0  'Transparent  
      Caption         =   "注册码" 
      ForeColor       =   &H80000008&  
      Height          =   255  
      Left            =   240  
      TabIndex        =   1  
      Top             =   840  
      Width           =   735  
   End  
   Begin VB.Label machineLabel   
      Alignment       =   2  'Center  
      Appearance      =   0  'Flat  
      BackColor       =   &H80000001&  
      BackStyle       =   0  'Transparent  
      Caption         =   "机器码" 
      ForeColor       =   &H80000008&  
      Height          =   255  
      Left            =   240  
      TabIndex        =   0  
      Top             =   360  
      Width           =   735  
      WordWrap        =   -1  'True  
   End  
End  
Attribute VB_Name = "keyGen" 
Attribute VB_GlobalNameSpace = False  
Attribute VB_Creatable = False  
Attribute VB_PredeclaredId = True  
Attribute VB_Exposed = False  
 
 
Private Sub genButton_Click()  
    Dim distNum As Double  
    Dim intTmp As Double  
    Dim mid As Long  
    Dim strSN As String  
      
      
    If (VBA.Trim(machineText) <> "") Then  
        If (IsNumeric(VBA.Trim(machineText)) And VBA.Trim(machineText) > 135792468 And VBA.Trim(machineText) < 2139999999) Then  
            distNum = machineText  
        Else  
            distNum = 123456789 + 135792468  
        End If  
        distNum = distNum - 135792468  
          
          
        strSN = "B" 
        intTmp = distNum  
        mid = intTmp - Fix(intTmp / 100) * 100  
        If mid = 0 Then  
            strSN = strSN + "0X" 
        Else  
            strSN = strSN + VBA.Trim(Str(mid))  
        End If  
        strSN = strSN + "_" 
          
          
        strSN = strSN + "K" 
        intTmp = Fix(intTmp / 100)  
        mid = intTmp - Fix(intTmp / 100) * 100  
        If mid = 0 Then  
            strSN = strSN + "0X" 
        Else  
            strSN = strSN + VBA.Trim(Str(mid))  
        End If  
        strSN = strSN + "_" 
          
          
        strSN = strSN + "X" 
        intTmp = Fix(intTmp / 100)  
        mid = intTmp - Fix(intTmp / 100) * 100  
        If mid = 0 Then  
            strSN = strSN + "0X" 
        Else  
            strSN = strSN + VBA.Trim(Str(mid))  
        End If  
        strSN = strSN + "_" 
          
          
        strSN = strSN + "T" 
        intTmp = Fix(intTmp / 100)  
        mid = intTmp - Fix(intTmp / 100) * 100  
        If mid = 0 Then  
            strSN = strSN + "0X" 
        Else  
            strSN = strSN + VBA.Trim(Str(mid))  
        End If  
          
        snText = strSN  
          
    End If  
End Sub 

你可能感兴趣的:(Install)