InstallShield Script

//=========================================================================== // //  File Name:    Setup.rul // //  Description:  Blank setup main script file // //  Comments:     Blank setup is an empty setup project. If you want to //                  create a new project via. step-by step instructions use the //                  Project Assistant. //                SETUP_FILE //===========================================================================

// Included header files ---------------------------------------------------- #include "ifx.h" #include "check.rul" #include "getcustomerkey.rul" #include "get_server_username_pass.rul" #include "get_server_username_pass_delete_db.rul" #include "getloginnameandpass.rul"

prototype CheckCustomerKey(); prototype CreateRegistryKey(STRING, STRING, NUMBER, STRING, NUMBER,BOOL); prototype STRING GetRegistryValue(STRING, STRING, NUMBER,NUMBER); prototype InformFinish(); prototype int CheckSQLInstallAndInstall(); prototype BOOL CheckSQl2005ProOrExpressInstalled(); prototype NUMBER GetServerNameAndInstallDB(); prototype STRING GetRealSqlInstallPath(STRING,STRING,STRING,STRING,STRING,STRING); prototype BOOL CheckIf2DBExist(STRING); prototype InstallDB(STRING,STRING,STRING,STRING); prototype INT GetInstanceNamePassAndInstall(); prototype STRING GetServerName(); prototype TestDB(STRING,STRING,STRING); prototype Delete1DB(STRING); prototype NUMBER ExcuteSqlFile(STRING); prototype string GetPathToOsql(); prototype CleanTempFiles(); prototype NUMBER AskCreateNewLogin(); prototype InstalledSQLExpress(STRING); prototype BOOL InsSQLExpress(STRING,STRING); prototype CheckInstallSuccess(STRING); prototype DeleteAndCopyFile(); prototype CreateShortCut(STRING,STRING,STRING,STRING,BOOL); prototype DeleteDB_SQLServer(); prototype STRING GetInstallPath(); prototype BOOL CheckApplicationRunning(STRING,BOOL); prototype GetProcessID(STRING, STRING); prototype CheckRuningProcess(); prototype ActionUpdater(); prototype STRING UpdaterScript(STRING,STRING,STRING,STRING,STRING,STRING); prototype STRING GetRegistryValue2(STRING,STRING);

BOOL bByPassCustomerKey,bInstallAborted,bCheckSetup; BOOL bvInstallData,bvInstallDB; BOOL  bvDataDB,bvSystemDB,installEXpressGoodOrBad; STRING svSQLDataRoot; STRING svServer,svUserName,svPassword; STRING DB_NAME; STRING DEFAULTUSERLOGIN; STRING DEFAULTPASSLOGIN; STRING sqlExpressInstanceName,svPassword2,svConfirmPassword2; BOOL bByPassConfig, bIsSQLExpress,bvCreateNewLogin; BOOL bCheckYesNoLicenseCustomerkey,bCheckYesNoDB; STRING EZLICENSE; STRING oldInstalledPath; BOOL bvLaunchLicense; STRING SQLPATH ; STRING SQLDATAROOT; STRING REGPATHSQL2000; STRING REGPATHSQL2005; STRING DBName;

#define FEATURE            "" #define SDASKOPTSTITLE     "Component Selection" #define SDASKOPTSMSG1      "Select components to install." #define SDASKOPTSMSG2      "Your selections will be used to effect file transfer." #define APPBASE_PATH       "Your Company Name\\Your Product Name"

//=========================================================================== // //  Topic:    OnBegin // //  Description: // //  My Name    : // //=========================================================================== function OnBegin() STRING szWritePath,szProcessName; begin

szWritePath=WINDISK +"\\LogProcess.txt"; DeleteAndCopyFile(); szProcessName=@PRODUCT_NAME; GetProcessID(szWritePath,szProcessName);

if LaunchAppAndWait (SUPPORTDIR ^"Encode_Decode.exe", "1.Check IIS             : NO", LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN)==0 then //MessageBox(" Encode_Decode thanh cong",WARNING);

else //MessageBox(" Encode_Decode fail",WARNING);

endif;

bvDataDB=TRUE; bvSystemDB=TRUE; bvInstallDB=TRUE; svPassword=""; bvCreateNewLogin=TRUE; bIsSQLExpress=FALSE; DEFAULTUSERLOGIN="DatabaseName"; //svRapidApplicationPools="PoolRapidEPM"; DEFAULTPASSLOGIN="123456"; installEXpressGoodOrBad=FALSE; sqlExpressInstanceName="SQLExpress"; EZLICENSE = PROGRAMFILES ^ "ACOM Solutions\\EZLicense"; REGPATHSQL2000 = "SOFTWARE\\Microsoft\\MSSQLServer\\Setup"; REGPATHSQL2005 = "SOFTWARE\\Microsoft\\Microsoft SQL Server\\MSSQL.1\\Setup"; bCheckYesNoLicenseCustomerkey=FALSE; bCheckYesNoDB=FALSE; DetectSoftWare();

end;

//=========================================================================== // //  Topic:    GetProcessID // //  Description: // //  My Name    : // //=========================================================================== function GetProcessID(szWritePath,szProcessName) STRING para; begin

para="\"" + szWritePath + "\" \""+szProcessName+"\""; if LaunchAppAndWait (SUPPORTDIR ^"GetProcessIDTest.exe",para, LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN)==0 then //MessageBox(" GetProcessID thanh cong" + "\n\n" + para,WARNING); else //MessageBox(" GetProcessID fail" + "\n\n" + para,WARNING); endif; end;

//=========================================================================== // //  Topic:    CheckRuningProcess // //  Description: // //  My Name    : // //===========================================================================

function CheckRuningProcess() STRING szWritePath; NUMBER nResult; STRING szMsg1,szMsg2,szMsg3,szMsg4;

begin

szWritePath=WINDISK +"\\LogProcess.txt";

nResult  = Is (FILE_EXISTS,szWritePath );

if(nResult=TRUE) then

szMsg1="Uninstalling process cannot be continued because"; szMsg2=" "+@PRODUCT_NAME + " "; szMsg3="is in use. Please close it and try again."; szMsg4=szMsg1+szMsg2+szMsg3; //MessageBox("Uninstalling process cannot be continued because " @PRODUCT_NAME " is in use. Please close it and try again.",WARNING); MessageBox(szMsg4,WARNING); DeleteFile(WINDISK +"\\LogProcess.txt"); abort; else endif; end;

//=========================================================================== // //  Topic:    OnFirstUIBefore // //  Description: // //  My Name    : // //=========================================================================== function OnFirstUIBefore() NUMBER  nResult, nLevel, nSize, nSetupType; STRING  szTitle, szMsg, szOpt1, szOpt2, szLicenseFile; STRING  szName, szCompany, szTargetPath, szDir, szFeatures; BOOL    bLicenseAccepted; NUMBER  nFlag, nFileHandle; LIST   listID; STRING svPath,svFile; BOOL bResult; STRING szKey, szNumName, szNumValue, svNumValue,szValueData; NUMBER nType; STRING svDir; STRING    nKeyValue,svEdit1; STRING path; begin //Check Application Running (file *.exe) CheckRuningProcess();

path=GetInstallPath(); oldInstalledPath=path   ; CheckApplicationRunning(path,TRUE);

nSetupType = COMPLETE; szDir = TARGETDIR; szName = ""; szCompany = ""; bLicenseAccepted = FALSE; bvDataDB=TRUE;

//Create Path in Registry key values. szNumName  = "Path"; szNumValue = TARGETDIR; nType      = REGDB_STRING; nSize      = -1; szKey = "SOFTWARE\\ACOM Solutions\\"+@PRODUCT_NAME; CreateRegistryKey(szKey, szNumName, nType, szNumValue, nSize,TRUE);

//Create InstallPath in Registry key values. szNumName="InstallPath"; svEdit1=EZLICENSE ^"EZLicense.exe"; CreateRegistryKey(szKey, szNumName, nType, svEdit1, nSize,FALSE)  ;

// Beginning of UI Sequence Dlg_Start: nResult = 0; Dlg_SdWelcome: szTitle = ""; szMsg = ""; nResult = SdWelcome( szTitle, szMsg ); if (nResult = BACK) goto Dlg_Start; Dlg_LicenseCustomerkey: //Show License and Customerkey listID = ListCreate (STRINGLIST); // Set the file mode to normal. OpenFileMode (FILE_MODE_NORMAL); // Open the file for editing. svPath=SRCDIR; svFile="Config.ini"; OpenFile (nFileHandle, svPath, svFile); // Get lines from the file into the list. while (GetLine (nFileHandle, svLine) = 0)

