Process owner over LAN - SOLVED

Just starting out? Need help? Post your questions and find answers here.
TeddyLM
Enthusiast
Enthusiast
Posts: 133
Joined: Wed Apr 30, 2003 2:04 pm
Location: Germany (French expat)

Process owner over LAN - SOLVED

Post by TeddyLM »

Hello,

i'm currently using this code to get the list of processes on remote computers. I get name and pid of these processes but i'd like to know who's owning them. Any idea how to get that information ? Thanks.

Code: Select all

#COINIT_MULTITHREAD=0 
#RPC_C_AUTHN_LEVEL_CONNECT=2 
#RPC_C_IMP_LEVEL_IDENTIFY=2 
#EOAC_NONE=0 
#RPC_C_AUTHN_WINNT=10 
#RPC_C_AUTHZ_NONE=0 
#RPC_C_AUTHN_LEVEL_CALL=3 
#RPC_C_IMP_LEVEL_IMPERSONATE=3 
#CLSCTX_INPROC_SERVER=1 
#wbemFlagReturnImmediately=16 
#wbemFlagForwardOnly=32 
#IFlags = #wbemFlagReturnImmediately + #wbemFlagForwardOnly 
#WBEM_INFINITE=$FFFFFFFF 
Global WMITask$
Global WMINbrProp.l
Global Dim WMIPropertie$(1)
;********************************
Procedure.l ansi2bstr(ansi.s) 
  size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0) 
  Dim unicode.w(size) 
  MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), size) 
  ProcedureReturn SysAllocString_(@unicode()) 
EndProcedure 
;********************************
Procedure bstr2string (bstr) 
  Shared result.s 
  result.s = "" 
  pos=bstr 
  While PeekW (pos) 
    result=result+Chr(PeekW(pos)) 
    pos=pos+2 
  Wend 
  ProcedureReturn @result 
