David,
I needed a user name (logon name) who created
a process, and this gives me some integer???
thanks
--
Strah
"David Browne" <davidbaxterbrowne no potted
(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
>
> "Willy Denoyette [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Strahimir Antoljak wrote:
> > || Is there a way to find out the name
> > || of the user who created a process.
> > || Some kind of process property or method
> > || that would report the user name how launched
> > || it?
> > || (but not Environment.UserName)
> > ||
> > || Thanks,
> > ||
> > || --
> > || Strah
> >
> > There is no support for this in the FCL.
> > Your only option is to PInvoke (or MC++)
> > 1. call the Win32 'OpenProcessToken' Win32 API using the
'Process.Handle'
> property as the first argument
> > 2. use the tokenHandle returned to call WindowsIdentity(tokenHandle)
> > 3. WindowsIdentity.Name should contain the process owner.
> > 4. Close the tokenHandle using the 'CloseHandle' Win32 API.
> >
> > Note that you will need special privileges to call OpenProcessToken,
> consult the SDK docs for details.
> > Willy.
> >
> Yikes. Sounds scarry.
>
> Anyway there is a performance counter that will tell you this. It is
slow,
> since the instances are identified by name, so you have to iterate all the
> Process counter instances, but it's probably fast enough for some
purposes.
> Eg to determine if a application has been started as a service or not.
>
>
> Function GetCreatingProcessID(ByVal processID As Integer) As Integer
> Dim creatingProcess As Integer
> Dim cat As New
System.Diagnostics.PerformanceCounterCategory("Process")
> Dim instance As String
> For Each instance In cat.GetInstanceNames()
> Dim pid As New System.Diagnostics.PerformanceCounter("Process", "ID
> Process", instance, True)
> If pid.RawValue = processID Then
> Dim creator As New
System.Diagnostics.PerformanceCounter("Process",
> "Creating Process ID", instance, True)
> creatingProcess = creator.RawValue
> pid.Dispose()
> creator.Dispose()
> Return creatingProcess
> End If
> pid.Dispose()
> Next
> Throw New Exception("Process " & processID.ToString & " not found")
> End Function
>
> David
>
>