問題:我們的Cobol應用程序可從我們的網絡上的許多服務器(主要是服務器2003)運行。許多(如果不是全部)這些應用程序使用環境變量進行設置。獲取遠程服務器環境變量
問題:從一個工作站可以從已知服務器遠程列表中收集環境變量的完整列表嗎?最好我想在批處理,VBS或Powershell中做到這一點。
答案:在VBS
GetEnvironment("[RemoteServersName]")
Function GetEnvironment(ServerName)
strComputer = ServerName
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer _
(strComputer, "root\cimv2", "[ValidLogonName]", "[PasswordForLogonName]")
objSWbemServices.Security_.ImpersonationLevel = 3
Set colVar = objSWbemServices.ExecQuery(_
"Select * from Win32_Environment")
For Each objVar in colVar
WScript.StdOut.Write("Server Name: " & ServerName & VBNewLine)
WScript.StdOut.Write("Description: " & objVar.Description & VBNewLine)
WScript.StdOut.Write("Name: " & objVar.Name & VBNewLine)
WScript.StdOut.Write("System Variable: " & objVar.SystemVariable & VBNewLine)
WScript.StdOut.Write("User Name: " & objVar.UserName & VBNewLine)
WScript.StdOut.Write("Variable Value: " & objVar.VariableValue & VBNewLine & VBNewLine)
Next
End Function
只好用這個頁面以及http://msdn.microsoft.com/en- us/library/aa389290(VS.85).aspx,但是謝謝! – 2010-01-15 14:16:17
相關提示:) – ghostdog74 2010-01-15 14:20:42