我该如何检查,如果W脚本/ CSCRIPT 64主机操作系统上运行?我该、脚本、操作系统、主机

2023-09-07 23:55:08 作者:硬装

我跑,可能64位Windows下运行的VBScript。我需要从注册表中读取的32位部分的注册表项。对于我使用的路径 HKLM \ SOFTWARE \ Wow6432Node \某某而不是 HKLM \ SOFTWARE \某某。我该如何检查脚本在x64执行?

I'm running a VBScript that may run under x64 Windows. I need to read a registry key from the 32-bit part of the registry. For that I use path HKLM\Software\Wow6432Node\xyz instead of HKLM\Software\xyz. How can I check if the script is executed under x64?

推荐答案

我不知道你需要检查,如果脚本是在x64执行。

I'm not sure you need to check if the script is executing under x64.

尝试从 HKLM读\ SOFTWARE \ Wow6432Node \某某,如果失败,则尝试从 HKLM \ SOFTWARE \某某,如果失败,你的注册表项不存在,采取任何行动是合适的。

Try to read from HKLM\Software\Wow6432Node\xyz, if that fails, try to read from HKLM\Software\xyz, if that fails, your registry key doesn't exist, take whatever action is appropriate.

当然,如果你的设计更为复杂(例如,你写一个值,如果它不存在的注册表项),那么该建议是行不通的。

Of course, if your design is more complicated (for example, you write a value into that registry key if it doesn't exist) then that suggestion won't work.

下面是一个VBScript用于检查操作系统。你可能还需要属性的解释可从的Win32_OperatingSystem类

Here is a VBScript for examining the operating system. You'll probably also need explanation of the Properties available from the Win32_OperatingSystem Class

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")        

Set colOperatingSystems = objWMIService.ExecQuery _
	("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
	msg = objOperatingSystem.Caption & " " & _
			objOperatingSystem.Version & " " & _
				objOperatingSystem.OSArchitecture
	msgbox msg
Next

请注意,对于Windows XP和2003, OSArchitecture 不可用,在这种情况下,你将有可能不得不检查无论是标题版本来确定您的操作系统是64位的。

Note that for Windows XP and 2003, OSArchitecture is not available, in which case you will probably have to examine either the Caption or Version to determine whether your OS is 64-bit.

您也可以使用像这视你需要的复杂程度。

You could also use something like this depending on the level of complexity you require.