WillShakespeare
MIS
Hi All,
Here's some code:
My problem is that I get an error:
If I change strComputer to ".", then all works fine. The problem I have is I am full Domain Administrator, and want to access all computers on the network for a more complicated script above, and gather information from them. I wrote this script months ago, and tested and ran it, and it worked fine. Now, suddenly it doesn't work! I can't seem to find out why it should suddenly not work. The above is only test code.
I have also used:
instead of the winmgmts Moniker. But I get an Access Denied error.
Now the kicker... I use the above code successfully with a script that has been running for over 10 months now on our server that checks disk space, but when I run the above sample script on the server (instead of my workstation), it still does not work!!
I must be doing something wrong! Can anyone help?
Will
![[morning] [morning] [morning]](/data/assets/smilies/morning.gif)
PS, here is the actual code I want to work, that worked a few months ago:
Here's some code:
Code:
1: strComputer = "uk-itspare02"
2: Set objWMIService = GetObject("winmgmts:" _
3: & "{impersonationLevel=impersonate}!\\" & _
4: strComputer & "\root\cimv2")
5: Set colComputer = objWMIService.ExecQuery _
6: ("Select * from Win32_ComputerSystem")
7:
8: For Each objComputer in colComputer
9: Wscript.Echo objComputer.UserName
10: Next
[b]For cut 'n paste:[/b]
strComputer = "uk-itspare02"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
Wscript.Echo objComputer.UserName
Next
My problem is that I get an error:
MyComputer said:(Error at line: 2)
Microsoft VBScript runtime error: Permission denied: 'GetObject'
If I change strComputer to ".", then all works fine. The problem I have is I am full Domain Administrator, and want to access all computers on the network for a more complicated script above, and gather information from them. I wrote this script months ago, and tested and ran it, and it worked fine. Now, suddenly it doesn't work! I can't seem to find out why it should suddenly not work. The above is only test code.
I have also used:
Code:
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer(strComputer, "root\cimv2")
objService.Security_.ImpersonationLevel = 3
Now the kicker... I use the above code successfully with a script that has been running for over 10 months now on our server that checks disk space, but when I run the above sample script on the server (instead of my workstation), it still does not work!!
I must be doing something wrong! Can anyone help?
Will
![[morning] [morning] [morning]](/data/assets/smilies/morning.gif)
PS, here is the actual code I want to work, that worked a few months ago:
Code:
Dim oDomain, oComp, strComputer
Set oDomain = GetObject("WinNT://myDomain")
oDomain.Filter = Array("computer")
For Each oComp In oDomain
strComputer = oComp.Name
'MsgBox strComputer, vbOK
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("c:\softlist\software-" & _
strComputer & ".tsv", True)
Set oWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2")
'Set objLocator = CreateObject("WbemScripting.SWbemLocator")
'Set objService = objLocator.ConnectServer(strComputer, "root\cimv2")
'objService.Security_.ImpersonationLevel = 3
Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product")
objTextFile.WriteLine "Caption" & vbtab & _
"Description" & vbtab & "Identifying Number" & vbtab & _
"Install Date" & vbtab & "Install Location" & vbtab & _
"Install State" & vbtab & "Name" & vbtab & _
"Package Cache" & vbtab & "SKU Number" & vbtab & _
"Vendor" & vbtab & "Version"
For Each objSoftware in colSoftware
objTextFile.WriteLine objSoftware.Caption & vbtab & _
objSoftware.Description & vbtab & _
objSoftware.IdentifyingNumber & vbtab & _
objSoftware.InstallDate2 & vbtab & _
objSoftware.InstallLocation & vbtab & _
objSoftware.InstallState & vbtab & _
objSoftware.Name & vbtab & _
objSoftware.PackageCache & vbtab & _
objSoftware.SKUNumber & vbtab & _
objSoftware.Vendor & vbtab & _
objSoftware.Version
Next
objTextFile.Close
Set objTextFile = Nothing
Set objWMIService = Nothing
Set objFSO = Nothing
Next