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

Trying to List remote services with WBEMlocator

Status
Not open for further replies.

Ambientguitar

Programmer
Apr 23, 2006
31
GB
I need help with this its driving me nuts when I run this as a vbscript on the same Pc it pulls out the required data but when I try to connect using Foxpro (version 8)It just keeps throwing errors up, the latest being OLE error code 0 with SWBEMlocator:Access is denied, I have tried several ways to get this to work with no joy.
Code:
    ObjWbemlocator=CREATEOBJECT("WbemScripting.SWbemlocator")objWMIService=objWbemlocator.Connectserver(lcip,lcnamespace,lcUserName,lcPassword)
    objService.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
    objWMIService.Security_.authenticationLevel=WbemAuthenticationLevelPktPrivacy
      
    colServices = objWMIService.ExecQuery("Select * from Win32_Service")

If colServices.Count > 0 Then
    For Each objService in colServices
		lorow= ThisForm.Pf1.Pg4.listservices.listitems.add(,allt(objService.Name +"."),allt(objService.State + "."),,)
        loRow.subitems(1)= objService.Name  
        loRow.subitems(2)=objService.State + "." 
        
	Next
Else
    ? objService.Name+"is not installed on PC."
EndIf
 
Give this a whirl:

objWbemlocator = CreateObject("WbemScripting.SWbemLocator")
objWMIService = ObjWbemlocator.ConnectServer(lcip, lcNameSpace, lcUserName, lcPassword)
objWMIService.Security_.ImpersonationLevel = 3 && wbemImpersonationLevelImpersonate
objWMIService.Security_.authenticationLevel = 6 && wbemAuthenticationLevelPktPrivacy

colServices = objWMIService.ExecQuery("Select * from Win32_Service")

If colServices.Count > 0 Then
For Each objService in colServices
lorow= ThisForm.Pf1.Pg4.listservices.listitems.add(,allt(objService.Name +"."),allt(objService.State + "."),,)
loRow.subitems(1)= objService.Name
loRow.subitems(2)=objService.State + "."

Next
Else
? objService.Name+"is not installed on PC."
EndIf




Here is a link for MS info on this:

Regards,

Rob
 
When I tested it I used:

lcIp = (My database servers ip)
lcUserName = (My domain admin username)
lcPassword = (My domains admin password)
lcNameSpace = "root\cimv2"

Regards,

Rob
 
Hi Rob thanks for the input but I had already define the below values at start of method. Tried your code still no joy.
Code:
#DEFINE wbemImpersonationLevelImpersonate 3

#DEFINE wbemAuthenticationLevelPktPrivacy 6

Its falling over on the line below:
Code:
objWMIService = ObjWbemlocator.ConnectServer(lcip, lcNameSpace, lcUserName, lcPassword)

I am using the following values, what I can't understand is that this works if I use it in a vbscript?

lcip=remote ipaddress
lcUserName = (remotes admin username)
lcPassword = (remotes admin password)
lcNameSpace = "root\cimv2"


 
When I execute the code with a regular user even in computers admin it fails. But using DOMAIN admin it works fine.

Regards,

Rob
 
Once again Rob thanks! Perhaps I should explain what I'm trying to do . I am writing a small tool for our support guys to use on customers remote P.C.'s . They access remote p.c.'s through customer headoffice server which allows access to thier WAN. I can get this to work on VBscript but not when using Foxpro ? Anyway looks like I'm beat perhaps this is impossible as I don't have domain\admin account details and I'm unlikely to get them.
 
Sorry Rob just a wee update, this works fine in Win 2000 Pro machine but falling over on my laptop which is XP Professional. Any thoughts anyone.
 
check to see if you are logging in as domain user on one and as workstation user on other.

Regards,

Rob
 
Cheers Rob, not this I'm afraid. I have turned off my firewall on the laptop and the windows firewall also so not that, I also got a collegue to try my code on his XP pro laptop he connected no problem so not Xp problem. Anyway incase you are interested came across this site where the guy builds a nice little class to do this.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top