Need help with GetObject("winmgmts:\\

AuntPeggy

Final Approach
PoA Supporter
Joined
May 23, 2006
Messages
8,480
Location
Oklahoma
Display Name

Display name:
Namaste
I need to work across domains and have begun studying online Microsoft TechNet about Writing WMI scripts. I haven't yet found how to apply permissions to run scripts on a machine under domain "fmsuz" that access machines on domain "sysk3". I know a user name and the administrator name and passwords for "sysk3", but don't know syntax to use it. Here is a test script. Any help will be appreciated.

Code:
'TestThis.vbs
 
For Each strComputer in Array ("MissionControl", "PMcMath", "Aardvark" )
 
 ' Which computer?
 msgbox strComputer
 
 ' This fails if computer is in a different domain (or if turned off)
 Set objSWbemServices = _
  GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
 ' Query for remote OS
 Set colItems = objSWbemServices.ExecQuery _
  ("Select * From Win32_OperatingSystem")
 
 ' Show remote OS (only one item is displayed )
 For Each objItem in ColItems
  Wscript.Echo strComputer & ": " & objItem.Caption
 Next
 
Next
 
' Machine is in a different domain
'---------------------------
'Windows Script Host
'---------------------------
'Script: ...\TestThis.vbs
'Line: 10
'Char: 2
'Error: Permission denied: 'GetObject'
'Code: 800A0046
'Source:  Microsoft VBScript runtime error
'
'---------------------------
'OK   
'---------------------------
 
' Machine is not available
'---------------------------
'Windows Script Host
'---------------------------
'Script: ...\TestThis.vbs
'Line: 10
'Char: 2
'Error: The remote server machine does not exist or is unavailable: 'GetObject'
'Code: 800A01CE
'Source:  Microsoft VBScript runtime error
'
'---------------------------
'OK   
'---------------------------
 
This also fails:
Code:
 ' This fails if computer is in a different domain (or if turned off)
 Set objSWbemServices = _
  GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
I found something that lets me cross domains. I still don't know how to make the rest work, though. I don't know yet whether this will allow me to execute scripts on the remote workstation.

Code:
' Create and connect service locator
 Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
 
 Set objWMIService = objwbemLocator.ConnectServer _
  (strComputer, strNamespace, strUser, strPassword)
 
' Display the disks on the remote workstation
 diskNames = strComputer & ": Disks"
 Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
 
 For Each objDisk in colDisks
  diskNames = diskNames & vbCrlf & objDisk.Name
 Next
 
 Wscript.Echo diskNames
 diskNames = ""

---------------------------
Windows Script Host
---------------------------
PMcMath: Disks
A:
C:
D:
E:
F:
M:
---------------------------
OK
---------------------------
 
Back
Top