ListAddString (listID, svLine, AFTER); StrSub ( svReadLine, svLine, 25,40); StrSub(svReadLineNumber,svLine,0,1); if(svReadLineNumber=="5" && svReadLine== " YES") then bCheckYesNoLicenseCustomerkey=TRUE; Dlg_SdLicense2: nResult=SdLicense2Rtf  (TITLES, "", "",SRCDIR^ LICENSE_PATH,TRUE); if (nResult = BACK)then goto Dlg_SdWelcome; endif; Dlg_CheckCustomerKeys: nResult=CheckCustomerKey(); if(nResult = BACK) then goto  Dlg_SdLicense2; endif; endif; if(svReadLineNumber=="6" && svReadLine== " YES") then bCheckYesNoDB=TRUE; Dlg_GetDBOptions: nResult= CheckSQLInstallAndInstall(); if(nResult=BACK) then if(bCheckYesNoLicenseCustomerkey=TRUE) then goto  Dlg_CheckCustomerKeys; else goto  Dlg_SdWelcome; endif; endif; if CheckSQl2005ProOrExpressInstalled()==FALSE then MessageBox("Please install Microsoft SQL Server 2005 before running Rapid EPM setup.",SEVERE); InformFinish(); endif;

//GetInstallDB Dlg_SdAskInstallDB: nResult= GetServerNameAndInstallDB(); if (nResult = BACK) goto Dlg_GetDBOptions; if bvDataDB|| bvSystemDB then svSQLDataRoot=GetRealSqlInstallPath(svServer,svUserName,svPassword,"master",SUPPORTDIR,"sqlPath.txt"); if CheckIf2DBExist(DB_NAME)==TRUE then SdShowMsg("Install Database ['"+DB_NAME+"']" ,TRUE); InstallDB(DB_NAME,svServer,svUserName,svPassword); SdShowMsg("",FALSE); endif; endif;

szNumName  = "ServerName"; szNumValue =svServer; nType      = REGDB_STRING; nSize      = -1; szKey = "SOFTWARE\\ACOM Solutions\\"+@PRODUCT_NAME; CreateRegistryKey(szKey, szNumName, nType, szNumValue, nSize,TRUE);

szNumName  = "RapidEPMDBName"; szNumValue =DB_NAME; nType      = REGDB_STRING; nSize      = -1; szKey = "SOFTWARE\\ACOM Solutions\\"+@PRODUCT_NAME; CreateRegistryKey(szKey, szNumName, nType, szNumValue, nSize,TRUE);

szNumName  = "Version"; szNumValue =@PRODUCT_VERSION; nType      = REGDB_STRING; nSize      = -1; szKey = "SOFTWARE\\ACOM Solutions\\"+@PRODUCT_NAME; CreateRegistryKey(szKey, szNumName, nType, szNumValue, nSize,TRUE);

szNumName  = "KeyValueVersion"; szNumValue =nKeyValue; nType      = REGDB_STRING; nSize      = -1; szKey = "SOFTWARE\\ACOM Solutions\\"+@PRODUCT_NAME; CreateRegistryKey(szKey, szNumName, nType, szNumValue, nSize,TRUE);

endif; endwhile; // Close the file. CloseFile (nFileHandle); // Remove the list from memory. ListDestroy (listID);

Dlg_SdAskDestPath2: szTitle = ""; szMsg = ""; if (nSetupType = CUSTOM) then nResult = SdAskDestPath2( szTitle, szMsg, szDir ); TARGETDIR = szDir; endif; if (nResult = BACK) then if(bCheckYesNoDB=TRUE) then goto  Dlg_SdAskInstallDB; else goto  Dlg_SdWelcome; endif; endif; Dlg_SdFeatureTree: if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SdAskDestPath2; szTitle = ""; szMsg = ""; szFeatures = ""; nLevel = 2; if (nSetupType = CUSTOM) then nResult = SdFeatureTree( szTitle, szMsg, TARGETDIR, szFeatures, nLevel ); if (nResult = BACK) goto Dlg_SdAskDestPath2; endif; Dlg_ObjDialogs: nResult = ShowObjWizardPages( nResult ); if (nResult = BACK) goto Dlg_SdFeatureTree; Dlg_SdStartCopy2: szTitle = ""; szMsg = ""; nResult = SdStartCopy2( szTitle, szMsg ); if (nResult = BACK) goto Dlg_ObjDialogs; // Added in 11.0 - Set appropriate StatusEx static text. SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_FIRSTUI ) ); FeatureSetTarget( MEDIA , "<EZLICENSE>" , EZLICENSE ); return 0; end;

//=========================================================================== // //  Topic:    GetInstallPath // //  Description: // //  My Name    : // //===========================================================================

function STRING GetInstallPath() string szIgnore, szMsg; number nResult; BOOL bOpt1, bOpt2; STRING szKey, szNumName, szNumValue, svNumValue, szTitle; NUMBER nType, nSize, nvType, nvSize; NUMBER nLocation; STRING  svSubStr; STRING RESULT; STRING szPathRegistry; begin

RESULT=""; szNumName  = "Path"; szNumValue = ""; nType      = REGDB_STRING; nSize      = -1; szPathRegistry ="\\"+@PRODUCT_NAME+"\\"; szKey = "SOFTWARE\\ACOM Solutions\\" + @PRODUCT_NAME ;

RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE); if (RegDBGetKeyValueEx (szKey, szNumName, nvType, svNumValue, nvSize) < 0) then else RESULT= svNumValue;

endif; return RESULT;

end;

//=========================================================================== // //  Topic:    CheckApplicationRunning // //  Description: // //  My Name    : // //=========================================================================== function BOOL CheckApplicationRunning(svNumValue,install) string szIgnore, szMsg; number nResult; BOOL bOpt1, bOpt2; NUMBER nType, nSize, nvType, nvSize; NUMBER nLocation; STRING  svSubStr,svExistingVersion; NUMBER resultDeleteFormLib; STRING svResult; BOOL FormsLibExist; STRING szRuningFile; STRING szMsg1,szMsg2,szMsg3,szMsg4;

begin szRuningFile="\\"+@SETUP_FILE+""; if FindFile(svNumValue,@SETUP_FILE,svResult)==0 then VerGetFileVersion(svNumValue^@SETUP_FILE,svExistingVersion); if VerCompare ( svExistingVersion, "2.6.0.0", VERSION )==LESS_THAN then bvLaunchLicense=TRUE; endif;

CopyFile(svNumValue+"\\EZRetrieve.exe",svNumValue+"\\EZDesigner4001.exe"); if DeleteFile(svNumValue+"\\EZRetrieve.exe")!=0 then DeleteFile(svNumValue+"\\EZDesigner4001.exe"); if install==FALSE then szMsg1="Uninstalling process cannot be continued because"; szMsg2=" "+@PRODUCT_NAME + " "; szMsg3="is in use. Please close it and try again."; szMsg4=szMsg1+szMsg2+szMsg3; MessageBox(szMsg4,WARNING); abort; return FALSE; else szMsg1=" "+@PRODUCT_NAME + " "; szMsg2="cannot be upgraded because it is in use. Please close it and try again."; MessageBox(szMsg1+szMsg2,WARNING); abort; return FALSE; endif; else endif; else bvLaunchLicense=TRUE; endif; end; //=========================================================================== // //  Topic:    CheckSQLInstallAndInstall // //  Description: // //  My Name    : // //=========================================================================== function int CheckSQLInstallAndInstall() STRING szMsg, szText1, szText2, szText3, szText4, szText5; STRING szText6, szText7, szText8, szText9; NUMBER nReturn, nValue,  nvCheck1, nvCheck2, nvCheck3, nvCheck4; NUMBER nvCheck5, nvCheck6, nvCheck7, nvCheck8, nvCheck9; INT nLocation; begin if  CheckSQl2005ProOrExpressInstalled()==TRUE then GetOptions: szMsg = "Database Server Choice"; szText1 = "Use an existing SQL Server"; szText2 = "Install SQL Server 2005 Express now"; nvCheck1 = TRUE; nvCheck2 = FALSE; nValue = EXCLUSIVE; nReturn=AskOptions (nValue, szMsg, szText1, nvCheck1, szText2, nvCheck2); if(nReturn==BACK) then return nReturn; else endif;

if nvCheck1==TRUE then endif; if nvCheck2==TRUE then nReturn=GetInstanceNamePassAndInstall(); if  nReturn=BACK then goto GetOptions; endif; endif; else if AskYesNo("Microsoft SQL Server 2005 Express was not installed in your system. \n\nWould you like to install it now?",YES)==YES  then nReturn=GetInstanceNamePassAndInstall(); if  nReturn=BACK then return nReturn; endif; else endif;

endif; end; //=========================================================================== // //  Topic:    CheckSQLInstallAndInstall // //  Description: // //  My Name    : // //===========================================================================

function BOOL CheckSQl2005ProOrExpressInstalled() BOOL result; begin

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); result=FALSE; if RegDBKeyExist ("SOFTWARE\\Microsoft\\Microsoft SQL Server\\90")==1 then result=TRUE; //MessageBox("co",WARNING); else result=FALSE; // MessageBox("khong",WARNING); endif; return result; end; //=========================================================================== // //  Topic:    GetServerNameAndInstallDB // //  Description: // //  My Name    : // //=========================================================================== function NUMBER GetServerNameAndInstallDB() NUMBER nResult; STRING svUpperDBName1,svUpperDBName2; begin Dlg_AskDBInformation: if svServer="" then svServer=GetServerName(); endif; if svUserName="" then svUserName="sa"; endif; if DB_NAME="" then DB_NAME="DatabaseName"; endif; if installEXpressGoodOrBad then svServer=svServer; endif; nResult = Get_Server_UserName_Pass("Database Login Information",bvInstallDB,svServer, svUserName,svPassword,DB_NAME,DB_NAME,bvDataDB,bvSystemDB); if nResult != BACK then if bvInstallDB =TRUE then SdShowMsg("",FALSE); SdShowMsg("Testing database connection and permissions for " + svUserName + "...",TRUE); if !TestDB(svServer,svUserName,svPassword) then MessageBox("Cannot connect to "+svServer+". \n\nPlease check the entered information again.", WARNING); SdShowMsg("",FALSE); goto Dlg_AskDBInformation; endif; SdShowMsg("",FALSE); StrToUpper(svUpperDBName1,DB_NAME); StrReplace(svUpperDBName1," ","",0); StrReplace(svUpperDBName2," ","",0); if(bvDataDB==TRUE && svUpperDBName1=="") || ( bvSystemDB==TRUE && svUpperDBName1=="") then MessageBox("Please enter Database Name.", WARNING); goto Dlg_AskDBInformation; endif; if  StrCompare(svUpperDBName1,svUpperDBName2)=0 && bvDataDB==TRUE && bvSystemDB==TRUE then MessageBox("Data Database Name must be different from System Database Name.\n\nPlease try again.", WARNING); goto Dlg_AskDBInformation; endif; endif; endif; return nResult; end; //=========================================================================== // //  Topic:    GetRealSqlInstallPath // //  Description: // //  My Name    : // //===========================================================================

function STRING GetRealSqlInstallPath(svServer0,svUser1,svPass2,dbName,svFilePath,svFileName) string para; STRING  szFileName, szPath, szText, svLine,fullPath,svResult; NUMBER  nFlag, nFileHandle; LIST   listID; begin

svResult=""; fullPath= svFilePath^ svFileName; para="\"" + svServer0 + "\" \""+svUser1+"\" \""+svPass2+"\" \""+dbName+"\" \""+fullPath+"\""; if LaunchAppAndWait (SUPPORTDIR ^ "GetSqlPath.exe", para, LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN)==0 then //MessageBox("thanh cong",WARNING); else //MessageBox("fail",WARNING); endif; OpenFileMode (FILE_MODE_NORMAL); if OpenFile (nFileHandle, svFilePath, svFileName)==0 then //MessageBox("moduoc"+svFilePath+svFileName,WARNING); else //MessageBox("khong moduoc"+svFilePath+svFileName,WARNING);

endif; while (GetLine (nFileHandle, svLine) = 0) // MessageBox(svLine,WARNING); svResult=svLine  ; endwhile; // Close the file. CloseFile (nFileHandle); DeleteFile(fullPath); return svLine; end; //=========================================================================== // //  Topic:    CheckIf2DBExist // //  Description: // //  My Name    : // //=========================================================================== function BOOL CheckIf2DBExist(svDBName1) NUMBER nResult; begin if GetRealSqlInstallPath(svServer,svUserName,svPassword,DB_NAME,SUPPORTDIR,"sqlPath.txt")!="" then

nResult = MessageBox( "Database [" + svDBName1 + "] has already existed, do you want to delete?", MB_YESNO ); if (nResult == IDYES ) then SdShowMsg("Delete Database ["+svDBName1+"]",TRUE); if( Delete1DB(svDBName1) <0) then SdShowMsg("",FALSE); return  FALSE; endif; SdShowMsg("",FALSE); else return FALSE; endif; else if (Is (FILE_EXISTS, svSQLDataRoot + svDBName1  + "_Log.ldf" )==TRUE) then DeleteFile(svSQLDataRoot + svDBName1  + "_Log.ldf"); DeleteFile(svSQLDataRoot + svDBName1  + ".mdf"); return FALSE; endif; endif; return TRUE; end; //=========================================================================== // //  Topic:    Delete1DB // //  Description: // //  My Name    : // //=========================================================================== function Delete1DB(svDBName) STRING szPath, szFileName; NUMBER nResult, nvFileHandle, nvType, nvSize, nvIndex; begin // Write the batch file to the TEMP directory szPath = WINDISK + "\\"; szFileName = "deleteDB.sql"; CreateFile(nvFileHandle, szPath, szFileName); WriteLine(nvFileHandle, "USE master"); WriteLine(nvFileHandle, "GO"); WriteLine(nvFileHandle, "IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'" + svDBName + "')"); WriteLine(nvFileHandle, "DROP DATABASE [" + svDBName + "]"); WriteLine(nvFileHandle, "GO"); CloseFile(nvFileHandle); // Run the batch file nResult = ExcuteSqlFile(szPath  + szFileName); // Check if database was installed if(nResult < 0 ) then MessageBox("Cannot drop the database ["+svDBName+"] because it is currently in use.", SEVERE); endif; SdShowMsg("",FALSE); return nResult; end; //=========================================================================== // //  Topic:    ExcuteSqlFile // //  Description: // //  My Name    : // //=========================================================================== function NUMBER ExcuteSqlFile(fileSql) STRING szPath, szFileName; NUMBER nResult, nvFileHandle; begin szPath = WINDISK + "\\"; szFileName = "excutesql.bat"; CreateFile(nvFileHandle, szPath, szFileName);

WriteLine(nvFileHandle, "@echo off"); WriteLine(nvFileHandle, "echo This window will close itself when it is finished."); WriteLine(nvFileHandle, ""); WriteLine(nvFileHandle, "echo Excute sql"); WriteLine(nvFileHandle, GetPathToOsql()+" -b -n -U " + svUserName + " -P " + svPassword + " -i \"" + fileSql + "\" -S " + svServer); WriteLine(nvFileHandle, "if errorlevel 1 goto pauseError"); WriteLine(nvFileHandle, "echo All Done"); WriteLine(nvFileHandle, "exit"); WriteLine(nvFileHandle, ":pauseError"); WriteLine(nvFileHandle, "echo DB Error > \"" + szPath ^ "\\deleteDB.fail\""); // WriteLine(nvFileHandle, "pause"); CloseFile(nvFileHandle); //thuc hien chay file bat nResult = LaunchAppAndWait(szPath ^ szFileName, "", WAIT |LAAW_OPTION_HIDDEN ); // Check if database was installed if( Is (FILE_EXISTS, szPath ^ "deleteDB.fail")==TRUE ) then CleanTempFiles(); return -1; endif; return 0; end; //=========================================================================== // //  Topic:    GetPathToOsql // //  Description: // //  My Name    : // //=========================================================================== function string GetPathToOsql() STRING szKey, szNumName, szNumValue, svNumValue; STRING result; NUMBER    nResult, nType, nMediaFlags,nSize; begin

nType      = REGDB_STRING; nSize      = -1; result=""; result=GetRegistryValue("SOFTWARE\\Microsoft\\Microsoft SQL Server\\90\\Tools\\ClientSetup","Path",nType,nSize); result="\""    +  result+"\\osql.exe\""; return result;

