Temporarily give the current user Local Admin rights

  • Thread starter Thread starter TravisTurman
  • Start date Start date
T

TravisTurman

I'm a C# newbie and have inherited a program that runs at login. Part
of the program looks at a text file to see which version is installed
and then installs the latest greatest version if needed. In order for
this to work, the person logging into the Windows XP desktop needs to
have local admin rights on the machine. Is there a way using C# to
give the current user the necessary rights, or put them in the local
administrators group, when this application starts and then put them
back to the way they were when the program finishes running?

Any help would be greatly appreciated.
 
Consider what you're asking for and then consider why the OS may try
and prevent this.

Now if your program is running UNDER an administrative account to set
something up later, that's a different story, but that doesn't appear
to be what you're asking for.
 
You can use impersonation but that requires storing the
username/password of an admin which you probably don't want to do.

A better option is to use a windows service which can be set to run as
an admin user. It can do whatever automatic stuff is needed and then
exit.

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).

HTH,

Sam
 
I'm not sure I understand you. Let me see if I can clarify what I'm
talking about. Right now I am a local administrator over my
workstation, but if I log in on another workstation I'm not a local
administrator unless someone with administrator access adds me to the
local administrator group on the workstation. What I'd like to have
happen is no matter which workstation I log into, I want to be a local
administrator while our PC inventory program runs and then be removed
from the local admin group when it's done.

Does this make sense?
 
Thanks for the info, Sam, but being a C# newbie I'm not sure how to
code something like this. The last option you mention sounds like what
I'm looking for. Do you have some sample code I can look at or know
where I can find some?
 
TravisTurman said:
I'm a C# newbie and have inherited a program that runs at login. Part
of the program looks at a text file to see which version is installed
and then installs the latest greatest version if needed. In order for
this to work, the person logging into the Windows XP desktop needs to
have local admin rights on the machine. Is there a way using C# to
give the current user the necessary rights, or put them in the local
administrators group, when this application starts and then put them
back to the way they were when the program finishes running?

Any help would be greatly appreciated.


Just schedule the program to run at each user logon using Wndows task scheduler.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top