在登录时使用 VBScript 确定是否安装了 powershell

Chr*_*ski 4 powershell logon-scripts vbscript

我的网络上混合了 Win7 和 XP 计算机。每个用户都使用基于 VBS 的登录脚本登录,对于支持它的客户端,我想显示一个信息弹出窗口,如下所示

如何检测是否使用 VBScript 安装了 Powershell?

小智 5

您可以使用以下内容。它读取 PowerShell 的注册表项。如果读取成功(返回代码 0),您会收到相应的消息框,您可以将其切换为其他需要执行的逻辑——例如,如果未检测到,则安装 PowerShell。有关更多信息,请参阅下面的源链接。

Option Explicit
Dim oShell
Dim value

'If the key isn't there when we try to read it, an error will be generated
'that we will later test for, so we want to automatically resume execution.
On Error Resume Next

'#Try reading the registry value
Set oShell = CreateObject("WScript.Shell")
value = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\")

'Catch the error
If Err.Number = 0 Then
    'Error code 0 indicates success
    MsgBox(Err.Number & "PowerShell is installed.")
Else
    'Any other error code indicates failure
    MsgBox(Err.Number & "PowerShell is NOT installed.")
End If
Run Code Online (Sandbox Code Playgroud)

用于检查应用程序注册表的 VBScript(例如 .NET):https : //stackoverflow.com/questions/4394607/vbscript-to-check-if-net-2-0-is-installed

用于检查 PowerShell 的注册表项:http : //blogs.msdn.com/b/powershell/archive/2009/06/25/detection-logic-poweshell-installation.aspx