end; //=========================================================================== // //  Topic:    InstallDB // //  Description: // //  My Name    : // //=========================================================================== function InstallDB(svDBName1,DB_SERVER_NAME,DB_ADMIN_USER,DB_ADMIN_PASS) STRING szPath, svFileName; STRING svSQLDataLogRoot; NUMBER nResult, nvFileHandle, nvType, nvSize; STRING strDescription1,strDescription2; STRING svRapidEPMData,svEZConnectExpressSystem; STRING archive_folder,error_folder,receive_folder,send_folder,setup_folder; INT nLocation; NUMBER nType; STRING sz_Data,sz_Log; begin

CleanTempFiles(); svSQLDataRoot=GetRealSqlInstallPath(DB_SERVER_NAME,DB_ADMIN_USER,DB_ADMIN_PASS,"master",SUPPORTDIR,"sqlPath.txt"); szPath = WINDISK + "\\"; if(szPath="") then MessageBox("Installed DB failed on Server Other!",WARNING); InformFinish(); endif; VarSave(SRCTARGETDIR); //svRapidEPMData="Lib_EDI"; svRapidEPMData=@DATABASE_NAME; SRCDIR =  SRCDIR + "\\DB"; TARGETDIR = WINDISK + "\\"; if bvDataDB then nResult = XCopyFile(svRapidEPMData+".mdf", "", COMP_NORMAL); // In 7.0 its ok to szPath as target... if nResult < 0 then MessageBox("DB could not be copied from the DB subdirectory of the installation media.", SEVERE); CleanTempFiles(); //abort; InformFinish(); endif; endif; VarRestore(SRCTARGETDIR); svFileName = "installdb.bat"; //GetSqlDataRootExpress(svSQLDataRoot); if StrCompare(svSQLDataRoot, "") == 0 then MessageBox("You do not have the database server components\ninstalled on this machine. You will need to\ninstall these before your can install the database.", SEVERE); CleanTempFiles(); //abort; InformFinish(); endif; svSQLDataRoot=svSQLDataRoot; if Is(FILE_EXISTS,svSQLDataRoot)!=TRUE then CreateDir(svSQLDataRoot); endif;

svSQLDataLogRoot=svSQLDataRoot; svSQLDataLogRoot=svSQLDataLogRoot+"\\"; svSQLDataRoot=svSQLDataRoot+"\\";

svFileName = "installdb.sql"; OpenFileMode(FILE_MODE_NORMAL); nResult = CreateFile(nvFileHandle, szPath, svFileName); if nResult < 0 then MessageBox("SQL script not created!", SEVERE); CleanTempFiles(); //abort; InformFinish(); endif; sz_Data=@DATABASE_DATA; sz_Log=@DATABASE_LOG; WriteLine(nvFileHandle, "USE master"); if bvDataDB then WriteLine(nvFileHandle, "GO"); WriteLine(nvFileHandle, "RESTORE DATABASE " + svDBName1); WriteLine(nvFileHandle, "FROM DISK = '" + szPath + "\\"+svRapidEPMData+".mdf'"); //WriteLine(nvFileHandle, "WITH  MOVE '" + svRapidEPMData + "' TO '" + svSQLDataRoot + svDBName1 + ".mdf', "); //WriteLine(nvFileHandle, "MOVE '" + svRapidEPMData + "_Log' TO '" + svSQLDataLogRoot +  svDBName1 + "_Log.ldf'"); //WriteLine(nvFileHandle, "WITH  MOVE '" + "aa" + "' TO '" + svSQLDataRoot + svDBName1 + ".mdf', "); //WriteLine(nvFileHandle, "MOVE '" + "aa_Log" + "' TO '" + svSQLDataLogRoot +  svDBName1 + "_Log.ldf'"); WriteLine(nvFileHandle, "WITH  MOVE '" + "Lib_EDI_Data" + "' TO '" + svSQLDataRoot + svDBName1 + ".mdf', "); WriteLine(nvFileHandle, "MOVE '" + "Lib_EDI_Log" + "' TO '" + svSQLDataLogRoot +  svDBName1 + "_Log.ldf'"); //WriteLine(nvFileHandle, "    MOVE '" + svRapidEPMData + "_Data' TO '" + SQLPATH + "\\Data\\" + svDBName1  + "_Data.mdf', "); //WriteLine(nvFileHandle, "    MOVE '" + svRapidEPMData + "_Log' TO '" + SQLPATH  + "\\Data\\" + svDBName1  + "_Log.ldf'"); //WriteLine(nvFileHandle, "WITH  MOVE '" + sz_Data + "' TO '" + svSQLDataRoot + svDBName1 + ".mdf', "); //WriteLine(nvFileHandle, "MOVE '" + sz_Log + "' TO '" + svSQLDataLogRoot +  svDBName1 + "_Log.ldf'");

WriteLine(nvFileHandle, "GO"); WriteLine(nvFileHandle, "USE " + svDBName1); WriteLine(nvFileHandle, "GO"); WriteLine(nvFileHandle, "EXEC sp_updatestats"); WriteLine(nvFileHandle, "GO"); endif; WriteLine(nvFileHandle, "USE master"); WriteLine(nvFileHandle, "GO"); WriteLine(nvFileHandle, "if (select count(*) from sys.syslogins where name = '"+ DEFAULTUSERLOGIN + "') < 1"); WriteLine(nvFileHandle, "BEGIN"); WriteLine(nvFileHandle, "    EXEC sp_addlogin '" + DEFAULTUSERLOGIN + "', '"+ DEFAULTPASSLOGIN + "', '" + svDBName1 + "', NULL, NULL"); WriteLine(nvFileHandle, "END"); WriteLine(nvFileHandle, "GO"); WriteLine(nvFileHandle, "USE " + svDBName1); WriteLine(nvFileHandle, "EXEC sp_grantdbaccess '"+ DEFAULTUSERLOGIN +"'"); WriteLine(nvFileHandle, "GO"); WriteLine(nvFileHandle, "EXEC sp_addrolemember 'db_owner', '" + DEFAULTUSERLOGIN + "'"); WriteLine(nvFileHandle, "GO"); CloseFile(nvFileHandle); svFileName = "installdb.bat"; OpenFileMode(FILE_MODE_NORMAL); nResult = CreateFile(nvFileHandle, szPath, svFileName); if nResult < 0 then MessageBox("Batch not created!", SEVERE); CleanTempFiles(); InformFinish(); endif; WriteLine(nvFileHandle, "@echo off"); WriteLine(nvFileHandle, "echo This window will close itself when it is finished."); WriteLine(nvFileHandle, ""); WriteLine(nvFileHandle, "echo Creating Database"); WriteLine(nvFileHandle, GetPathToOsql() + " -b -n -U " + DB_ADMIN_USER + " -P " + DB_ADMIN_PASS + " -i \"" + szPath + "\\installdb.sql\" -S " + DB_SERVER_NAME); WriteLine(nvFileHandle, "if errorlevel 1 goto pauseError"); WriteLine(nvFileHandle, "echo All Done"); WriteLine(nvFileHandle, "exit"); WriteLine(nvFileHandle, ":pauseError"); WriteLine(nvFileHandle, "echo DB Error > " + szPath + "installdb.fail"); WriteLine(nvFileHandle, ""); WriteLine(nvFileHandle, "echo The database could not be created.  Please see error message above"); WriteLine(nvFileHandle, "echo to address the problem."); //WriteLine(nvFileHandle, "pause"); WriteLine(nvFileHandle, "exit"); CloseFile(nvFileHandle); // Run the batch file nResult = LaunchAppAndWait(szPath ^ svFileName, "", WAIT |LAAW_OPTION_HIDDEN ); if( Is (FILE_EXISTS, szPath ^ "installdb.fail") ==TRUE) then MessageBox("DB Installation failed.\n\nPlease make sure that SQL Server 2005 is installed and that\nyou have the correct database connection information.\n\nAfter you have done that, please try the installation again.", SEVERE); CleanTempFiles(); InformFinish(); endif; CleanTempFiles(); return nResult; end; //=========================================================================== // //  Topic:    CleanTempFiles // //  Description: // //  My Name    : // //=========================================================================== function CleanTempFiles() STRING szFileName; begin

szFileName=@DATABASE_NAME; VarSave(SRCTARGETDIR); TARGETDIR = WINDISK + "\\"; DeleteFile(szFileName+".mdf"); DeleteFile("RapidEPM.mdf"); DeleteFile("installdb.sql"); DeleteFile("installdb.bat"); DeleteFile("installdb.fail"); DeleteFile("excutesql.bat"); DeleteFile("deleteDB.fail"); DeleteFile("aspnet_regiis.exe"); DeleteFile("deleteDB.sql"); DeleteFile("YServer.txt"); DeleteFile("LogfileEncode.txt"); //DeleteFile("updater.sql"); VarRestore(SRCTARGETDIR);

end; //=========================================================================== // //  Topic:    GetInstanceNamePassAndInstall // //  Description: // //  My Name    : // //=========================================================================== function INT GetInstanceNamePassAndInstall() INT nReturn; begin

Start_GetDBInfo: nReturn=AskCreateNewLogin(); if nReturn==BACK then return nReturn; endif; if  sqlExpressInstanceName="" || svPassword2="" then MessageBox("Please input Server and Admin Password.",WARNING); goto  Start_GetDBInfo; endif; if( InstalledSQLExpress(sqlExpressInstanceName)==TRUE) then MessageBox("The " + sqlExpressInstanceName + " instance already exists on SQLExpress. \n\nPlease choose another instance of SQLExpress to continue with this install.", WARNING); goto Start_GetDBInfo; endif; InsSQLExpress(sqlExpressInstanceName,svPassword2) ; CheckInstallSuccess(sqlExpressInstanceName); end; //////////////////////////////////////////////////////////////////////////// // //  Function: InsSQLExpress // //  Purpose: Install new instance SQLExpress /////////////////////////////////////////////////////////////////////////////// function BOOL InsSQLExpress(SQLInstallName,DB_ADMIN_PASS) STRING szPath, szFileNameIni, szFileNameBat, svResult, svNewResult; NUMBER nResult, nvFileHandle, nvIdx; NUMBER nvType, nvSize; STRING svSQLDataRoot,DB_SERVER_NAME,svPathSQL; STRING fullPath,fultPathWinlater;

begin

OpenFileMode (FILE_MODE_APPEND); szPath = WINDISK + "\\"; szFileNameIni = "installsQLExpress.ini"; //szFileNameBat = "installSQLExpress.bat"; if svPathSQL =="" then svPathSQL = PROGRAMFILES +"\\Microsoft SQL Server"; endif; if ! Is (PATH_EXISTS, svPathSQL)  then CreateDir(svPathSQL); endif; if CreateFile(nvFileHandle, szPath, szFileNameIni) == 0 then WriteLine(nvFileHandle, "[Options]"); WriteLine(nvFileHandle, "USERNAME=User"); WriteLine(nvFileHandle, "COMPANYNAME=Company"); WriteLine(nvFileHandle, "INSTALLSQLDIR=" + svPathSQL); WriteLine(nvFileHandle, "ADDLOCAL=ALL"); WriteLine(nvFileHandle, "INSTANCENAME="+SQLInstallName); WriteLine(nvFileHandle, "SECURITYMODE=SQL"); WriteLine(nvFileHandle, "DISABLENETWORKPROTOCOLS=0"); WriteLine(nvFileHandle, "SAPWD="+DB_ADMIN_PASS); CloseFile(nvFileHandle); endif; fullPath =  SRCDIR + "\\SQL2005 Express\\SQLEXPR32.EXE"; if Is(FILE_EXISTS, fullPath)==FALSE then MessageBox("File SQLEXPR32.EXE not exist on 'SQL2005 Express' folder.", WARNING); //abort; InformFinish(); endif; nResult=LaunchAppAndWait(fullPath ,"/qb /settings " +  WINDISK ^ szFileNameIni, WAIT|LAAW_OPTION_HIDDEN); DeleteFile(WINDISK ^ szFileNameIni); return nResult; end; //=========================================================================== // //  Topic:    CheckInstallSuccess // //  Description: // //  My Name    : // //===========================================================================

function  CheckInstallSuccess(SQLInstallName) NUMBER  nResult, nvType; NUMBER  nLevel; NUMBER  nvSize, nSetupType; NUMBER  nId; STRING  szTitle, szMsg, szMsg1, szMsg2; STRING  szOpt1, szOpt2, szLicenseFile; STRING  szName, szCompany; STRING  szTargetPath; STRING  svDir; STRING  szFeatures, szTargetdir; STRING  szId; BOOL bvCheck1, bvCheck2, bvNewInstanceSQL; NUMBER bvOpt1 , bvOpt2;

begin if RegDBKeyExist("SOFTWARE\\Microsoft\\Microsoft SQL Server\\"+ SQLInstallName)==1 then installEXpressGoodOrBad=TRUE; else MessageBox("SQL Server 2005 Express install did not successfully",SEVERE); //abort; InformFinish(); endif; end; //=========================================================================== // //  Topic:    InformFinish // //  Description: // //  My Name    : // //=========================================================================== function InformFinish() NUMBER  nResult, nLevel, nSize, nSetupType; STRING  szTitle, szMsg, szOpt1, szOpt2, szLicenseFile; STRING  szName, szCompany, szTargetPath, szDir, szFeatures; BOOL    bLicenseAccepted; STRING   szProductName; STRING   szMsg1, szMsg2; BOOL     bvOpt1, bvOpt2; NUMBER   nReturn; NUMBER     nType, nMediaFlags; STRING    szIgnore,svOldPath; STRING szKey, szNumName, szNumValue, svNumValue;

begin szTitle =@PRODUCT_NAME + " Installation is not Completed."; szMsg1  =@PRODUCT_NAME + " Installation is not Completed. Please setup again." ; szMsg2  = "Click Finish to complete %P Setup."; SdFinish (szTitle, szMsg1, szMsg2, szOpt1, szOpt2, bvOpt1, bvOpt2); abort;

end; //=========================================================================== // //  Topic:    InstalledSQLExpress // //  Description: // //  My Name    : // //=========================================================================== function InstalledSQLExpress(IntantSQLName) NUMBER nvType, nvSize; STRING svSQLDataRoot; begin RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE); if RegDBKeyExist("SOFTWARE\\Microsoft\\Microsoft SQL Server\\"+IntantSQLName)==1 then return TRUE; else return FALSE; endif; end; //=========================================================================== // //  Topic:    AskCreateNewLogin // //  Description: // //  My Name    : // //=========================================================================== function NUMBER AskCreateNewLogin() NUMBER nResult; begin GetLoginNameAndPass: nResult=Get_UserName_Pass("",bvCreateNewLogin,sqlExpressInstanceName,svPassword2,svConfirmPassword2); if nResult==BACK then return BACK;

endif;

if nResult!=BACK then if bvCreateNewLogin==TRUE then if svPassword2!=svConfirmPassword2 then MessageBox("The password and confirm password fields do not match.",WARNING); goto GetLoginNameAndPass;

endif; endif; else

endif; return nResult; end; //=========================================================================== // //  Topic:    GetServerName // //  Description: // //  My Name    : // //=========================================================================== function STRING GetServerName() NUMBER nvResult, nResult, nvType, nvSize, nvFileHandle; STRING svServerName; begin

svServerName=""; RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE); nvType = REGDB_STRING; //GetSqlDataRootExpress(svSQLDataRoot); RegDBGetKeyValueEx ("SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName", "ComputerName", nvType, svServerName, nvSize); if bIsSQLExpress then svServerName = svServerName + "\\SQLExpress";

endif; return svServerName; end; //=========================================================================== // //  Topic:    TestDB // //  Description: // //  My Name    : // //=========================================================================== function TestDB(svServer,svUserName,svPassword) STRING svFileName, szPath; NUMBER nvFileHandle, nResult, nvType, nvSize; begin

CleanTempFiles(); szPath = WINDISK + "\\"; RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE); nvType = REGDB_STRING; // Create / Drop database SQL script svFileName = "installdb.sql"; OpenFileMode(FILE_MODE_NORMAL); nResult = CreateFile(nvFileHandle, szPath, svFileName); if nResult < 0 then MessageBox("SQL script not created!", SEVERE); CleanTempFiles(); //abort; InformFinish(); endif; WriteLine(nvFileHandle, "USE master"); WriteLine(nvFileHandle, "GO"); WriteLine(nvFileHandle, "CREATE DATABASE EZPMTESTME123"); WriteLine(nvFileHandle, "GO"); WriteLine(nvFileHandle, "DROP DATABASE EZPMTESTME123"); WriteLine(nvFileHandle, "GO"); CloseFile(nvFileHandle);

