WalleyeGuy
Technical User
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
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