Getobject access denied WMI in vbscript
Crabe77
-
Anonymous user -
Anonymous user -
Bonjour,
I have been looking for a while for a way to get my script to work; it's a script that scans the computers on a network and pings as well as retrieves the screen resolution. I am receiving an access denied error on the getobject.
I tried to do the impersonation but it doesn't work, and being a novice in scripting, can you provide me with some information? Thank you
while Not f.AtEndOfStream
sPoste= f.readline
wscript.echo "reading the computer: " & sPoste
'err.clear
set objWMIService = GetObject("winmgmts:\\"& sPoste &"\root\cimv2")
set objWMIService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//"& sPoste &"/root/cimv2")
if err = 0 then
set objPing = objWMIService.ExecQuery("select * from Win32_PingStatus where address = '" & sPoste & "'")
For Each objStatus In objPing
r.Write "ping ok: " & sPoste & vbcrlf
set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("Select * From Win32_DesktopMonitor where address = '" & sPoste & "'")
'set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
for each objItem in colItems
if objItem.ScreenWidth <> null then
wscript.echo "the value is not null"
'On Error resume next
CurrentRecordSet.open "select Nom_Pos from POSTES where Nom_Pos = '" & sPoste & "' ;" ,oConn
if currentrecordset("Nom_Pos") = null then
wscript.echo "the computer name is: " & currentrecordset("Nom_Pos")
Valeur = currentrecordset("Nom_Pos")
CurrentRecordset.close
Configuration: Windows 7 / Safari 535.11
I have been looking for a while for a way to get my script to work; it's a script that scans the computers on a network and pings as well as retrieves the screen resolution. I am receiving an access denied error on the getobject.
I tried to do the impersonation but it doesn't work, and being a novice in scripting, can you provide me with some information? Thank you
while Not f.AtEndOfStream
sPoste= f.readline
wscript.echo "reading the computer: " & sPoste
'err.clear
set objWMIService = GetObject("winmgmts:\\"& sPoste &"\root\cimv2")
set objWMIService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//"& sPoste &"/root/cimv2")
if err = 0 then
set objPing = objWMIService.ExecQuery("select * from Win32_PingStatus where address = '" & sPoste & "'")
For Each objStatus In objPing
r.Write "ping ok: " & sPoste & vbcrlf
set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("Select * From Win32_DesktopMonitor where address = '" & sPoste & "'")
'set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
for each objItem in colItems
if objItem.ScreenWidth <> null then
wscript.echo "the value is not null"
'On Error resume next
CurrentRecordSet.open "select Nom_Pos from POSTES where Nom_Pos = '" & sPoste & "' ;" ,oConn
if currentrecordset("Nom_Pos") = null then
wscript.echo "the computer name is: " & currentrecordset("Nom_Pos")
Valeur = currentrecordset("Nom_Pos")
CurrentRecordset.close
Configuration: Windows 7 / Safari 535.11
7 answers
while Not f.AtEndOfStream
sPoste= f.readline
wscript.echo "reading the station :" & sPoste
'err.clear
'set objWMIService = GetObject("winmgmts:\\"& sPoste &"\root\cimv2")
set objWMIService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//"& sPoste &"/root/cimv2")
if err = 0 then
set objPing = objWMIService.ExecQuery("select * from Win32_PingStatus where address = '" & sPoste & "'")
For Each objStatus In objPing
r.Write "ping ok : " & sPoste & vbcrlf
set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("Select * From Win32_DesktopMonitor where address = '" & sPoste & "'")
'set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
for each objItem in colItems
if objItem.ScreenWidth <> null then
wscript.echo "the value is not null"
'On Error resume next
CurrentRecordSet.open "select Nom_Pos from POSTES where Nom_Pos = '" & sPoste & "' ;" ,oConn
if currentrecordset("Nom_Pos") = null then
wscript.echo "the name of the station is :" & currentrecordset("Nom_Pos")
Valeur = currentrecordset("Nom_Pos")
CurrentRecordset.close
sPoste= f.readline
wscript.echo "reading the station :" & sPoste
'err.clear
'set objWMIService = GetObject("winmgmts:\\"& sPoste &"\root\cimv2")
set objWMIService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//"& sPoste &"/root/cimv2")
if err = 0 then
set objPing = objWMIService.ExecQuery("select * from Win32_PingStatus where address = '" & sPoste & "'")
For Each objStatus In objPing
r.Write "ping ok : " & sPoste & vbcrlf
set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("Select * From Win32_DesktopMonitor where address = '" & sPoste & "'")
'set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
for each objItem in colItems
if objItem.ScreenWidth <> null then
wscript.echo "the value is not null"
'On Error resume next
CurrentRecordSet.open "select Nom_Pos from POSTES where Nom_Pos = '" & sPoste & "' ;" ,oConn
if currentrecordset("Nom_Pos") = null then
wscript.echo "the name of the station is :" & currentrecordset("Nom_Pos")
Valeur = currentrecordset("Nom_Pos")
CurrentRecordset.close
Hello,
At first glance:
set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("Select * From Win32_DesktopMonitor where address = '" & sPoste & "'")
should read as follows:
set colItems = objWMIService.GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("Select * From Win32_DesktopMonitor where address = '" & sPoste & "'")
here is an example of one of my scripts:
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='Service'")
Best regards
Lupin
At first glance:
set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("Select * From Win32_DesktopMonitor where address = '" & sPoste & "'")
should read as follows:
set colItems = objWMIService.GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("Select * From Win32_DesktopMonitor where address = '" & sPoste & "'")
here is an example of one of my scripts:
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='Service'")
Best regards
Lupin
I tried and I still have the error on
set objWMIService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//"& sPoste &"/root/cimv2")
Access denied
set objWMIService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//"& sPoste &"/root/cimv2")
Access denied
re :
Observe bien, ta syntaxe est différente :
La tienne :
set objWMIService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & sPoste & "/root/cimv2")
La mienne :
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & sPoste & "\root\cimv2")
tu peux aussi essayer de remplacer [ sPoste ] par [ . ] pour localhost
gère les espaces dans la syntaxe.
Cdt
Lupin
Observe bien, ta syntaxe est différente :
La tienne :
set objWMIService = GetObject("WinMgmts:{impersonationLevel=impersonate}!//" & sPoste & "/root/cimv2")
La mienne :
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & sPoste & "\root\cimv2")
tu peux aussi essayer de remplacer [ sPoste ] par [ . ] pour localhost
gère les espaces dans la syntaxe.
Cdt
Lupin
I wrote in my script, your piece of (Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}\\" & Computer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='Service'") ) replacing with the right data and still getting the same error...
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='Service'") ) replacing with the right data and still getting the same error...