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!

Check if process its running in a remote computer.....

Status
Not open for further replies.

Jetttt

MIS
Nov 3, 2003
32
MX
Exist a way to detect if a remote computer it executing a process using Vbasic???. I was trying of to use the WMI service, but i was reading the microsoft documentation and this service dont work in windows xp home edition.

Any ideas, will be helpfull...


Regards

JETTTT
 
>>this service dont work in windows xp home edition

where did you get this info from? Far as I know it works fine with XP Home. You can download and install a package for it to work with W98 so I don't know of any reason it wouldn't work with XP Home.

Anyway, here is some code:

Code:
strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecQuery( _
    "select * from win32_process" )
For Each objProcess in colProcesses
   
    If objProcess.GetOwner ( User, Domain ) = 0 Then
          Wscript.Echo "Process " & _
              objProcess.Caption & _
              " belongs to " & Domain & _
              "\" & User
    Else
          Wscript.Echo "Problem " & Rtn & _
              " getting the owner for process " _
              & objProcess.Caption
    End If
Next

This code was pulled directly from


If you have a specific question or problem, post back here and we'll be glad to help.
 
Hi bjd4jc, thanks for answer me. In the online documentation of Microsoft :
Said you cant connect to a computer that is running windows XP Home edition.

I check my code in a computer with Home and this work fine locally. But when i try of to access remotelly a error message appear.

this is the code that i use :

Function IsProcessRunning( strServer, strProcess )
Dim Process, strObject, booValueReturned

booValueReturned= False
strObject = "winmgmts://" & strServer
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If strComp(UCase( Process.name ),UCase( strProcess )) = 0 Then
booValueReturned = True
'Exit Function
End If
Next
IsProcessRunning = booValueReturned
End Function
 
Well I didn't know that about XP Home. Here is another option using the OpenSCManager API. It is just a starter piece of code. I just want to see if you can connect to an XP Home edition computer with this code. I don't have any computers with Home edition to test this otherwise I would. If lRet is anything but 0 then it works and then we can continue on with the next step...


Code:
Option Explicit
Private Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
Private Declare Function CloseServiceHandle Lib "advapi32.dll" (ByVal hSCObject As Long) As Long

Private Const SC_MANAGER_ENUMERATE_SERVICE = &H4
Private Sub Form_Load()
    Dim strMachine As String
    Dim strDatabase As String
    Dim lRet As Long
    
    'Try with an empty string first
    'strMachine = "COMPNAME" ' leave this empty to connect to the local computer
    
    lRet = OpenSCManager(strMachine, strDatabase, SC_MANAGER_ENUMERATE_SERVICE)
    
    If lRet <> 0 Then
        'you connected so close the handle
        CloseServiceHandle lRet
    Else
        'call did not work
        MsgBox "Call failed"
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top