Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Process Username

Status
Not open for further replies.

mjk9564

Programmer
Apr 23, 2003
64
US
I'm writing code to shutdown a process in a Terminal Service Environment and I'm running into the problem that it shuts down that process for all users.

I know the user that is trying to shutdown the process now I need to find out the username for each process.

Here is the code I'm currently using to shutdown the process. Is there a way I can find out the username for each process with the process object?

Code:
       'This method will shutdown a given process name

        Dim instance As Process
        Dim myProcesses() As Process

             'Set the array to all the processes running w/ the same name
            myProcesses = Process.GetProcessesByName(strProcessName)

            'Stop a process
            For Each instance In myProcesses
                instance.Kill()
                instance.WaitForExit()
            Next

I found a lot of posts to get the username of the person logged onto the system, but I need the username for each process. I'm using VB.NET 2005.

Thanks in advance for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top