Autor Beitrag
OKNER
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 19



BeitragVerfasst: Di 03.10.06 11:46 
Hallo,

in VB komme ich über dies an den User, der einen Prozess gestartet hat:

Dim Processes As WbemScripting.SWbemObjectSet = WMIService.ExecQuery("select * from win32_process")

Mit Process.GetProcesses() bekomme ich in c# die anderen Infos (Pfad,...), die ich haben will. Nur nicht den User.

Wie funktioniert das in c#?

Habe dazu nichts gefunden.

Gruß
Renko


Moderiert von user profile iconChristian S.: Topic aus C# - Die Sprache verschoben am Do 08.11.2007 um 09:35
OKNER Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 19



BeitragVerfasst: Do 08.11.07 10:28 
Titel: Lösung
Zitat:
man kann einfach via InvokeMethod die "GetOwner" Methode aufrufen. Als Parameter muss man ein Array von string Objekten übergeben, in der dann der User und die PID drinsteht.

Siehe www.csharphelp.com/a...ves2/archive334.html


Links zur Lösung:

www.csharphelp.com/a...ves2/archive334.html

msdn2.microsoft.com/...ibrary/Aa390460.aspx

Bespiel in VB:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
strComputer = "."
Set colProcesses = GetObject("winmgmts:" & _
   "{impersonationLevel=impersonate}!\\" & strComputer & _
   "\root\cimv2").ExecQuery("Select * from Win32_Process")

For Each objProcess in colProcesses

    Return = objProcess.GetOwner(strNameOfUser)
    If Return <> 0 Then
        Wscript.Echo "Could not get owner info for process " & _  
            objProcess.Name & VBNewLine _
            & "Error = " & Return
    Else 
        Wscript.Echo "Process " _
            & objProcess.Name & " is owned by " _ 
            & "\" & strNameOfUser & "."
    End If
Next