Jump to content

Runas Function Instead Of Opening Outside Program?


Recommended Posts

I am trying to write registry values as an administrator. Normally, I would do a RunAsSet and call an outside script, let's call it registryfix.exe, that just had the RegWrite information. Is there a way to do a RunAsSet and then RunWait a function instead of an external program? The reason I want to do this is to reduce the amount of scripts from 2 to 1 that I need to perform this function. I just think AutoIt has to have a way to do things within a script as a different user.

Thanks!

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

I am trying to write registry values as an administrator.

Have you tried creating a .reg file?

Registry Cmd Line Options.

Is there a way to do a RunAsSet and then RunWait a function instead of an external program?

I'm not sure what you are asking... If you run a function, it must complete (usually giving a return value or changing @error level) before the next line is executed.

You could try running a secondary script:

RunWait('cmd /c "c:\Program Files\AutoIt3\AutoIt3.exe" MyUDF.au3', '', @SW_HIDE)

Or just a function like this:

RunWait('cmd /c "c:\Program Files\AutoIt3\'AutoIt3.exe /AutoIt3ExecuteLine  "MsgBox(0, 'Hello World!', 'Hi!')"'
, '', @SW_HIDE)
Edited by MadSc13ntist
Link to comment
Share on other sites

RunAsSet("Administrator", @Computername, "adminpassword")

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey", "REG_SZ", "Hello this is a test")

RunAsSet()

I'm not sure what you are asking... If you run a function, it must complete (usually giving a return value or changing @error level) before the next line is executed.

That will just try to write the registry value as the user running the script. RunAsSet only applies to Run and RunWait. The RunAsSet in that script does absolutely nothing.

I'm asking if I can do something like this:

RunAsSet("Administrator", @Computername, "adminpassword")

RunWait('function')

RunAsSet()

Func function()

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey", "REG_SZ", "Hello this is a test")

EndFunc

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

That will just try to write the registry value as the user running the script. RunAsSet only applies to Run and RunWait. The RunAsSet in that script does absolutely nothing.

I'm asking if I can do something like this:

RunAsSet("Administrator", @Computername, "adminpassword")

RunWait('function')

RunAsSet()

Func function()

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey", "REG_SZ", "Hello this is a test")

EndFunc

RunAsSet("Administrator", @Computername, "adminpassword")
RunWait('cmd /c "c:\Program Files\AutoIt3\'AutoIt3.exe /AutoIt3ExecuteLine  "RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey", "REG_SZ", "Hello this is a test")"'
, '', @SW_HIDE)
RunAsSet()

Or

RunAsSet("Administrator", @Computername, "adminpassword")
RunWait('cmd /c regedit.exe /s myfile.reg', '', @SW_HIDE)
RunAsSet()

this is a good question not sure if i've got an answer for this one but that is probably the best i can think of. I will certainly follow this post.

Edited by MadSc13ntist
Link to comment
Share on other sites

Restart the same script as admin.

Sample code:

If Not $CMDLINE[0] Then
    RunAsSet("Administrator", @Computername, "adminpassword")
    If @Compiled Then
        RunWait('"' & @ScriptFullPath & '" /admin')
    Else
        RunWait('"' & @AutoItExe & '" "' & @ScriptFullPath & '" /admin')
    EndIf
    RunAsSet()
ElseIf $CMDLINE[0] And $CMDLINE[1] = '/admin' Then
    RegWrite("HKLM\SOFTWARE\Test", "TestKey", "REG_SZ", "Hello this is a test")
EndIf
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...