Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

System.Environment.UserName in a .net setup project gives me SYSTEM

Posted on 2009-07-09
2
Medium Priority
?
490 Views
Last Modified: 2012-06-21
Hi,
when starting my application from autostart or by an icon-click System.Environment.UserName gives me the logged in user's name. I want this.

When starting from a .net setup project (on finish) System.Environment.UserName gives me "SYSTEM". I don't want this.

Grateful for an answer!
0
Comment
Question by:Jonasxx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Assisted Solution

by:Craig Wagner
Craig Wagner earned 80 total points
ID: 24841351
I know that MSIExec does some of its work under a LocalSystem process, so that's probably what's happening. Have you tried using WindowsIdentity.GetCurrent().Name instead? It might give you the same result, but it's worth a try.
0
 

Accepted Solution

by:
Jonasxx earned 0 total points
ID: 24877440
WindowsIdentity.GetCurrent().Name is the same. I guess a part of the problem is that there can be many user logged in at the same time, solved it by in System.Management.
if (System.Security.Principal.WindowsIdentity.GetCurrent().IsSystem)
                    {
                        ConnectionOptions co = new ConnectionOptions();
                        ManagementScope ms = new ManagementScope(@"\\localhost\root\cimv2", co);
                        ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_ComputerSystem");
                        ManagementObjectSearcher searcher = new ManagementObjectSearcher(ms, oq);
                        ManagementObjectCollection collection = searcher.Get();
                        foreach (ManagementObject mo in collection)
                        {
                            userName = mo["UserName"].ToString();
                            int position = userName.LastIndexOf(@"\");
                            if (position != -1)
                            {
                                userName = userName.Substring(++position);
                            }
                            break;
                        }
                    }
                }

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question