473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How does a process find its user

Is it possible in .NET2.0 to find the user that the current process is
running under without going through the whole WMI palaver? I tried looking at
ProcessStartInfo.UserName but that was empty - I presume that's more for new
starting processes than examining the current one.
--
Dave
Jul 7 '06 #1
7 3106
WindowsPrincipal Principle = Thread.CurrentPrincipal as WindowsPrincipal;

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Dave" <Da**@discussions.microsoft.comwrote in message
news:2D**********************************@microsof t.com...
Is it possible in .NET2.0 to find the user that the current process is
running under without going through the whole WMI palaver? I tried looking
at
ProcessStartInfo.UserName but that was empty - I presume that's more for
new
starting processes than examining the current one.
--
Dave

Jul 7 '06 #2
Wow, brilliant, and it's not even new in VS2005!

Now - do you know how to get the user that a DIFFERENT process is running
under? I can do Process.GetProcesses() but a Process doesn't seem to include
user info.
--
Dave
"Greg Young" wrote:
WindowsPrincipal Principle = Thread.CurrentPrincipal as WindowsPrincipal;

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Dave" <Da**@discussions.microsoft.comwrote in message
news:2D**********************************@microsof t.com...
Is it possible in .NET2.0 to find the user that the current process is
running under without going through the whole WMI palaver? I tried looking
at
ProcessStartInfo.UserName but that was empty - I presume that's more for
new
starting processes than examining the current one.
--
Dave


Jul 7 '06 #3
Something like this ?

