Sign in to follow this  
Followers 0
EricL

Add current user to administrators group with runas

4 posts in this topic

This is probably simple. But i am struggling for many hours with this.

Any sugestions on how to get a non-admin added to the local administrators group?

i figured it out in dos with set localgroup. but if you run this as an admin so you have permission to make the change, it uses the variable %username% of the runas person.

I need the executor of the script added to admins group. I will hard code the user that can approve this into the script.

Any help appreciated.

THanks!

Share this post


Link to post
Share on other sites



I guess you could add them using "net localgroup administrator YOURUSER /add" that should add them to the admin group. However I'm not sure if this will require a logon logoff to take effect or not. You might be able to run a gpupdate meaning you won't have to log off. But I can't be sure.

Hope this helps

CalBoy

Share this post


Link to post
Share on other sites

I guess you could add them using "net localgroup administrator YOURUSER /add" that should add them to the admin group. However I'm not sure if this will require a logon logoff to take effect or not. You might be able to run a gpupdate meaning you won't have to log off. But I can't be sure.

Hope this helps

CalBoy

im installing software where part of the setup pulls the user name for registration. so it needs to run as the end user. i found if i do it manually via command prompt and do a runaswait with "do not load profile" it seems to recognize they are in the admins group. However the user in question is not a admin before the script runs. so they can not run the localgroup /add. and if i run it as a local admin I can no longer use the %username% because it will pull "administrator" as the current ser because of the runas.

Share this post


Link to post
Share on other sites

One way to do it would be to get use some of the Process UDF's from around the forum to get the user that is currently running explorer. Once you have that then you can substitute that value in instead of %username% and use runas.

I can't remember which UDF you want to use, but basically it parses the running processes and then you could do some string matching and get the username. I think I might have written something that even uses this, but I can't seem to find it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0