Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permission Denied Script Error

Status
Not open for further replies.
Feb 4, 2002
792
GB
Hi All,

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
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]

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

 
Hello WillShakespeare,

What is your os's?

regards - tsuji
 
Hi tsuji,

Finally got to the bottom of this! We are on XP Pro, and all our users on XP Pro experience serious slowness (up to 10 minutes for a folder with only one item to refresh!) when going further down a network folders hierarchy, through My Network Places. Only through My Network Places, mind you, but pre-XP (many of us still on Win2K) don't have this problem. What's odd is if you create a shortcut on the desktop to the same network folder, avoiding the link in My Network Places, and then access the network area through the shortcut, it is quick as lightning!! But deadly slow through My Network Places... anyway, to cut long story short, I looked long and hard for a solution, and found many registry hacks, and Service Disabling strategies, which did imporve matters, but did not cure by a long shot. As matters were improved, i left my changes for the time.

Anyway, one of the Services I disabled was "Cryptographic Services". Another was "Distributed Transaction Links".
I have since re-enabled and started these and now my scripts work just like they used to! Oddly, though, I was VNC-ing to another computer, and trying to run the script from that computer, and it also failed. Since making this change on my computer, it also works on the others! This means that those remote admin windows also use my local services for network communication, even when called on the other machine... interesting...

Still, I solved this, so if anyone else having trouble...

Will
[morning]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top