// Call SQL and detect error or not svFileName = "installdb.bat"; OpenFileMode(FILE_MODE_NORMAL); nResult = CreateFile(nvFileHandle, szPath, svFileName); if nResult < 0 then MessageBox("Batch not created!", SEVERE); CleanTempFiles(); //abort; InformFinish(); endif; WriteLine(nvFileHandle, "@echo off"); WriteLine(nvFileHandle, "echo Testing database connection and permissions for " + svUserName + "..."); WriteLine(nvFileHandle, GetPathToOsql()+" -b -n -U " + svUserName + " -P " + svPassword + " -i \"" + szPath ^ "installdb.sql\" -S " + svServer); WriteLine(nvFileHandle, "if errorlevel 1 goto pauseError"); WriteLine(nvFileHandle, "exit"); // Fatal! WriteLine(nvFileHandle, ":pauseError"); WriteLine(nvFileHandle, "echo Connection/Permission Error > " + szPath + "installdb.fail"); WriteLine(nvFileHandle, "exit"); CloseFile(nvFileHandle); // Run the batch file nResult = LaunchAppAndWait(szPath ^ svFileName, "",WAIT|LAAW_OPTION_HIDDEN); if( Is (FILE_EXISTS, szPath ^ "installdb.fail") ==TRUE) then CleanTempFiles(); return FALSE; endif; CleanTempFiles(); return TRUE; end; //=========================================================================== // //  Topic:    DeleteAndCopyFile // //  Description: // //  My Name    : // //===========================================================================

function DeleteAndCopyFile() NUMBER nResult; STRING fullParth; STRING pathToAsp; NUMBER  nvFileHandle; STRING  svLine,svPath,svUseDatabase ; STRING svDatabaseName,szInsertLine,szPathCopy; STRING   xCopyFile,svDisk; begin

DeleteFile(SUPPORTDIR+"\\GetSqlPath.exe"); DeleteFile(SUPPORTDIR+"\\UpdateWebconfig.exe"); DeleteFile(SUPPORTDIR+"\\aspnet_regiis.exe"); DeleteFile(SUPPORTDIR+"\\UpdateDatabase.exe"); DeleteFile(SUPPORTDIR+"\\LinkWeb.exe"); DeleteFile(SUPPORTDIR+"\\RapidEPMWebconfig.exe"); DeleteFile(SUPPORTDIR+"\\Uninstall.exe"); DeleteFile(SUPPORTDIR+"\\EditBeforWebconfig.exe"); DeleteFile(SUPPORTDIR+"\\RapidBitmap.bmp"); DeleteFile(SUPPORTDIR+"\\RemoveWebconfig.exe"); DeleteFile(SUPPORTDIR+"\\AssignPool.vbs"); DeleteFile(SUPPORTDIR+"\\GetProcessIDTest.exe"); DeleteFile(SUPPORTDIR+"\\Encode_Decode.exe");

xCopyFile=SRCDIR+"sqlscript\\updater.sql"; svDisk=WINDISK +"\\"; CopyFile(xCopyFile ,svDisk^"updater.sql"); //After Copy File in others into SUPPORTDIR XCopyFile(SRCDIR+"\\others\\*.*",SUPPORTDIR+"\\*.*",COMP_NORMAL); end; /////////////////////////////////////////////////////////////////////////////// // // Function: CheckCustomerKey // //  Purpose: This function checks the registry, CD file called CustomerKey.txt //           and then prompts user if not found. //

/////////////////////////////////////////////////////////////////////////////// function CheckCustomerKey() NUMBER nvType, nvSize, nFileHandle, nResult; STRING szTitle, szMsg; begin

RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE); nvType = REGDB_STRING; // Check registry if StrCompare(CUSTOMER_KEY,"") = 0 then RegDBGetKeyValueEx(@LICENSE_BASE, "CustomerKey", nvType, CUSTOMER_KEY, nvSize); if StrLength(CUSTOMER_KEY) > 0 && StrLength(CUSTOMER_KEY) != 36 then MessageBox("The Customer Key in the registry was not 36 characters" , WARNING); CUSTOMER_KEY = ""; elseif StrLength(CUSTOMER_KEY) == 36 then bByPassCustomerKey = TRUE; endif; // Check file if StrCompare(CUSTOMER_KEY,"") = 0 && Is(FILE_EXISTS, SRCDIR ^ "CustomerKey.txt") then OpenFileMode(FILE_MODE_BINARYREADONLY); OpenFile(nFileHandle, SRCDIR + "\\", "CustomerKey.txt"); ReadBytes(nFileHandle, CUSTOMER_KEY, 0, 36); CloseFile(nFileHandle);

if StrLength(CUSTOMER_KEY) != 36 then MessageBox("The Customer Key \"" + CUSTOMER_KEY + "\" in CustomerKey.txt on the CD was not 36 characters" , WARNING); CUSTOMER_KEY = ""; else bByPassCustomerKey = TRUE; endif; endif; elseif StrLength(CUSTOMER_KEY) != 36 then CUSTOMER_KEY = ""; endif; szTitle  = ""; szMsg    = "What is your Customer Key?\nIf you are not sure, please contact ACOM support.\nTel: (800)217-2266  Email: support@acom.com"; nResult=GetCustomerKey( szTitle,szMsg,CUSTOMER_KEY,"Customer Key Information","Please enter your Customer Key information."); if (nResult = BACK) then return BACK; endif; return NEXT; end; /////////////////////////////////////////////////////////////////////////////// // // Function: CreateRegistryKey // //  Purpose: This function checks the registry, CD file called CustomerKey.txt //           and then prompts user if not found. // /////////////////////////////////////////////////////////////////////////////// function CreateRegistryKey(szKey, szNumName, nType, szNumValue, nSize,blnWillBeDeleteWhenUninstall) STRING szMsg; begin

RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE); if blnWillBeDeleteWhenUninstall=FALSE then Disable(LOGGING); endif; if (RegDBCreateKeyEx (szKey, "") < 0) then else if (RegDBSetKeyValueEx (szKey, szNumName, nType, szNumValue, nSize) < 0) then else endif; endif; if blnWillBeDeleteWhenUninstall=FALSE then Enable(LOGGING); endif; end; /////////////////////////////////////////////////////////////////////////////// // // Function: CreateRegistryKey // //  Purpose: This function checks the registry, CD file called CustomerKey.txt //           and then prompts user if not found. // /////////////////////////////////////////////////////////////////////////////// function STRING GetRegistryValue(szKey,szNumName,nvType,nvSize) STRING RESULT,svNumValue; begin

RESULT=""; RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE); if (RegDBGetKeyValueEx (szKey, szNumName, nvType, svNumValue, nvSize) < 0) then else RESULT= svNumValue;

endif; return RESULT;

end; /////////////////////////////////////////////////////////////////////////////// // // Function: CreateRegistryKey // //  Purpose: This function checks the registry, CD file called CustomerKey.txt //           and then prompts user if not found. ///////////////////////////////////////////////////////////////////////////////

function CreateShortCut(szProgramFolder,szItemName,szProgram,szWorkingDir,willBeDeleteWhenUninstall) STRING  szCommandLine; STRING  szIconPath, szShortCutKey, szParam; STRING szKey, szNumName, szNumValue, svNumValue, szMsg; NUMBER  nIcon, nFlag, nFlag2, nResult; begin LongPathToQuote (szProgram, TRUE); szCommandLine = szProgram; //szWorkingDir  = TARGETDIR; szIconPath    = ""; nIcon         = 0; szShortCutKey = ""; nFlag         = NULL; if willBeDeleteWhenUninstall==TRUE then

nResult = AddFolderIcon (szProgramFolder, szItemName, szCommandLine, szWorkingDir, szIconPath, nIcon, szShortCutKey, nFlag); else Disable(LOGGING); nResult = AddFolderIcon (szProgramFolder, szItemName, szCommandLine, szWorkingDir, szIconPath, nIcon, szShortCutKey, nFlag);

Enable(LOGGING); endif; end; //=========================================================================== // //  Topic:    DeleteDB_SQLServer // //  Description: // //  My Name    : // //===========================================================================

function DeleteDB_SQLServer() STRING szPath, szFileName; NUMBER nResult, nvFileHandle, nvType, nvSize, nvIndex; begin

// Write the batch file to the TEMP directory szPath = WINDISK + "\\"; szFileName = "deleteDB.sql"; CreateFile(nvFileHandle, szPath, szFileName); WriteLine(nvFileHandle, "USE master"); WriteLine(nvFileHandle, "GO"); if DB_NAME!="" && bvDataDB==TRUE then WriteLine(nvFileHandle, "IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'" + DB_NAME + "')"); WriteLine(nvFileHandle, "DROP DATABASE [" + DB_NAME + "]"); WriteLine(nvFileHandle, "GO"); endif; CloseFile(nvFileHandle); // Run the batch file nResult = ExcuteSqlFile(szPath  + szFileName); // Check if database was installed if(nResult < 0 ) then MessageBox("Cannot drop the database because it is currently in use.", SEVERE); endif; SdShowMsg("",FALSE); return nResult; end;

