installer registry access in windows server 2012

陌路散爱 提交于 2019-12-13 03:24:46

问题


I have a custom action in an Installshield Basic MSI project to find out the version of SQL Server from registry.

RegKey2012 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\" & _
             "Microsoft SQL Server\MSSQL11.MSSQLSERVER\"
If RegKeyExists(RegKey2012) Then 
  WScript.StdOut.Write("2012") 
Else 
  WScript.StdOut.Write("2008R2") 
End If 

Function RegKeyExists(Key) 
  Dim oShell, entry 
  On Error Resume Next 
  Set oShell = CreateObject("WScript.Shell") 
  entry = oShell.RegRead(Key) 
  If Err.Number <> 0 Then 
    Err.Clear 
    RegKeyExists = False 
  Else 
    Err.Clear 
    RegKeyExists = True 
  End If 
End Function

The installer works fine on a Windows 7 machine. The above script works fine in isolation on a Windows Server 2012 machine. However when I run the installer (as ADMIN) on windows server 2012, it does not work as expected and the error description is - It cannot find the registry key.

Any ideas.


回答1:


strkey="HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\Setup" & Chr(34) &  " /v Version /reg:64"

Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("REG QUERY " & Chr(34) & strkey )

strText = objScriptExec.StdOut.ReadAll()
if (strText <> "") then
WScript.echo "2012"
else
WScript.echo "2008R2"
end if

Note the /reg:64 option in line1. Without that it was not working.



来源:https://stackoverflow.com/questions/14384235/installer-registry-access-in-windows-server-2012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!