static void Main(string[] args) {
string[] arg = { "", "" };

ManagementScope scope = new ManagementScope(@"\root\cimv2");
ObjectQuery query = new ObjectQuery("select * from
Win32_Process");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);
ManagementObjectCollection processes = searcher.Get();
foreach (ManagementObject process in processes) {
process.InvokeMethod("GetOwner", arg);
Console.WriteLine("caption = " + process["caption"] + "
owner = " + arg[1] + "\\" + arg[0]);
}
}

note you would just need the process id to only call it for a single process

Cheers,

Greg
"Dave" <Da**@discussions.microsoft.comwrote in message
news:3A**********************************@microsof t.com...
Wow, brilliant, and it's not even new in VS2005!

Now - do you know how to get the user that a DIFFERENT process is running
under? I can do Process.GetProcesses() but a Process doesn't seem to
include
user info.
--
Dave
"Greg Young" wrote:
>WindowsPrincipal Principle = Thread.CurrentPrincipal as WindowsPrincipal;

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Dave" <Da**@discussions.microsoft.comwrote in message
news:2D**********************************@microso ft.com...
Is it possible in .NET2.0 to find the user that the current process is
running under without going through the whole WMI palaver? I tried
looking
at
ProcessStartInfo.UserName but that was empty - I presume that's more
for
new
starting processes than examining the current one.
--
Dave



Jul 7 '06 #4
Yes, that's the "WMI palaver" I mentioned earlier. I was hoping .NET2.0 might
have something more elegant. Thanks anyway.
--
Dave
"Greg Young" wrote:
Something like this ?

static void Main(string[] args) {
string[] arg = { "", "" };

ManagementScope scope = new ManagementScope(@"\root\cimv2");
ObjectQuery query = new ObjectQuery("select * from
Win32_Process");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);
ManagementObjectCollection processes = searcher.Get();
foreach (ManagementObject process in processes) {
process.InvokeMethod("GetOwner", arg);
Console.WriteLine("caption = " + process["caption"] + "
owner = " + arg[1] + "\\" + arg[0]);
}
}

note you would just need the process id to only call it for a single process

Cheers,

Greg
"Dave" <Da**@discussions.microsoft.comwrote in message
news:3A**********************************@microsof t.com...
Wow, brilliant, and it's not even new in VS2005!

Now - do you know how to get the user that a DIFFERENT process is running
under? I can do Process.GetProcesses() but a Process doesn't seem to
include
user info.
--
Dave
"Greg Young" wrote:
WindowsPrincipal Principle = Thread.CurrentPrincipal as WindowsPrincipal;

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Dave" <Da**@discussions.microsoft.comwrote in message
news:2D**********************************@microsof t.com...
Is it possible in .NET2.0 to find the user that the current process is
running under without going through the whole WMI palaver? I tried
looking
at
ProcessStartInfo.UserName but that was empty - I presume that's more
for
new
starting processes than examining the current one.
--
Dave


Jul 8 '06 #5
There are other ways of getting the same information (such as pinvoking). I
am not sure if you consider those more elegant.

Cheers,

Greg
"Dave" <Da**@discussions.microsoft.comwrote in message
news:DA**********************************@microsof t.com...
Yes, that's the "WMI palaver" I mentioned earlier. I was hoping .NET2.0
might
have something more elegant. Thanks anyway.
--
Dave
"Greg Young" wrote:
>Something like this ?

static void Main(string[] args) {
string[] arg = { "", "" };

ManagementScope scope = new ManagementScope(@"\root\cimv2");
ObjectQuery query = new ObjectQuery("select * from
Win32_Process");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);
ManagementObjectCollection processes = searcher.Get();
foreach (ManagementObject process in processes) {
process.InvokeMethod("GetOwner", arg);
Console.WriteLine("caption = " + process["caption"] + "
owner = " + arg[1] + "\\" + arg[0]);
}
}

note you would just need the process id to only call it for a single
process

Cheers,

Greg
"Dave" <Da**@discussions.microsoft.comwrote in message
news:3A**********************************@microso ft.com...
Wow, brilliant, and it's not even new in VS2005!

Now - do you know how to get the user that a DIFFERENT process is
running
under? I can do Process.GetProcesses() but a Process doesn't seem to
include
user info.
--
Dave
"Greg Young" wrote:

WindowsPrincipal Principle = Thread.CurrentPrincipal as
WindowsPrincipal;

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Dave" <Da**@discussions.microsoft.comwrote in message
news:2D**********************************@microso ft.com...
Is it possible in .NET2.0 to find the user that the current process
is
running under without going through the whole WMI palaver? I tried
looking
at
ProcessStartInfo.UserName but that was empty - I presume that's more
for
new
starting processes than examining the current one.
--
Dave



Jul 8 '06 #6
Hmm. Actually it's really speed that is the important factor - but I doubt
that a pinvoke will be significantly faster.
--
Dave
"Greg Young" wrote:
There are other ways of getting the same information (such as pinvoking). I
am not sure if you consider those more elegant.

Cheers,

Greg
"Dave" <Da**@discussions.microsoft.comwrote in message
news:DA**********************************@microsof t.com...
Yes, that's the "WMI palaver" I mentioned earlier. I was hoping .NET2.0
might
have something more elegant. Thanks anyway.
--
Dave
"Greg Young" wrote:
Something like this ?

static void Main(string[] args) {
string[] arg = { "", "" };

ManagementScope scope = new ManagementScope(@"\root\cimv2");
ObjectQuery query = new ObjectQuery("select * from
Win32_Process");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);
ManagementObjectCollection processes = searcher.Get();
foreach (ManagementObject process in processes) {
process.InvokeMethod("GetOwner", arg);
Console.WriteLine("caption = " + process["caption"] + "
owner = " + arg[1] + "\\" + arg[0]);
}
}

note you would just need the process id to only call it for a single
process

Cheers,

Greg
"Dave" <Da**@discussions.microsoft.comwrote in message
news:3A**********************************@microsof t.com...
Wow, brilliant, and it's not even new in VS2005!

Now - do you know how to get the user that a DIFFERENT process is
running
under? I can do Process.GetProcesses() but a Process doesn't seem to
include
user info.
--
Dave
"Greg Young" wrote:

WindowsPrincipal Principle = Thread.CurrentPrincipal as
WindowsPrincipal;

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Dave" <Da**@discussions.microsoft.comwrote in message
news:2D**********************************@microsof t.com...
Is it possible in .NET2.0 to find the user that the current process
is
running under without going through the whole WMI palaver? I tried
looking
at
ProcessStartInfo.UserName but that was empty - I presume that's more
for
new
starting processes than examining the current one.
--
Dave



Jul 8 '06 #7
I just tried this, and it doesn't actually work. For one thing
Thread.CurrentPrinciple actually returns a GenericPrincipal not a
WindowsPrincipal, and secondly Thread.CurrentPrincipal.Identity.Name, which
presumably should contain the user name, is blank. Maybe I'm doing something
wrong. Anyway, I'm now using WindowsIdentity.GetCurrent().Name which seems to
work OK.
--
Dave
"Greg Young" wrote:
WindowsPrincipal Principle = Thread.CurrentPrincipal as WindowsPrincipal;

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Dave" <Da**@discussions.microsoft.comwrote in message
news:2D**********************************@microsof t.com...
Is it possible in .NET2.0 to find the user that the current process is
running under without going through the whole WMI palaver? I tried looking
at
ProcessStartInfo.UserName but that was empty - I presume that's more for
new
starting processes than examining the current one.
--
Dave


Jul 12 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: pigeon | last post by:
I have 2 users that their client software must be going crazy.. they are sending packets every .02 seconds to the db server... I know this because I stuck a sniffer on teh traffic.. but now i just...
1
by: kbailey | last post by:
what a waste of money. visual studio does not handle user control files - these are files with and ascx extension are are refered to in the help as 'user-authored server controls'. the VS...
2
by: jason | last post by:
I'm trying to run an external command-line file using user create C:\DLL\*.dll files as following code Process.Start("c:\test.exe" The test.exe has no problem when I run on the dos prompt as I...
3
by: Trapulo | last post by:
What does mean this error? The current configuration system does not support user-scoped settings. I'm accessing a my.settings data from a DAL dll referenced by an ASP.NET app. I've a...
6
by: Steve Kershaw | last post by:
I have a problem in which I'm trying to access a method in a .DLL from an ASP.Net web page (written in C#). I keep on getting the error "The current configuration system does not support...
6
by: Andrus | last post by:
I need to create object cache in memory. Each object id can be composed from several string, integer and decimal type values. ContainsKey does not find existing key in this case. How to...
5
by: kimiraikkonen | last post by:
I made a very small (2 forms) application with VB.NET 2005 express and second form contains web-browser component and flash movie inside it. Everything OK but after i close the program via normal...
2
by: Screaming Eagles 101 | last post by:
Hi, I looked and found a lot of different code regarding send/receiving input/output to a command window, but none helped me so far. I would like to start a process with telnet a bit like this...
4
by: James | last post by:
Hi, I have just upgraded a user machine to Vista (our first) as a test. Unfortunately a couple of our apps are failing due to Vista... 1. One app that loads an assembly from an Intranet...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.