Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do I get the owner of process running>
Message
From
30/07/2016 14:19:22
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
How do I get the owner of process running>
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2016
Network:
Windows Server 2016
Database:
Visual FoxPro
Application:
Desktop
Virtual environment:
VMWare
Miscellaneous
Thread ID:
01638970
Message ID:
01638970
Views:
79
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
Stuart Reid

True nobility lies not in being superior to another man, but in being superior to one’s previous self
Next
Reply
Map
View

Click here to load this message in the networking platform