问题:我们的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