Click here to Skip to main content
15,891,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear everyone
my windows application needs the limited user to login as administrator...

so i made a form with username, password, domain. then i logged in as administrator ..

the problem is that while running the application for the first time it gives a domain name "NT AUTHORITY" but my domain name is "JOHN"..

but after closing the application and open it again it gives my true domain name "JOHN"


i tried to use this code to get domain name

C#
string domain_name=Environment.UserDomainName;


i tried to use also this code
C#
string sTempUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
if (sTempUser.IndexOf("\\") != -1)
{
    string[] aryUser = new String[2];
    char[] splitter = { '\\' };
    aryUser = sTempUser.Split(splitter);
   string domain_name = aryUser[0];

}

i want to know how i can get my domain name IN FIRST time as it is in next time of executing the program??
Posted

The code is correct. I'm more interested in knowing what you did to get it to fail the way you describe.

An application, when launched, is launched as the user that launched it. It inherits the users security token. AT NO TIME is the application running as another user or system account and then switches to the current user, unless explicitly coded to do so! And even then, it will launch as the user first, then switch the another account.

If this application needs the users admin privileges, then you should be creating a manfiest for the app and changing the requestedExecutionLevel as spelled out in these[^].

There's no need for a username and password box for that.
 
Share this answer
 
Comments
John_Tadros 20-Nov-13 1:58am    
more explanation of the problem



i have to put username, password and domain because the application must
run as administrator and the limited user must not use some features of
the application.. but if the administrator enters the username, password
and domain... it let him work as administrator and use all features of
application for this time only and if the program is closed then opened it will work as limited user with his limited features... so i dont want to work as administrator all the times.. but only when the administrator add his credentials only.

the problem is that the application gives for me wrong domain name and sometimes when i tried to put domain name as empty it works correctly...

can i run as administrator without domain?? using username and password only or i have to write domain??

and if i have to write domain .. how to get the true domian name


i dont know how can i help it..
Dave Kreskowiak 20-Nov-13 9:25am    
You can't switch the elevation context at runtime. What you can do is partition your app into seperate executables, one for normal users and one for administrators, each with its own manifest specifying the ExecutionLevel for it. If the user doesn't have an admin account, launch the normal user app, or if they do, launch the admin level app. Having the seperate applications and manifests also keeps a normal user from trying to circumvent the login and launching the admin level app directly.
i already made it with username, password and domain and everything is going good..and works perfectly.... i don't have to make 2 manifest


all that i need is to get the right domain name... else everything is working perfectly
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900