Sign in to follow this  
Followers 0
digibuddha

Add user as admin then switch to user

5 posts in this topic

#1 ·  Posted (edited)

Hey Guys,

Trying to figure out a way to elevate the users rights then run the rest of the script as the user not the user that elevated the rights. Make Sense?

Code so far:

RunAsSet("username", "domain", "password", 0)

If IsAdmin() = 0 Then

runwait("net localgroup Administrators " & @UserName & " /Add")

EndIf
Edited by digibuddha

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Once you add the user to the admin group on the machine do this:

RunAsSet("USERNAME", @ComputerName, "PASSWORD")
If @Compiled Then
    Run('"' & @ScriptFullPath & '"')
    Exit
EndIf
Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Share this post


Link to post
Share on other sites

Once you add the user to the admin group on the machine do this:

RunAsSet("USERNAME", @ComputerName, "PASSWORD")
If @Compiled Then
    Run('"' & @ScriptFullPath & '"')
    Exit
EndIf
The alternative would be to use RunAsSet with no parameters after adding @username to the Administrators group. Using your original code:

If IsAdmin() = 0 Then
   RunAsSet("username", "domain", "password", 0)
   runwait("net localgroup Administrators " & @UserName & " /Add")
   RunAsSet()
EndIf

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This should do the trick, but often a Logoff/Logon is required to activate this setting. You could also try a forced restart of Explorer but that could also give other issues.

If IsAdmin() = 0 Then
    RunAsSet("username", "domain", "password", 0)
    RunWait("net localgroup Administrators " & @UserName & " /Add")
    RunAsSet()
EndIf
Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ok cool thanks guys. I'll give it a shot and let you know. I had actually given the last one a thought, but wasn't sure if that would do it.

Edited:

Yep that worked, working code:

If IsAdmin() = 0 Then
    RunAsSet("username", "domain", "password", 0)
    RunWait("net localgroup Administrators " & @UserName & " /Add")
    RunAsSet()
EndIf

Thank you all!

:)

Edited by digibuddha

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