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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Error 800A0046

Status
Not open for further replies.

WalleyeGuy

Technical User
Oct 18, 2007
44
US
I have a snippet of code that keeps spewing off an access denied error

I created a test.vbs file (below) to try and narrow down the problem and am getting nowhere.

It's the "For Each objItem in colItems" line below that spouts the error; however, I think it's due to the Set objWMI that actually causes it.


strComputer = "."
wmiNS = "\root\cimv2"

Set objWMI = GetObject("winmgmts:\\" & strComputer & wmiNS)
'Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & wmiNS)
Win2K = False
WinXP = False
Vista = False
WinServ2K = False
WinServ2K3 = False
WorkStation = False
Server = False

Set colItems = objWMI.ExecQuery("Select * "&_
"from Win32_OperatingSystem")

For Each objItem in colItems
strWinVer = Left(objItem.Version,3)
Next

Select Case strWinVer
Case "5.0" strOS = "Windows 2000"
Win2K = True
Server = True
Case "5.1" strOS = "Windows XP"
WinXP = True
Workstation = True
Case "5.2" strOS = "Windows Server 2003"
WinServ2K3 = True
Server = True
Case "6.0" strOS = "Windows Vista"
Vista = True
Workstation = True
Case Else
strOS = "Unknown - Probably Win9x"
End Select
WScript.Echo strOS


The computer that I'm having this issue on, is a WinXP machine and it doesn't matter what credentials I use to run the script - I get the error no matter what. The code above is from a logon script; however, even running the simple code above, same error. I also get the error no matter which of the objWMI sets I use.

Any help would be appreciated
 
OK, so I tested the code on my own system. I have user level access rights (when not in admin mode) and the code worked like a charm - no error.

So...

I looked up the error code by going to Google and typing in the error number. The error number seems to be related to permissions.

Maybe try checking permissions under which the script is being ran - just a suggestion. Another option might be to run the script with admin rights just to see if it works.

V/r,

SPC Key
United States Army
 
I have a few machines that just don't like WMI calls. Try running the following commands on the "bad" machine and see if it helps:

winmgmt /clearadap
winmgmt /resyncperf

Often, I just have to "On Error Resume Next" around the For...Next structure to detect the error and use an alternate method. Since you are looking for OS info, you can read it from the registry or infer it from file versions, FS structure, etc...


PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
I did an "On Error" for that computer specifically
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top