//--------------------------------------------------------------------------- // OnMaintUIBefore // // Maintenance UI Sequence - Before Move Data // // The OnMaintUIBefore event is called by OnShowUI when the setup is // running in maintenance mode. By default this event displays UI that // allows the end user to add or remove features, repair currently // installed features or uninstall the application. // // Note: This event will not be called automatically in a // program...endprogram style setup. //--------------------------------------------------------------------------- function OnMaintUIBefore() NUMBER    nResult, nType, nMediaFlags,nSize; STRING    szTitle, szMsg, szIgnore; STRING szPathPrograms; STRING szKey, szNumName, szNumValue, svNumValue,szValueData; STRING    svOldPath,svPAT; NUMBER  nFlag, nFileHandle; LIST   listID; STRING svPath,svFile; BOOL bResult; STRING svDir; STRING szDir; STRING    nKeyValue,svEdit1; STRING path; STRING szID; STRING svUpperDBName1,svUpperDBName2; begin

nType = REMOVEALL; //Initialize SQL OnSQLServerInitializeMaint();

// Beginning of UI Sequence Dlg_Start:

// Added in Version 9.5 - Support for REMOVEONLY option. if( !REMOVEONLY ) then // In standard mode show maintenance dialog Disable( BACKBUTTON ); nType = SdWelcomeMaint( szTitle, szMsg, nType ); //nType = SdRemoveAndRepair( szTitle, szMsg, nType );

Enable( BACKBUTTON ); nResult = NEXT; else // Hide the initial progress dialog as otherwise the user can // click on it, and hide the MessageBox. Disable( DIALOGCACHE );

// In RemoveOnly mode, set to remove. nType = REMOVEALL; endif;

// Show Uninstall Confirmation Dialog if ( nType = REMOVEALL ) then nResult = MessageBox( SdLoadString( IFX_MAINTUI_MSG ), MB_YESNO ); if (nResult != IDYES ) then

if( REMOVEONLY ) then // In REMOVEONLY mode, abort the setup. abort; else // In non-REMOVEONLY mode, redisplay the previous dialog. goto Dlg_Start; endif;

endif; endif;

Dlg_SdFeatureTree: if ( nType = MODIFY ) then szTitle = ""; szMsg = SdLoadString( SD_STR_COMPONENT_MAINT_MSG ); nResult = SdFeatureTree( szTitle, szMsg, TARGETDIR, "", -1 ); if ( nResult = BACK ) goto Dlg_Start; endif;

Dlg_ObjDialogs: nResult = ShowObjWizardPages( nResult ); if ( ( nResult = BACK ) && ( nType != MODIFY ) ) goto Dlg_Start; if ( ( nResult = BACK ) && ( nType = MODIFY ) ) goto Dlg_SdFeatureTree;

switch(nType)

case REMOVEALL:

CheckRuningProcess(); //svPAT=GetInstallPath(); //CheckApplicationRunning(svPAT,FALSE); // Ensure that all previously installed features are removed // for media that supports updating. MediaGetData( MEDIA, MEDIA_FIELD_MEDIA_FLAGS, nMediaFlags, szIgnore );

if( nMediaFlags & MEDIA_FLAG_UPDATEMODE_SUPPORTED ) then FeatureRemoveAllInMediaAndLog(); else FeatureRemoveAllInMedia(); endif;

// Added in 11.0 - Set appropriate StatusEx static text. SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REMOVEALL ) ); case REPAIR: CheckRuningProcess(); listID = ListCreate (STRINGLIST); // Set the file mode to normal. OpenFileMode (FILE_MODE_NORMAL); // Open the file for editing. svPath=SRCDIR; svFile="Config.ini"; OpenFile (nFileHandle, svPath, svFile); while (GetLine (nFileHandle, svLine) = 0) ListAddString (listID, svLine, AFTER); StrSub ( svReadLine, svLine, 25,40); StrSub(svReadLineNumber,svLine,0,2); if(svReadLineNumber=="10" && svReadLine== " YES") then //MessageBox("vao chua ??",WARNING); //    Dialog Select install Dlg_SelectInstallDataAndDB: svDir   = TARGETDIR; szTitle = @PRODUCT_NAME+" "+"Feature Selection"; szMsg   = "Select the features you want to update on your computer."; Dlg_ChoseTaget:

nResult=SdAskOptions (SDASKOPTSTITLE, SDASKOPTSMSG1, SDASKOPTSMSG2,"", FEATURE, NONEXCLUSIVE);

if(nResult==BACK) then goto Dlg_Start: endif;

bvInstallData = FeatureIsItemSelected(MEDIA, "Update Project"); bvInstallDB = FeatureIsItemSelected(MEDIA, "Update  Project Database"); if  bvInstallData==FALSE && bvInstallDB==FALSE then MessageBox("No feature selected. You have to select at least one feature to be installed into your PC. ",SEVERE); goto Dlg_ChoseTaget; endif; if bvInstallData==TRUE then //MessageBox(" Bat dau update Du lieu.",WARNING);

if( ADDREMOVE ) then FeatureUpdate( "" );  // disk1 features. else FeatureReinstall();  // Reinstall all previously installed features. endif;

// Added in 11.0 - Set appropriate StatusEx static text. SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REPAIR ) ); endif; if bvInstallDB==TRUE then if svServer="" then svServer=GetServerName(); endif; if svUserName="" then svUserName="sa"; endif; DBName=GetRegistryValue2("SOFTWARE\\ACOM Solutions\\EDIViewer","RapidEPMDBName"); if DBName="" then DBName="DatabaseName"; endif; //MessageBox(" hay Code updater script cho data base di.",WARNING); Dlg_UpdaterDB: nResult = Get_Server_UserName_Pass("Database Login Information",bvInstallDB,svServer, svUserName,svPassword,DBName,DB_NAME,bvDataDB,bvSystemDB); if nResult != BACK then if bvInstallDB =TRUE then SdShowMsg("",FALSE); SdShowMsg("Testing database connection and permissions for " + svUserName + "...",TRUE); if !TestDB(svServer,svUserName,svPassword) then //MessageBox("The Server/Username/Password you supplied cannot be used to create a database.\n\nPlease try again.", WARNING); MessageBox("Cannot connect to "+svServer+". \n\nPlease check the entered information again.", WARNING);

SdShowMsg("",FALSE); goto Dlg_UpdaterDB: abort; endif; SdShowMsg("",FALSE); StrToUpper(svUpperDBName1,DBName); StrReplace(svUpperDBName1," ","",0); StrReplace(svUpperDBName2," ","",0); if(bvDataDB==TRUE && svUpperDBName1=="") || ( bvSystemDB==TRUE && svUpperDBName1=="") then MessageBox("Please enter Database Name.", WARNING); goto Dlg_UpdaterDB; endif; if  StrCompare(svUpperDBName1,svUpperDBName2)=0 && bvDataDB==TRUE && bvSystemDB==TRUE then MessageBox("Data Database Name must be different from System Database Name.\n\nPlease try again.", WARNING); goto Dlg_UpdaterDB; endif; ActionUpdater();    //Dua hµm thuc thi script vao day /*Dlg_SQLServer:

nResult = OnSQLServerInitialize( nResult ); if( nResult = BACK ) goto Dlg_SdFeatureTree;*/

endif; else goto Dlg_SelectInstallDataAndDB; //abort; endif; endif; endif; endwhile;

// Close the file. CloseFile (nFileHandle); // Remove the list from memory. ListDestroy (listID); //svPAT=GetInstallPath(); //CheckApplicationRunning(svPAT,FALSE); if( ADDREMOVE ) then FeatureUpdate( "" );  // disk1 features. else FeatureReinstall();  // Reinstall all previously installed features. endif;

// Added in 11.0 - Set appropriate StatusEx static text. SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REPAIR ) ); // szNumName  = "Path"; szNumValue = TARGETDIR; nType      = REGDB_STRING; nSize      = -1; szKey = "SOFTWARE\\ACOM Solutions\\"+@PRODUCT_NAME; CreateRegistryKey(szKey, szNumName, nType, szNumValue, nSize,TRUE);

szNumName  = "ServerName"; szNumValue =svServer; nType      = REGDB_STRING; nSize      = -1; szKey = "SOFTWARE\\ACOM Solutions\\"+@PRODUCT_NAME; CreateRegistryKey(szKey, szNumName, nType, szNumValue, nSize,TRUE);

