Temporarily give a user local administrator rights  
Author Message
TravisTurman





PostPosted: Visual C# Language, Temporarily give a user local administrator rights Top

I'm a C# newbie and have inherited an application at work that runs at login. Part of this application looks at a text file to determine what version is installed and then installs the latest/greatest version if one is available. In order to do this, the user logging in has to have local administrator rights on the Windows XP workstation. Is there a way to determine if the user logging in has administrator rights and if not give them the rights while the application is running and then take them back when the application is done running.

Any help would be greatly appreciated.



Visual C#3  
 
 
James Curran





PostPosted: Visual C# Language, Temporarily give a user local administrator rights Top

I believe there is a method to bump a user's rights. However, to make use of this, the application will have to store a copy of an admin userid/password for the particular system it's being run on. This puts a large security hole in any system that is running your application, but doing it any other way would require putting a incredible security hole in the operating system.

 
 
TravisTurman





PostPosted: Visual C# Language, Temporarily give a user local administrator rights Top

Thanks for the input. I've heard about the IMPERSONATE method but that requires hard coding an administrator user name/password in the project. I'd like to avoid this if possible.

Somone on another forum suggested:

"If you need it to be tied to someone logging in instead of just when
the computer starts up you can still use a windows service for the
real work, set it to manual start, and then have a winform app that
runs on startup and uses ServiceController to start up the windows
service (which can shut itself down when done)."

Being a newbie, I'm not sure how to do this or if it would even answer my question.


 
 
James Curran





PostPosted: Visual C# Language, Temporarily give a user local administrator rights Top

That works mostly by passing the buck, but it would work.

When the service is installed, the user can assign it a userid/password for an account to run under. So, we're basically doing the same thing as above, except we're letting Windows hold on to the password, in a secure way.

I've never actually created a service, but I don't believe it's very difficult. As I understand it, you just derive a class from System.ServiceProcess.ServiceBase, and implement two methods (OnStart and OnStop --- and since you'd be doing everything in OnStart, include shutting down, your OnStop would be empty).