Windows

如何在不使用包裝腳本的情況下對使用者 (.vbs) 隱藏正在執行的登錄腳本?

  • March 31, 2015

我有一個執行登錄腳本 (.vbs) 並將其連結到包含 W2012R2 RDS 主機的 OU 的 GPO(配置了環回替換)。

我對政策進行了這些(與問題相關的)更改:

Computer Configuration -> Policies -> Administrative Templates -> System -> Group Policy -> Configure Logon Script Delay -> Enabled -> minute: 0 

User Configuration -> Policies -> Windows Settings -> Scripts (Logon/Logoff) -> MyScript.vbs 

User Configuration -> Policies -> Administrative Templates -> System -> Run legacy logon scripts hidden -> Enabled 

User Configuration -> Policies -> Administrative Templates -> System -> Display instructions in logon scripts as they run -> Disabled

當使用者登錄時,腳本在前台完美執行,但根據我所做的設置,我本來希望命令提示符根本不會彈出。那麼我在這裡做錯了什麼,微軟對“遺留腳本”的定義到底是什麼?

我知道我可以編寫一個cscript.exe使用隱藏參數呼叫的小型“包裝腳本”,但我想保持它盡可能乾淨,並想了解為什麼我的設置不起作用。

我弄清楚是什麼原因造成的,因為我的 GPO 設置是正確的。我需要執行的腳本使用一個函式來強制使用 32 位版本的腳本主機。

Function fncForce32bitCscript()
   Dim strCurrentScriptHost : strCurrentScriptHost  = lcase(wscript.fullname)
   dim strRequiredScriptHost: strRequiredScriptHost = "c:\windows\system32\cscript.exe"
   if fncCheckOS = "X64" Then
       strRequiredScriptHost = "c:\windows\syswow64\cscript.exe"
   end If  

   Dim objShell
   Set objShell = CreateObject("WScript.Shell")
   objShell.run "cscript //h:cscript",0,True

   If strCurrentScriptHost = strRequiredScriptHost Then
       'no switching to cscript required
   Else
     Dim strArgColl
         strArgColl = " "
         If WScript.Arguments.Count>0 Then
           Dim ArgCollect
           For ArgCollect = 0 To WScript.Arguments.Count-1
             strArgColl = strArgColl & chr(34) & (WScript.Arguments.Item(ArgCollect)) & chr(34) & " "
           Next
         End If
         'wscript.echo "script will be re-launched with the required script host " & strRequiredScriptHost
         objShell.Run  "cmd /C " & strRequiredScriptHost & " " & WScript.ScriptFullName & " " & strArgColl,1,false
         'Set objShell = Nothing
         'wscript.sleep 3000
         WScript.Quit  
   End If
End Function

所以把這個電話換成cmd.exe……

'objShell.Run "cmd /C " & strRequiredScriptHost & " " & WScript.ScriptFullName & " " & strArgColl, 0, false

…這使它隱藏起來。任務完成。

objShell.Run strRequiredScriptHost & " " & WScript.ScriptFullName & " " & strArgColl, 0, false

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