szNumName  = "RapidEPMDBName"; szNumValue =DB_NAME; nType      = REGDB_STRING; nSize      = -1; szKey = "SOFTWARE\\ACOM Solutions\\"+@PRODUCT_NAME; CreateRegistryKey(szKey, szNumName, nType, szNumValue, nSize,TRUE);

szNumName  = "Version"; szNumValue =@PRODUCT_VERSION; nType      = REGDB_STRING; nSize      = -1; szKey = "SOFTWARE\\ACOM Solutions\\"+@PRODUCT_NAME; CreateRegistryKey(szKey, szNumName, nType, szNumValue, nSize,TRUE);

szPathPrograms="\\"+@PRODUCT_NAME+"\\"; CreateShortCut(FOLDER_DESKTOP,@PRODUCT_NAME,TARGETDIR^@SETUP_FILE,TARGETDIR,TRUE); //CreateShortCut(FOLDER_PROGRAMS,@COMPANY_NAME+"\\EPM\\Link localhost EPM",EZLICENSE^"LinkWeb.exe",EZLICENSE,TRUE); CreateShortCut(FOLDER_PROGRAMS,@COMPANY_NAME +szPathPrograms+ @PRODUCT_NAME,TARGETDIR^@SETUP_FILE,TARGETDIR,TRUE); //CreateShortCut(FOLDER_PROGRAMS,@COMPANY_NAME+"\\EPM\\Config EPM",EZLICENSE^"RapidEPMWebconfig.exe",EZLICENSE,TRUE); //CreateShortCut(FOLDER_PROGRAMS,@COMPANY_NAME +szPathPrograms+ @PRODUCT_NAME,TARGETDIR^"EZconfig.exe",TARGETDIR,TRUE); CreateShortCut(FOLDER_PROGRAMS,@COMPANY_NAME +szPathPrograms+"\\EZconfig",TARGETDIR^"EZconfig.exe",TARGETDIR,TRUE);

case MODIFY:

// Added in 11.0 - Set appropriate StatusEx static text. SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_MODIFY ) );

endswitch;

end; //=========================================================================== // //  Topic:    GetRegistryValue2 // //  Description: // //  My Name    : // //=========================================================================== function STRING GetRegistryValue2(szKey,szNumName) STRING RESULT,svNumValue; NUMBER  nvType, nvSize; begin

RESULT=""; RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE); if (RegDBGetKeyValueEx (szKey, szNumName, nvType, svNumValue, nvSize) < 0) then else RESULT= svNumValue;

endif; return RESULT;

end; //=========================================================================== // //  Topic:    ActionUpdater // //  Description: // //  My Name    : // //=========================================================================== function ActionUpdater()

STRING svlogfiles,svsqlfile,sverrorfile; STRING xCopy; STRING    szFFile,szDDir; NUMBER nvFileHandle; STRING svPath,svFolder,xCopyFile,svDisk,svReplaceDB; STRING svLogFileName,svfileName; begin

svFolder=WINDISK+"\\Log File"; DeleteDir(svFolder,ALLCONTENTS); szDDir=WINDISK +"\\Log File";

//CreateFile (nvFileHandle, EXAMPLE_DIR, EXAMPLE_FILE); CreateDir (svPath ^ szDDir);

svLogFileName=WINDISK+"\\LogFile.txt";

svfileName=WINDISK+"\\updater.sql";

sverrorfile=WINDISK+"\\CheckFile.txt";

svReplaceDB="RapidEPM123456789";

//UpdateDatabase(svServer,svUserName,svPassword,RapidEPMDBName,svlogfiles,svsqlfile ,sverrorfile,svReplaceDB); UpdaterScript(svServer,DBName,svUserName,svPassword,svfileName,svLogFileName ); xCopy=WINDISK + "\\";

// MessageBox(svFolder,WARNING);

//CopyFile(xcopy ^ "Web.config",TARGETDIR ^"Web.config"); CopyFile(xCopy ^ "LogFile.txt",svFolder^"LogFile.txt"); CopyFile(xCopy ^ "updater.sql",svFolder^"updater.sql"); CopyFile(xCopy ^ "CheckFile.txt",svFolder^"CheckFile.txt");

DeleteFile(xCopy ^ "LogFile.txt"); DeleteFile(xCopy ^ "updater.sql"); DeleteFile(xCopy ^ "CheckFile.txt"); end; //=========================================================================== // //  Topic:    UpdaterScript // //  Description: // //  My Name    : // //=========================================================================== function STRING UpdaterScript(svServerName,dbName,svUserName,svPassword,svfileName,svlogFileName)

STRING  szFileName, szPath, szText, svLine,fullPath,svResult; NUMBER  nFlag, nFileHandle; LIST   listID; STRING para,svDisk,xCopyFile; begin //para="\"" + svServerName + "\" \""+svUserName+"\" \""+svPassword+"\" \""+dbName+"\" \""+svfileName+"\" \""+svlogFileName+"\ \""; para="\"" + svServerName + "\" \""+dbName+"\" \""+svUserName+"\" \""+svPassword+"\" \""+svfileName+"\" \""+svlogFileName+"\ \"";

xCopyFile=SRCDIR+"others\\TestDB.exe"; svDisk=WINDISK +"\\"; CopyFile(xCopyFile ,svDisk^"TestDB.exe"); if LaunchAppAndWait (WINDISK ^ "TestDB.exe", para, LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN)<0 then //MessageBox(" khong thanh cong"+"\n"+para,WARNING); else //MessageBox("thanh cong roi" +"\n" + para,WARNING); endif; DeleteFile(svDisk ^ "TestDB.exe"); end; //--------------------------------------------------------------------------- // OnFirstUIAfter // // First Install UI Sequence - After Move Data // // The OnFirstUIAfter event called by OnShowUI after the file transfer // of the setup when the setup is running in first install mode. By default // this event displays UI that informs the end user that the setup has been // completed successfully. // // Note: This event will not be called automatically in a // program...endprogram style setup. //--------------------------------------------------------------------------- function OnFirstUIAfter() STRING szTitle, szMsg1, szMsg2, szOpt1, szOpt2; NUMBER bvOpt1, bvOpt2; NUMBER bShowUpdateServiceDlg; STRING szPathPrograms; begin

ShowObjWizardPages(NEXT);

szTitle = ""; szMsg1 = ""; szMsg2 = ""; szOpt1 = ""; szOpt2 = ""; bvOpt1   = FALSE; bvOpt2   = FALSE; szPathPrograms="\\"+@PRODUCT_NAME+"\\"; CreateShortCut(FOLDER_DESKTOP,@PRODUCT_NAME,TARGETDIR^@SETUP_FILE,TARGETDIR,TRUE); //CreateShortCut(FOLDER_PROGRAMS,@COMPANY_NAME+"\\EPM\\Link localhost EPM",EZLICENSE^"LinkWeb.exe",EZLICENSE,TRUE); CreateShortCut(FOLDER_PROGRAMS,@COMPANY_NAME +szPathPrograms+ @PRODUCT_NAME,TARGETDIR^@SETUP_FILE,TARGETDIR,TRUE); //CreateShortCut(FOLDER_PROGRAMS,@COMPANY_NAME+"\\EPM\\Config EPM",EZLICENSE^"RapidEPMWebconfig.exe",EZLICENSE,TRUE); CreateShortCut(FOLDER_PROGRAMS,@COMPANY_NAME +szPathPrograms+"\\EZconfig",TARGETDIR^"EZconfig.exe",TARGETDIR,TRUE);

// Set this to true if you have the update service enabled, and if you want to check for updates. // Note: the ISUS Starter Edition does not support checking for updates programatically.  So, // only set this to true if you have at least the ISUS Professional Edition. bShowUpdateServiceDlg = FALSE; if ( BATCH_INSTALL ) then SdFinishReboot ( szTitle , szMsg1 , SYS_BOOTMACHINE , szMsg2 , 0 ); else

// If the update service is enabled, show finish dialog that includes // update check option. if( bShowUpdateServiceDlg && ( ENABLED_ISERVICES & SERVICE_ISUPDATE ) ) then if( SdFinishUpdateEx( szTitle, szMsg1, szMsg2, szOpt1, szOpt2, TRUE ) ) then if( MODE != SILENTMODE ) then UpdateServiceCheckForUpdates( "", FALSE ); endif; endif; else SdFinish ( szTitle , szMsg1 , szMsg2 , szOpt1 , szOpt2 , bvOpt1 , bvOpt2 ); endif; endif; end;

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: