By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

Temporarily give the current user Local Admin rights

P: n/a
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.

Dec 14 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.

On Dec 13, 4:17 pm, "TravisTurman" <travis_tur...@corphealth.com>
wrote:
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.
Dec 14 '06 #2

P: n/a

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

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On 13 Dec 2006 13:17:47 -0800, "TravisTurman"
<tr***********@corphealth.comwrote:
>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.
Dec 14 '06 #3

P: n/a
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?

Michael Letterle wrote:
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.

On Dec 13, 4:17 pm, "TravisTurman" <travis_tur...@corphealth.com>
wrote:
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.
Dec 14 '06 #4

P: n/a
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?

Samuel R. Neff wrote:
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

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On 13 Dec 2006 13:17:47 -0800, "TravisTurman"
<tr***********@corphealth.comwrote:
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.
Dec 14 '06 #5

P: n/a
"TravisTurman" <tr***********@corphealth.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
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.

Dec 14 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.