Jump to content

Help with RunAsSet - work with domain accounts?

Recommended Posts

Hi folks,

I'm trying an automated software install, and the software requires a regkey added to run.

RunAsSet("domainadminaccountname", "DOMAINNAME", "password",0)
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "nikink-testing", "REG_SZ", "C:\Program Files\Something.exe")
$Err = @error
Switch $Err
Case $Err = 1 
    MsgBox(0, "RegWrite Succeeded!", "In theory!")
Case $Err = 2 
    MsgBox(0, "Error on RegWrite!", "Unable to open requested main key!")
Case $Err = 3 
    MsgBox(0, "Error on RegWrite!", "unable to remote connect to the registry!")
Case $Err = -1
    MsgBox(0, "Error on RegWrite!", "unable to open requested value!")
Case $Err = -2 
    MsgBox(0, "Error on RegWrite!", "value type not supported!")
Case $Err = 0 
    MsgBox(0, "Error on RegWrite!", "Unable to open requested key!")
$var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "nikink-testing")

MsgBox(0, "Registry", $var)
Sleep(5000) ;five seconds

Now, running this from a user account, fails to write anything to the registry. But it SHOULD because of the runasset(domainaccount)... shouldn't it?

Pls help!

Link to post
Share on other sites

It's not actually writing to the registry. My clumsy switch statement there has proven useless.

If I'm logged in as a domainadmin, and run my script, I get "RegWrite Succeeded!" and then the second msgbox pops up and shows "C:\Program Files\Something.exe" which is great and what I expected.

If I'm logged in as bog standard user and run the script, I get "RegWrite Succeeded!" but the second box is blank, and if I check the registry manually, I can confirm there is no new entry.

Link to post
Share on other sites

My first preface is that I am no expert. (I just really got started.) But doesn't the RunAsSet adjust the credentials for items launched with the Run(), and RunWait() functions? I don't think it applies to RegWrite() function. As a workarround, you could use the Run() function to launch regedit session to write the information to the registry. An example is below:

regedit newstuff.reg /s

The /s switch will cause regedit to run silent. Then again, you might not want this as you can still automate the process and perhaps use the output to validate that things went correctly. :)


Link to post
Share on other sites

Thanks for the advice. I eventually found a way to make the script re-run itself with admin rights, which allowed for the regwrite to work. I think this is one of the more frequently posed problems on the forums cuz there were many many many threads found on it using search, and I wonder if there could ever be a collection of these problems (with answers) linked off the documentation files or something like that. I needed the answer at very short notice, so I searched, and then while searching started this thread, and kept searching. Yay for the AutoIt forumites!

But it occurred to me that if the solution to these seemingly common problems were linked from a central area, a lot of repetitive posts would be eliminated.

Anyway, thankyou all! B-)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...