Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How do I get the owner of process running>
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2016
Network:
Windows Server 2016
Database:
Visual FoxPro
Application:
Desktop
Virtual environment:
VMWare
Divers
Thread ID:
01638970
Message ID:
01639047
Vues:
84
Try this:
lcCurrentUser = getenv("USERNAME")
FOR EACH PROCESS IN oStuff
	lcOwner		= ''
	PROCESS.getOwner(@lcOwner)
	IF PROCESS.NAME = ltProcess and not empty(lcOwner) and lcOwner = lcCurrentUser
		i = i + 1
		IF pnPID <> PROCESS.ProcessId AND ltKill = .T.
			PROCESS.TERMINATE()
		ENDIF
	ENDIF
ENDFOR 
>Hi All,
>
>I need to get the owner of process that is running so that if they try and open another instance of the program it will not allow them to and kill that process.
>
>I can get the process and the current processID but my code will then kill all instances of the application effecting all users. I only want to prevent the user from opening a second instance.
>
>
>
>check Instance('myprog.exe')
>
>*----------------------------*
>FUNCTION CheckInstance()
>*----------------------------
>LPARAMETER ltProcess, ltKill
>
>oManager = GETOBJECT("winmgmts:")
>oStuff = oManager.InstancesOf("Win32_process")
>i = 0
>
>pnPID = GetProcessID()
>
>FOR EACH PROCESS IN oStuff
>   IF PROCESS.NAME = ltProcess
>      i = i + 1
>      IF pnPID <> PROCESS.ProcessId AND ltKill = .T.
>         PROCESS.TERMINATE()
>      ENDIF
>   ENDIF
>
>ENDFOR 
>
>RETURN i
>
>*----------------------------*
>FUNCTION GetProcessID()
>*----------------------------*
>* Identify the process id for the process
>DECLARE INTEGER GetCurrentProcessId IN kernel32
>pnPID = GetCurrentProcessId()
>
>RETURN pnPID 
>
>ENDFUNC
>
>
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform