Powershell

登錄時使用 VBScript 確定是否安裝了 powershell

  • April 26, 2012

我的網路上混合了 Win7 和 XP 機器。每個使用者都使用基於 VBS 的登錄腳本登錄,對於支持它的客戶端,我想顯示一個資訊彈出視窗,如此處所示

如何檢測是否使用 VBScript 安裝了 Powershell?

您可以使用以下內容。它讀取 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

用於檢查應用程序系統資料庫的 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

引用自:https://serverfault.com/questions/383427