首页 > 代码库 > InstallShield集成安装MSDE2000最小版本(一) fishout特许授权发布

InstallShield集成安装MSDE2000最小版本(一) fishout特许授权发布

原文:InstallShield集成安装MSDE2000最小版本(一) fishout特许授权发布

原帖地址:http://blog.csdn.net/fishout/archive/2009/10/26/4730086.aspx

在网上看到许多关于MSDE2000集成到应用程序中一并安装的文章,这些方法无一例外都使用了InstallShield中调用外部命令的方式,其本质就是在安装过程中调用LaunchAppAndWait函数执行MSDE2000的setup.exe程序,这样一来,带来几个问题:
    1、无法与应用程序的安装一并卸载;
    2、无法实现MSDE2000的最小安装;
    3、如果用户中途取消安装,程序不能完全回滚;
    4、无法与应用程序安装到同一个目录。
    如果使用installshield中的预安装功能,也仅能在MSI工程中使用,同时,也不能灵活地控制安装过程及实现上述功能,为此,我们需要一种方法,用于在安装过程中集成MSDE2000。这是因为许多应用需要SQL Server支持,而MSDE2000确实是一个不错的选择,撇开版权不说,仅全面兼容SQL和支持2G的数据量就足够了,如果能解决安装时的集成问题,就会为极大地方便应用程序的分发。
    下面我通过具体实例来介绍这一方法。
    目标一:实现不可控的最小安装。
    一、数据准备:
    1、下载SQL Server 2000 Desktop Engine (MSDE) 组件(SQL2000.MSDE-KB884525-SP4-x86.EXE)
    2、双击下载的exe文件,解压缩至C:\SQL2KSP4,在运行中浏览至c:\SQL2KSP4\MSDE,找到setup.exe文件,双击它,不要急着点“确定”,在setup.exe后面空一格,接着输入安装参数:INSTANCENAME="fishout" SECURITYMODE=SQL SAPWD="fishout@TOM.COM" /L*v C:\MSDELog.log,点击确定(其中:INSTANCENAME="实例名",SAPWD="密码",可自行修改,以下均以命名实例“fishout”为例),待其安装完毕后不要启动服务,也不要重启机器,将C:\Program Files\Microsoft SQL Server\MSSQL$FISHOUT\文件夹下的binn、Data、log三个文件夹保留,其余的删除。
    3、准备注册表入口。打开注册表编辑器,导航至:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server,删除多余的子健,使其看上去如图所示:图一
  再在SuperSocketNetLib子键下面的ProtocolList属性中增加两个字符串:tcp/np,右击Microsoft SQL Server,选择导出注册表,文件名任意取,打开并编辑已导出的注册表文件,将安装路径“C:\Program Files\Microsoft SQL Server”替换为“<TARGETDIR>”,使其修改完成的注册表文件如下:

 

view plaincopy to clipboardprint?

  1. Windows Registry Editor Version 5.00   
  2. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server]   
  3. "InstalledInstances"=hex(7):46,00,49,00,53,00,48,00,4f,00,55,00,54,00,00,00,00,\   
  4.   00   
  5. "SsrpActiveServer"=""
  6. "SqlMdacRegRefCount"=dword:00000001   
  7. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT]   
  8. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer]   
  9. "AuditLevel"=dword:00000000   
  10. "DefaultLogin"="guest"
  11. "ListenOn"=hex(7):53,00,53,00,4d,00,53,00,53,00,48,00,37,00,30,00,00,00,53,00,\   
  12.   53,00,4e,00,45,00,54,00,4c,00,49,00,42,00,00,00,00,00   
  13. "LoginMode"=dword:00000000   
  14. "Map_"="\\"
  15. "Map#"="-"
  16. "Map$"=""
  17. "SetHostName"=dword:00000000   
  18. "Tapeloadwaittime"=dword:ffffffff   
  19. "uptime_pid"=dword:000000c8   
  20. "uptime_time_utc"=hex:0e,55,77,e8,59,58,ca,01   
  21. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer\CurrentVersion]   
  22. "CurrentVersion"="8.00.194"
  23. "RegisteredOwner"=""
  24. "SerialNumber"=""
  25. "CSDVersionNumber"=dword:00000400   
  26. "CSDVersion"="8.00.1100"
  27. "Language"=dword:00000804   
  28. "checksum"=hex:38,30,32,32,63,31,35,38,61,65,37,64,34,63,64,37,35,30,64,61,30,\   
  29.   33,34,62,36,30,31,34,32,63,62,61,66,37,30,33,30,38,35,35,65,62,64,63,34,34,\   
  30.   36,62,61,37,35,64,61,62,37,30,34,66,37,33,65,35,30,37,64,65,37,34,30,39,31,\   
  31.   32,65,62,39,35,65,62,36,62,63,37,64,64,37,32,66,62,36,65,39,32,63,61,66,63,\   
  32.   33,30,66,62,30,30,35,64,31,37,30,61,65,61,32,34,61,30,30,63,65,33,64,62,66,\   
  33.   62,61,39,64,61,64,65,30,36,36,30,66,31,62,63,63,35,32,37,33,63,32,62,33,30,\   
  34.   36,31,66,66,61,64,65,36,65,32,30,36,38,34,33,64,00   
  35. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer\Parameters]   
  36. "SQLArg0"="-d<TARGETDIR>\\MSSQL$FISHOUT\\Data\\master.mdf"
  37. "SQLArg1"="-e<TARGETDIR>\\MSSQL$FISHOUT\\LOG\\ERRORLOG"
  38. "SQLArg2"="-l<TARGETDIR>\\MSSQL$FISHOUT\\Data\\mastlog.ldf"
  39. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer\SuperSocketNetLib]   
  40. "ProtocolList"=hex(7):74,00,63,00,70,00,00,00,6e,00,70,00,00,00,00,00   
  41. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer\SuperSocketNetLib\Np]   
  42. "PipeName"="\\\\.\\pipe\\MSSQL$FISHOUT\\sql\\query"
  43. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer\SuperSocketNetLib\Tcp]   
  44. "TcpHideFlag"=dword:00000000   
  45. "TcpDynamicPorts"="0"
  46. "TcpPort"="0"
  47. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\Setup]   
  48. "FeatureName"="SqlRun"
  49. "FirstStart"=dword:00000000   
  50. "ProductCode"="{E09B48B5-E141-427A-AB0C-D3605127224A}"
  51. "SQLDataRoot"="<TARGETDIR>\\MSSQL$FISHOUT"
  52. "SQLPath"="<TARGETDIR>\\MSSQL$FISHOUT"
  53. "Edition"="Desktop Engine"
  54. "PatchLevel"="8.4.2039"

Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server] "InstalledInstances"=hex(7):46,00,49,00,53,00,48,00,4f,00,55,00,54,00,00,00,00,\ 00 "SsrpActiveServer"="" "SqlMdacRegRefCount"=dword:00000001 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT] [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer] "AuditLevel"=dword:00000000 "DefaultLogin"="guest" "ListenOn"=hex(7):53,00,53,00,4d,00,53,00,53,00,48,00,37,00,30,00,00,00,53,00,\ 53,00,4e,00,45,00,54,00,4c,00,49,00,42,00,00,00,00,00 "LoginMode"=dword:00000000 "Map_"="\\" "Map#"="-" "Map$"="" "SetHostName"=dword:00000000 "Tapeloadwaittime"=dword:ffffffff "uptime_pid"=dword:000000c8 "uptime_time_utc"=hex:0e,55,77,e8,59,58,ca,01 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer\CurrentVersion] "CurrentVersion"="8.00.194" "RegisteredOwner"="" "SerialNumber"="" "CSDVersionNumber"=dword:00000400 "CSDVersion"="8.00.1100" "Language"=dword:00000804 "checksum"=hex:38,30,32,32,63,31,35,38,61,65,37,64,34,63,64,37,35,30,64,61,30,\ 33,34,62,36,30,31,34,32,63,62,61,66,37,30,33,30,38,35,35,65,62,64,63,34,34,\ 36,62,61,37,35,64,61,62,37,30,34,66,37,33,65,35,30,37,64,65,37,34,30,39,31,\ 32,65,62,39,35,65,62,36,62,63,37,64,64,37,32,66,62,36,65,39,32,63,61,66,63,\ 33,30,66,62,30,30,35,64,31,37,30,61,65,61,32,34,61,30,30,63,65,33,64,62,66,\ 62,61,39,64,61,64,65,30,36,36,30,66,31,62,63,63,35,32,37,33,63,32,62,33,30,\ 36,31,66,66,61,64,65,36,65,32,30,36,38,34,33,64,00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer\Parameters] "SQLArg0"="-d<TARGETDIR>\\MSSQL$FISHOUT\\Data\\master.mdf" "SQLArg1"="-e<TARGETDIR>\\MSSQL$FISHOUT\\LOG\\ERRORLOG" "SQLArg2"="-l<TARGETDIR>\\MSSQL$FISHOUT\\Data\\mastlog.ldf" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer\SuperSocketNetLib] "ProtocolList"=hex(7):74,00,63,00,70,00,00,00,6e,00,70,00,00,00,00,00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer\SuperSocketNetLib\Np] "PipeName"="\\\\.\\pipe\\MSSQL$FISHOUT\\sql\\query" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\MSSQLServer\SuperSocketNetLib\Tcp] "TcpHideFlag"=dword:00000000 "TcpDynamicPorts"="0" "TcpPort"="0" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\FISHOUT\Setup] "FeatureName"="SqlRun" "FirstStart"=dword:00000000 "ProductCode"="{E09B48B5-E141-427A-AB0C-D3605127224A}" "SQLDataRoot"="<TARGETDIR>\\MSSQL$FISHOUT" "SQLPath"="<TARGETDIR>\\MSSQL$FISHOUT" "Edition"="Desktop Engine" "PatchLevel"="8.4.2039"

    二、设计制作安装程序:
    1、在installshield中新建一个InstallScript Project工程,命名为MDSE2000,在工程文件夹下新建files文件夹,复制刚才安装目录下MSSQL$FISHOUT文件夹到工程files中,复制C:\WINDOWS\System32\msvcp71.dll及msvcr71.dll文件到files\MSSQL$FISHOUT\Binn中(不要遗忘这个文件),设置Product Properties中TARGETDIR内容为:<FOLDER_APPLICATIONS>\Microsoft SQL Server,添加files中MSSQL$FISHOUT文件夹到Application Target Folder中。
    2、导入注册表。在Registry注册表入口中右击Destination Computer,单击New Registry Set,重命名为:MDSE2000,右击它,点击:Import REG File...,导入刚才已修改好的注册表设置,在右边勾选与此关联的安装文件组。
    3、在安装脚本中点选DefaultFeature,生成Installed事件,代码如下:

view plaincopy to clipboardprint?

  1. export prototype DefaultFeature_Installed();   
  2. function DefaultFeature_Installed()   
  3.     number nvServiceState;   
  4. string szServiceName, szServiceDisplayName, szServiceDescription, szServicePathFile, szStartServiceArgs;   
  5.     BOOL bStartService;   
  6. begin   
  7. // 安装服务
  8.     szServiceName = "MSSQL$FISHOUT";   
  9.     szServiceDisplayName = "MSSQL$FISHOUT";   
  10.     szServiceDescription = "";   
  11.     szServicePathFile = TARGETDIR ^ "mssql$fishout\\Binn\\sqlservr.exe -sFISHOUT";   
  12.     bStartService = TRUE;   
  13.     szStartServiceArgs = "";   
  14. if (ServiceGetServiceState (szServiceName, nvServiceState ) >= ISERR_SUCCESS) then   
  15. // 停止并卸载原来的服务
  16.         ServiceStopService ( szServiceName );   
  17.         ServiceRemoveService ( szServiceName );   
  18.     endif;   
  19.     ServiceAddService ( szServiceName, szServiceDisplayName, szServiceDescription, szServicePathFile, bStartService, szStartServiceArgs );   
  20. end; 

export prototype DefaultFeature_Installed(); function DefaultFeature_Installed() number nvServiceState; string szServiceName, szServiceDisplayName, szServiceDescription, szServicePathFile, szStartServiceArgs; BOOL bStartService; begin // 安装服务 szServiceName = "MSSQL$FISHOUT"; szServiceDisplayName = "MSSQL$FISHOUT"; szServiceDescription = ""; szServicePathFile = TARGETDIR ^ "mssql$fishout\\Binn\\sqlservr.exe -sFISHOUT"; bStartService = TRUE; szStartServiceArgs = ""; if (ServiceGetServiceState (szServiceName, nvServiceState ) >= ISERR_SUCCESS) then // 停止并卸载原来的服务 ServiceStopService ( szServiceName ); ServiceRemoveService ( szServiceName ); endif; ServiceAddService ( szServiceName, szServiceDisplayName, szServiceDescription, szServicePathFile, bStartService, szStartServiceArgs ); end;      4、编译生成安装程序,可以看到,生成的安装包仅有12.4兆,比微软原来的安装包要小多了,非常利于网络传输和应用程序的分发,不过,有一个致命的缺点,就是不支持安装路径的更改,这个问题,放在下一节解决。