My first real use of the Powershell Object. WMI does not have a way to get the Window Title, however, .Net does... and Powershell's get-process can tie all this together...
Function PSGetWindowNamefromPID($PID , optional $PSObject )
if $PSobject =""
$PSObject =CreateObject ("SAPIEN.ActiveXPoSH" )
endif
if $PSObject.init (not 0 )
$PSObject.Execute ('$process=Get-Process | Where-Object {$_.ID -eq "' + $PID + '"}' )
$PSGetWindowNamefromPID =$PSObject.GetValue ('$process.MainWindowTitle' )
endif
endfunction
Function PSGetPIDfromWindowName($WindowName , optional $PSObject )
if $PSobject =""
$PSObject =CreateObject ("SAPIEN.ActiveXPoSH" )
endif
if $PSObject.init (not 0 )
$PSObject.Execute ('$process=Get-Process | Where-Object {$_.MainWindowTitle -eq "' + $WindowName + '"}' )
$PSGetPIDfromWindowName =$PSObject.GetValue ('$process.ID' )
endif
endfunction
So the code would be simply...
break on
$RC =setoption ("NoVarsInStrings" ,"on" )
$RC =setoption ("NoMacrosInStrings" ,"on" )
$RC =setoption ("WrapATEOL" ,"on" )
? PSGetWindowNamefromPid (4784 )
? PSGetPIDfromWindowName ("Administrator: Windows Powershell" )