EndProcedure
;*********************************************************
Procedure.s CallWMI(Hostname$)  
    CoInitializeEx_(0,#COINIT_MULTITHREAD) 
    hres=CoInitializeSecurity_(0, -1,0,0,#RPC_C_AUTHN_LEVEL_CONNECT,#RPC_C_IMP_LEVEL_IDENTIFY,0,#EOAC_NONE,0) 
    If hres = 0 
        hres=CoCreateInstance_(?CLSID_WbemLocator,0,#CLSCTX_INPROC_SERVER,?IID_IWbemLocator,@loc.IWbemLocator) 
        If hres = 0 
            hres=loc\ConnectServer(ansi2bstr("\\" + Hostname$ + "\root\cimv2"),0,0,0,0,0,0,@svc.IWbemServices) 
            If hres = 0 
                hres=svc\queryinterface(?IID_IUnknown,@pUnk.IUnknown)
                hres=CoSetProxyBlanket_(svc,#RPC_C_AUTHN_WINNT,#RPC_C_AUTHZ_NONE,0,#RPC_C_AUTHN_LEVEL_CALL,#RPC_C_IMP_LEVEL_IMPERSONATE,0,#EOAC_NONE) 
                If hres = 0 
                    hres=CoSetProxyBlanket_(pUnk,#RPC_C_AUTHN_WINNT,#RPC_C_AUTHZ_NONE,0,#RPC_C_AUTHN_LEVEL_CALL,#RPC_C_IMP_LEVEL_IMPERSONATE,0,#EOAC_NONE) 
                    If hres = 0 
                        pUnk\release()                      
                        hres=svc\ExecQuery(ansi2bstr("WQL"),ansi2bstr(WMITask$), #IFlags,0,@pEnumerator.IEnumWbemClassObject) 
                        If hres = 0 
                            hres=pEnumerator\reset() 
                            Repeat 
                            hres=pEnumerator\Next(#WBEM_INFINITE, 1, @pclsObj.IWbemClassObject, @uReturn)
                            For i=0 To WMINbrProp-1
                              mem=AllocateMemory(1000) 
                                  hres=pclsObj\get(ansi2bstr(WMIPropertie$(i)), 0, mem, 0, 0) 
                                  type=PeekW(mem) 
                                  Select type 
                                    Case 11 
                                      v=PeekL(mem+8) 
                                      If v=0 
                                        val.s="FALSE" 
                                      Else 
                                        val.s="TRUE" 
                                      EndIf 
                                    Case 8 
                                      val.s=PeekS(bstr2string(PeekL(mem+8))) 
                                    Case 3 
                                      val.s=Str(PeekL(mem+8)) 
                                    Default 
                                      val.s="" 
                                  EndSelect 
                              If uReturn <> 0: wmi$=wmi$+val+"~": EndIf 
                              FreeMemory(mem) 
                            Next 
                            Until uReturn = 0 
                            pEnumerator\release() 
                            pclsObj\release()
                        Else
                            wmi$ = "ERROR - unable To call IWbemServices::ExecQuery" 
                        EndIf
                    Else
                        wmi$ = "ERROR - unable to call CoSetProxyBlanket" 
                    EndIf
                Else
                    wmi$ = "ERROR - unable to call CoSetProxyBlanket" 
                EndIf
                svc\release()
            Else
                wmi$ = "ERROR - unable to call IWbemLocator::ConnectServer"
            EndIf
            loc\release()
        Else
            wmi$ = "ERROR - unable to call CoCreateInstance"
        EndIf
    Else
        wmi$ = "ERROR - unable to call CoInitializeSecurity"
    EndIf
    CoUninitialize_()
    ProcedureReturn wmi$
    DataSection 
        CLSID_IEnumWbemClassObject: Data.l $1B1CAD8C : Data.w $2DAB, $11D2 : Data.b $B6, $04, $00, $10, $4B, $70, $3E, $FD 
        IID_IEnumWbemClassObject:   Data.l $7C857801 : Data.w $7381, $11CF : Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24 
        CLSID_WbemLocator:          Data.l $4590F811 : Data.w $1D3A, $11D0 : Data.b $89, $1F, $00, $AA, $00, $4B, $2E, $24 
        IID_IWbemLocator:           Data.l $DC12A687 : Data.w $737F, $11CF : Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24 
        IID_IUnknown:               Data.l $00000000 : Data.w $0000, $0000 : Data.b $C0, $00, $00, $00, $00, $00, $00, $46 
    EndDataSection
EndProcedure
;*********************************************************
Host$ = "ThisComputer"            ;<---- the computer you want to query 
WMITask$ = "SELECT * FROM Win32_Process"
WMINbrProp.l = 2
Dim WMIPropertie$(WMINbrProp-1)
WMIPropertie$(0) = "Name"
WMIPropertie$(1) = "ProcessId"
WMIText$ = CallWMI(Host$)

If Left(WMIText$,5) = "ERROR"
    Debug WMIText$
Else
    NbrLines = CountString(WMIText$, "~")
    For counter = 1 To NbrLines Step 2 
        PName$ = StringField(WMIText$, counter, "~")
        PID$ = StringField(WMIText$, counter+1, "~")    
        Debug "Process = " + PName$ + "  (PID=" + PID$ + ")"        
    Next 
EndIf    
End 
Last edited by TeddyLM on Tue Jul 16, 2013 3:41 pm, edited 1 time in total.
TeddyLM
Enthusiast
Enthusiast
Posts: 133
Joined: Wed Apr 30, 2003 2:04 pm
Location: Germany (French expat)

Post by TeddyLM »

I'd like to do something like this, but i have no idea how to call the GetOwner method of the Win32_process:

Code: Select all

Function IsProcessRunning(strServer, strProcess)    
	Dim strNameOfUser As String 'changed it to string to display text    
	Dim Process, strObject    
	IsProcessRunning = False    
	strObject = "winmgmts://" & strServer    
	strNameOfUser = strServer    
	For Each Process In GetObject(strObject).InstancesOf("win32_process")        
		If UCase(Process.Name) = UCase(strProcess) Then            
			Call Process.GetOwner (strNameOfUser) 'called function            
			MsgBox strNameOfUser            
			IsProcessRunning = True            
			Exit Function        
		End If    
	Next
End Function
TeddyLM
Enthusiast
Enthusiast
Posts: 133
Joined: Wed Apr 30, 2003 2:04 pm
Location: Germany (French expat)

Re: Process owner over LAN - SOLVED

Post by TeddyLM »

Hi there,

after years i needed this again and eventually found how to call the method:

Code: Select all

#WBEM_INFINITE = $FFFFFFFF  
#COINIT_MULTITHREADED               = 0
#RPC_C_AUTHN_LEVEL_CONNECT          = 2     ;Authenticates the credentials of the client only when the client establishes a relationship with the server. 
#RPC_C_AUTHN_LEVEL_CALL             = 3     ;Authenticates only at the beginning of each remote procedure call when the server receives the request.
#EOAC_NONE                          = 0     ;No Authentication capability flags are set
#RPC_C_AUTHN_WINNT                  = 10    ;Use the Microsoft NT LAN Manager (NTLM) SSP.
#RPC_C_AUTHZ_NONE                   = 0     ;The server performs no authorization. Currently, RPC_C_AUTHN_WINNT, RPC_C_AUTHN_GSS_SCHANNEL, And RPC_C_AUTHN_GSS_KERBEROS all use only RPC_C_AUTHZ_NONE.
#RPC_C_IMP_LEVEL_IMPERSONATE        = 3     ;The server process can impersonate the client's security context while acting on behalf of the client. When impersonating at this level, the impersonation token can only be passed across one machine boundary (can be used to access local resources such as files).
#wbemFlagReturnImmediately          = 16    ;Causes the call to return immediately.
#wbemFlagForwardOnly                = 32    ;Causes a forward-only enumerator to be returned. Forward-only enumerators are generally much faster and use less memory than conventional enumerators, but they do not allow calls to SWbemObject.Clone_.
#CLSCTX_INPROC_SERVER               = $1

CompilerIf #PB_Compiler_OS = #PB_Compiler_Unicode
    Macro ptr(String) : @String : EndMacro
CompilerElse
    Macro ptr(String) : ansi2bstr(String) : EndMacro
CompilerEndIf

;=======================================
Procedure.i ansi2bstr(String$)
	size.i = MultiByteToWideChar_(#CP_ACP, 0, String$, Len(String$), 0, 0)
	If Size
    Dim unicode.w(size)
    MultiByteToWideChar_(#CP_ACP, 0, String$, Len(String$), unicode(), size)   ;#CP_ACP
    For Counter.i = 0 To size
        tmp.s + Hex(unicode(Counter), #PB_Unicode)
    Next
    EndIf
    ProcedureReturn SysAllocString_(@unicode())
EndProcedure
;=======================================
Procedure.i bstr2string(bstr.i)
    Shared result.s
    result = PeekS(bstr, -1, #PB_Unicode)
    ProcedureReturn @result
EndProcedure 
;=======================================
Procedure.s WMI_GetProcessOwner(Servername$, Processname$)
    Result$ = ""
    Select Servername$
        Case "" : Namespace$ = "\\.\root\CIMV2"
        Default : Namespace$ = "\\" + RemoveString(Servername$, "\") + "\root\CIMV2" 
    EndSelect        
    ;
    If CoInitializeEx_(0, #COINIT_MULTITHREADED) = 0         
        If CoInitializeSecurity_(0, -1, 0, 0, #RPC_C_AUTHN_LEVEL_CONNECT, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE, 0) = 0             
            If CoCreateInstance_(?CLSID_WbemLocator, 0, #CLSCTX_INPROC_SERVER, ?IID_IWbemLocator, @pLocator.IWbemLocator) = 0 
                If pLocator\ConnectServer(ptr(Namespace$), 0, 0, 0, 0, 0, 0, @pService.IWbemServices) = 0
                    If CoSetProxyBlanket_(pService, #RPC_C_AUTHN_WINNT, #RPC_C_AUTHZ_NONE, 0, #RPC_C_AUTHN_LEVEL_CALL, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE) = 0 
                        pService\queryinterface(?IID_IUnknown,@pUnknown.IUnknown)  
                        If CoSetProxyBlanket_(pUnknown, #RPC_C_AUTHN_WINNT, #RPC_C_AUTHZ_NONE, 0, #RPC_C_AUTHN_LEVEL_CALL, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE) = 0 
                            If pService\ExecQuery(ptr("WQL"), ptr("SELECT * FROM Win32_Process"), #wbemFlagReturnImmediately|#wbemFlagForwardOnly, 0, @pEnumerator.IEnumWbemClassObject) = 0
                                pEnumerator\reset()  
                                NbrReturned.i = 1
                                While NbrReturned  
                                    pEnumerator\Next(#WBEM_INFINITE, 1, @pclsObj.IWbemClassObject, @NbrReturned) 
                                    ;Get Processname
                                    If pclsObj\Get(ptr("Name"), 0, @vtReturn.VARIANT, 0, 0) = 0          ;Debug PeekS(bstr2string(vtReturn\bstrVal))
                                        Found.i = #False
                                        If LCase(PeekS(bstr2string(vtReturn\bstrVal))) = Processname$   
                                            Found = #True
                                            ;Get Processpath
                                            If pclsObj\Get(ptr("__PATH"), 0, @vtPath.VARIANT, 0, 0) = 0  ;Debug PeekS(bstr2string(vtPath\bstrVal))
                                                ;Get Processowner
                                                If pService\ExecMethod(vtPath\bstrVal, ptr("GetOwner"), 0, 0, 0, @pResult.IWbemClassObject, 0) = 0
                                                    If pResult\Get(ptr("User"), 0, @vtUser.VARIANT, 0, 0) = 0
                                                        Result$ = PeekS(bstr2string(vtUser\bstrVal))
                                                        VariantClear_(vtUser)
                                                    EndIf
                                                    pResult\release()   
                                                EndIf   
                                                VariantClear_(vtPath)        
                                            EndIf  
                                            Break
                                        EndIf     
                                        VariantClear_(vtReturn)
                                        If Found = #False : Result$ = "Error - Unable to find the process" : EndIf
                                    EndIf
                                Wend 
                                pclsObj\release()    
                            Else
                                Result$ = "Error - Unable to retrieve the objects"
                            EndIf
                            pUnknown\release()  
                        Else
                            Result$ = "Error - Unable to set the IUnknown security"                            
                        EndIf
                    Else
                        Result$ = "Error - Unable to set the proxy security"
                    EndIf    
                    pService\release() 
                Else
                    Result$ = "Error - Unable to connect to CIMV2"
                EndIf  
                pLocator\release()
            Else
                Result$ = "Error - Unable to create a WbemLocator"
            EndIf
        Else
            Result$ = "Error - Unable to set the security values for the process"
        EndIf
        CoUninitialize_()
    Else
        Result$ = "Error - Unable to launch COM"
    EndIf    
    ProcedureReturn Result$
    DataSection  
        CLSID_IEnumWbemClassObject:     Data.l $1B1CAD8C : Data.w $2DAB, $11D2 : Data.b $B6, $04, $00, $10, $4B, $70, $3E, $FD  
        IID_IEnumWbemClassObject:       Data.l $7C857801 : Data.w $7381, $11CF : Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24  
        CLSID_WbemLocator:              Data.l $4590F811 : Data.w $1D3A, $11D0 : Data.b $89, $1F, $00, $AA, $00, $4B, $2E, $24  
        IID_IWbemLocator:               Data.l $DC12A687 : Data.w $737F, $11CF : Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24  
        IID_IUnknown:                   Data.l $00000000 : Data.w $0000, $0000 : Data.b $C0, $00, $00, $00, $00, $00, $00, $46  
        IID_IWbemRefresher:             Data.l $49353C99 : Data.w $516B, $11D1 : Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20  
        CLSID_WbemRefresher:            Data.l $C71566F2 : Data.w $561E, $11D1 : Data.b $AD, $87, $00, $C0, $4F, $D8, $FD, $FF  
        IID_IWbemConfigureRefresher:    Data.l $49353C92 : Data.w $516B, $11D1 : Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20  
        IID_IWbemObjectAccess:          Data.l $49353C9A : Data.w $516B, $11D1 : Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20  
    EndDataSection    
EndProcedure
;=======================================
;=======================================
;=======================================
Servername$ = ""      
Processname$ = "explorer.exe"
Debug WMI_GetProcessOwner(Servername$, Processname$)
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: Process owner over LAN - SOLVED

Post by em_uk »

Here's how I do using WMI and Commate.

This is from a remote admin tool I've written.

Code: Select all

Procedure GetProcess(*sw)
  
  strComputer.s = machine.s
  Define.COMateObject objWMIService, objProcess
  colProcessList.COMateEnumObject
  objWMIService = COMate_GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2")
  
  If objWMIService
    colProcessList = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_Process')")
    If colProcessList
      objProcess = colProcessList\GetNextObject()
      While objProcess
        name$=objProcess\GetStringProperty("Name") 
        handle=objProcess\GetIntegerProperty("Handle")
        path$=objProcess\GetStringProperty("ExecutablePath")
        time.l=objProcess\GetIntegerProperty("KernelModeTime")
        cmdline$=objProcess\GetStringProperty("CommandLine")
        t$=ConvertToMin(time)
        Debug Val(time$)
        
        username$=objProcess\GetStringProperty("Username, Domain")
        Debug "Process name = " + objProcess\GetStringProperty("Name")
        If objProcess\GetIntegerProperty("GetOwner(" + Str(@userName) + " byref)") = #S_OK
          username$=PeekS(userName, -1, #PB_Unicode)
          SysFreeString_(userName)
        Else
          Debug "Cannot locate user's name."
        EndIf
        ;Debug "==========================================================="
        ;      objProcess\Release()
        objProcess = colProcessList\GetNextObject()
        If IsWindow(#w_process)
          AddGadgetItem(#wListIcon_0,-1,Str(handle)+Chr(10)+name$+Chr(10)+username$+Chr(10)+t$+Chr(10)+path$+Chr(10)+cmdline$)
        Else
          Break 1
        EndIf
      Wend
      colProcessList\Release()
    EndIf
    objWMIService\Release()
  Else
    MessageRequester("RIMmer", "Error detecting processes!")
  EndIf
EndProcedure
----

R Tape loading error, 0:1
User avatar
OldSkoolGamer
Enthusiast
Enthusiast
Posts: 150
Joined: Mon Dec 15, 2008 11:15 pm
Location: Nashville, TN
Contact:

Re: Process owner over LAN - SOLVED

Post by OldSkoolGamer »

Necro post I know, but I was using em_uk's code and with PB6.10 it's no longer working. I get an error:
PeekS() :Specified address is null.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Process owner over LAN - SOLVED

Post by RASHAD »

I am not sure
But as a common issue with PB v 6.10 change long to integer
As next it may work :)
Or
Stay with PB v 6.04 :D

Code: Select all

	time.l=objProcess\GetIntegerProperty("KernelModeTime")
	;To
	time.i=objProcess\GetIntegerProperty("KernelModeTime")
Egypt my love
User avatar
OldSkoolGamer
Enthusiast
Enthusiast
Posts: 150
Joined: Mon Dec 15, 2008 11:15 pm
Location: Nashville, TN
Contact:

Re: Process owner over LAN - SOLVED

Post by OldSkoolGamer »

Here's the line that throws the error:
If objProcess\GetIntegerProperty("GetOwner(" + Str(@userName) + " byref)") = #S_OK
procowner$=PeekS(userName, -1, #PB_Unicode)
UpdateDots()
SysFreeString_(userName)
Else
procowner$="<None>"
UpdateDots()
EndIf

It specifically calls the error on the PeekS line saying:
PeekS(): Specified address is null

EDIT:
For laughs??? I changed every .l to .i in my code and COMAte Plus, no change, still getting the same error, guess I'll roll back to 6.04 for now...
Axolotl
Addict
Addict
Posts: 802
Joined: Wed Dec 31, 2008 3:36 pm

Re: Process owner over LAN - SOLVED

Post by Axolotl »

No value is assigned to userName in the shown code. From my understanding the value is Zero.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Process owner over LAN - SOLVED

Post by mk-soft »

I think the Username must be defined as Variant ...

Alternative to COMate with ActiveScript.
Returns the domain and username

Update

Code: Select all

;-TOP

; Comment   : Modul ActiveScript Example 20
; Version   : v2.10.1

; Link to ActiveScript  : https://www.purebasic.fr/english/viewtopic.php?f=12&t=71399
; Link to SmartTags     : https://www.purebasic.fr/english/viewtopic.php?f=12&t=71399#p527089
; Link to VariantHelper : https://www.purebasic.fr/english/viewtopic.php?f=12&t=71399#p527090

; ***************************************************************************************

XIncludeFile "Modul_ActiveScript.pb"
XIncludeFile "Modul_SmartTags.pb"
XIncludeFile "VariantHelper.pb"

UseModule ActiveScript
UseModule ActiveSmartTags

; -------------------------------------------------------------------------------------

Procedure.s GetDataSectionText(*Addr.Character)
  Protected result.s, temp.s
  While *Addr\c <> #ETX
    temp = PeekS(*Addr)
    *Addr + StringByteLength(temp) + SizeOf(Character)
    result + temp + #LF$
  Wend
  ProcedureReturn result
EndProcedure

; -------------------------------------------------------------------------------------

Global script.s, run_script.s

Global Servername.s    
Global Processname.s

Global Username.s
Global Running

Runtime Servername
Runtime Processname
Runtime UserName
Runtime Running

*Control = NewActiveScript()
If *Control
  ; AddOn SmartTags hinzufügen
  AddNamedObject(*Control, "SmartTags", NewSmartTags())
  
  Debug "*** Parse ScriptText ***"
  
  script = GetDataSectionText(?vbs)
  run_script = GetDataSectionText(?vbsrun)
  
  r1 = ParseScriptText(*Control, script)
  If r1 = #S_OK
    Debug "*** Load Code Ready. ***"
  Else
    Debug "Error"
    End
  EndIf
  
  Servername.s = ""      
  Processname.s = "explorer.exe"
  Running = #False
  r1 = ParseScriptText(*Control, run_script)
  If r1 = #S_OK
    Debug "*** Run Code Ready. ***"
  Else
    Debug "Error"
  EndIf
  If Running
    Debug Processname + " running as domain/username = " + UserName
  Else
    Debug Processname + " not running"
  EndIf
  Debug "********"
  
  Servername.s = ""      
  Processname.s = "purebasic.exe"
  Running = #False
  r1 = ParseScriptText(*Control, run_script)
  If r1 = #S_OK
    Debug "*** Run Code Ready. ***"
  Else
    Debug "Error"
  EndIf
  If Running
    Debug Processname + " running as domain/username = " + UserName
  Else
    Debug Processname + " not running"
  EndIf
  Debug "********"
  
  Debug "*** Free ActiveScript ***"
  FreeActiveScript(*Control)
  
  Debug "************************************************************"
EndIf

; -------------------------------------------------------------------------------------

DataSection
  vbs:
  Data.s ~"Function IsProcessRunning(strServer, strProcess)"
  Data.s ~"  Dim strNameOfUser, strDomain 'changed it to string to display text"
  Data.s ~"  Dim Process, strObject, r1"
  Data.s ~"  IsProcessRunning = False"
  Data.s ~"  strObject = \"winmgmts://\" & strServer"
  Data.s ~"  strNameOfUser = strServer"
  Data.s ~"  For Each Process In GetObject(strObject).InstancesOf(\"win32_process\")"
  Data.s ~"    If UCase(Process.Name) = UCase(strProcess) Then"
  Data.s ~"      'Process.GetOwner strNameOfUser, strDomain"
  Data.s ~"      'MsgBox \"User: \" & strNameOfUser & vbNewLine & \"Domain: \" & strDomain"
  Data.s ~"      IsProcessRunning = True"
  Data.s ~"      Exit Function"
  Data.s ~"    End If"
  Data.s ~"  Next"
  Data.s ~"End Function"
  Data.s ~""
  Data.s ~"Function ProcessRunningAsUser(strServer, strProcess)"
  Data.s ~"  Dim strNameOfUser, strDomain 'changed it to string to display text"
  Data.s ~"  Dim Process, strObject, r1"
  Data.s ~"  strObject = \"winmgmts://\" & strServer"
  Data.s ~"  strNameOfUser = strServer"
  Data.s ~"  For Each Process In GetObject(strObject).InstancesOf(\"win32_process\")"
  Data.s ~"    'Runtime.Trace Process.Name"
  Data.s ~"    If UCase(Process.Name) = UCase(strProcess) Then"
  Data.s ~"      Process.GetOwner strNameOfUser, strDomain"
  Data.s ~"      'MsgBox \"User: \" & strNameOfUser & vbNewLine & \"Domain: \" & strDomain"
  Data.s ~"      ProcessRunningAsUser = strDomain & \"\\\" & strNameOfUser"
  Data.s ~"      Exit Function"
  Data.s ~"    End If"
  Data.s ~"  Next"
  Data.s ~"  ProcessRunningAsUser = \"\""
  Data.s ~"End Function"
  Data.s ~""
  Data.s #ETX$
  vbsrun:
  Data.s ~"Dim strServer, strProcess, Run"
  Data.s ~""
  Data.s ~"strServer = Runtime.String(\"Servername\")"
  Data.s ~"strProcess = Runtime.String(\"Processname\")"
  Data.s ~""
  Data.s ~""
  Data.s ~"Run = IsProcessRunning(strServer, strProcess)"
  Data.s ~"If Run Then"
  Data.s ~"  Runtime.Integer(\"Running\") = Run"
  Data.s ~"  Runtime.String(\"Username\") = ProcessRunningAsUser(strServer, strProcess)"
  Data.s ~"End If"
  Data.s ~""
  Data.s #ETX$
EndDataSection
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply