Hi,
I'm looking through the list of processes via WMI.
Is it possible to find out the name of the user on whose behalf the process is opened?
Hi,
I'm looking through the list of processes via WMI.
Is it possible to find out the name of the user on whose behalf the process is opened?
Hi,
Why don't you use this function : WNetGetUser()
Good luck.
Regards,
Michel D.
Genk (Belgium)
I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773
driessen wrote:Hi,
Why don't you use this function : WNetGetUser()
Good luck.
FUNCTION TstUser()
LOCAL cDest := "procown.ps1"
LOCAL nHndl
nHndl := fCreate( cDest )
fClose( nHndl )
IF ( nHndl := fOpen( cDest, 17 ) ) != -1 // write+exclusive
fWrite( nHndl, [$proc = Get-CimInstance Win32_Process -Filter "name = 'notepad.exe'"] + HB_OsNewline() )
fWrite( nHndl, [Invoke-CimMethod -InputObject $proc -MethodName GetOwner >procown.txt] + HB_OsNewline() )
fClose( nHndl )
ENDIF
WinExec( "powershell.exe -windowstyle hidden -File procown.ps1" )
RETURN NILThanks, ADutheil !
To prevent the Powershell shell window from appearing, the script must be run through Wscript and cmd.exe .
Of course, I made a flag DBF, where each launching application locks its own line.
But it seemed to me that by viewing all processes through WMI, you can find out the name of the user on whose behalf a particular process is opened.