使用 VBS 和注册表确定安装的版本以及 32 位和 64 位 Oracle 驱动程序

Cha*_*adD 3 oracle vbscript

我想使用 VBS 读取注册表以列出服务器上的一些信息,包括驱动程序。

视频BS:

REM Run this file with the following command:
REM cscript  drivers.vbs | clip

WScript.Echo "------------------------------------------------"

Const HKEY_LOCAL_MACHINE = &H80000002

'Get Server Name
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
strComputerName = wshNetwork.ComputerName
WScript.Echo "Computer Name: " & strComputerName

'Get Driver Names  
strComputer = "."
 
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"
objRegistry.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes


For i = 0 to UBound(arrValueNames)
    strValueName = arrValueNames(i)
    objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue    
    Wscript.Echo arrValueNames(i) & " -- " & strValue
Next

Set objShell = WScript.CreateObject("WScript.Shell")

'Get Oracle Environment variables
WScript.Echo "TNS_ADMIN=" & objShell.Environment("SYSTEM").Item("TNS_ADMIN")
WScript.Echo "ORACLE_HOME=" & objShell.Environment("SYSTEM").Item("ORACLE_HOME")


WScript.Echo "------------------------------------------------"
Run Code Online (Sandbox Code Playgroud)

输出:

------------------------------------------------
Computer Name: WLDL2532
SQL Server -- Installed
Client Access ODBC Driver (32-bit) -- Installed
iSeries Access ODBC Driver -- Installed
SQL Server Native Client 10.0 -- Installed
**Oracle in OraClient11g_home1 -- Installed**
IBM DB2 ODBC DRIVER - DB2_976_64 -- Installed
IBM DB2 ODBC DRIVER -- Installed
ODBC Driver 11 for SQL Server -- Installed
DataDirect 6.1 Sybase Wire Protocol -- Installed
SQL Server Native Client 11.0 -- Installed
TNS_ADMIN=C:\WINDOWS\TNS
ORACLE_HOME=
------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

我想知道如何分别列出是否安装了32位驱动程序或64位Oracle驱动程序。我的机器上都有,但它没有指出是哪一个。我想,这可能意味着两者或其中之一。通常,如果找到 32 位驱动程序,我希望在名称中看到“32”。

另外,我很想知道在注册表中哪里可以最好地查找此信息。

Wer*_*eit 5

根据您的 VBS 代码,问题应该是:使用 VBS 和注册表来确定安装了哪个版本以及 32 位与 64 位ODBC驱动程序

还有许多其他驱动程序可用于 Oracle,例如 OleDB、ODP.NET、JDBC 等。

为了获得 32 位和 64 位,您可以通过两种方式进行

在不同的脚本主机中运行 VBS,即

For 64 Bit: >c:\Windows\system32\cscript.exe Drivers.vbs
For 32 Bit: >c:\Windows\SysWOW64\cscript.exe Drivers.vbs
Run Code Online (Sandbox Code Playgroud)

或者修改 VBS 脚本以询问注册表中的 32 位和 64 位路径:

strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"
objRegistry.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes

For i = 0 to UBound(arrValueNames)
    strValueName = arrValueNames(i)
    objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue    
    Wscript.Echo arrValueNames(i) & " -- 64 Bit " & strValue
Next

strKeyPath = "SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\ODBC Drivers"
objRegistry.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes

For i = 0 to UBound(arrValueNames)
    strValueName = arrValueNames(i)
    objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue    
    Wscript.Echo arrValueNames(i) & " -- 32 Bit " & strValue
Next
Run Code Online (Sandbox Code Playgroud)

另请注意:TNS_ADMINORACLE_HOME可以通过环境变量定义,但是您也可以在注册表中定义它们。检查是否为 64 位

HKLM\SOFTWARE\ORACLE\Key_{ORACLE_HOME_NAME}\TNS_ADMIN 
and 
HKLM\SOFTWARE\ORACLE\Key_{ORACLE_HOME_NAME}\ORACLE_HOME
Run Code Online (Sandbox Code Playgroud)

对于 32 位

HKLM\SOFTWARE\Wow6432Node\ORACLE\Key_{ORACLE_HOME_NAME}\TNS_ADMIN
and
HKLM\SOFTWARE\Wow6432Node\ORACLE\Key_{ORACLE_HOME_NAME}\ORACLE_HOME
Run Code Online (Sandbox Code Playgroud)

  • 是的当然。当您在 64 位 Windows 上运行 32 位应用程序时,它的运行方式就像在另一个虚拟 32 位 Windows 环境中一样。您无法访问“C:\Windows\System32”等文件夹或“HKLM\SOFTWARE\ORACLE”等注册表路径。它们会自动重定向到“c:\Windows\SysWOW64”。`HKLM\SOFTWARE\Wow6432Node\ORACLE`。请查看[Windows 64 位如何支持 32 位应用程序](http://www.techsupportalert.com/content/how-windows7-vista64-support-32bit-applications.htm) 以获取更多详细信息。 (2认同)