Jump to content

Recommended Posts

Posted

I know how run a particular task in AutoIt as an Admin using RunAsSet, but I can't find a way to run an entire script.

For example, I would like for Non-Admin users to be able to launch an AutoIt executable file that modifies two entries in the HKLM part of the Registry. The following works--but obviously only in Admin mode. Any assistance would be appreciated.

CODE

$Reg01_keyname = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"

$Reg01_valuename = "DisablePagingExecutive"

$Reg01_type = "REG_DWORD"

$Reg01_value = "00000001"

RegWrite ( $Reg01_keyname, $Reg01_valuename, $Reg01_type, $Reg01_value)

If @error Then

MsgBox(4096,"", "Error: " & $Reg01_keyname)

Else

MsgBox(4096, "Result for " & $Reg01_valuename, "Successfully wrote value: " & $Reg01_value & _

@LF & "To name: " & $Reg01_valuename & _

@LF & "Under key: " & $Reg01_keyname)

EndIf

;===Force Windows to Unload DLLs from Memory

$Reg02_keyname = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AlwaysUnloadDLL"

$Reg02_valuename = ""

$Reg02_type = "REG_SZ"

$Reg02_value = "1"

RegWrite ( $Reg02_keyname, $Reg02_valuename, $Reg02_type, $Reg02_value)

If @error Then

MsgBox(4096,"", "Error: " & $Reg02_keyname)

Else

MsgBox(4096, "Result for " & $Reg02_valuename, "Successfully wrote value: " & $Reg02_value & _

@LF & "To name: " & $Reg02_valuename & _

@LF & "Under key: " & $Reg02_keyname)

EndIf

Posted

I had this problem also, so I made 2 scripts. One is the one that does things (like edit the registry). The other is a wrapper that executes the actual app.

Dim $Username, $Password
$Username = "Administrator"
$Password = "Password"
RunAsSet ( $Username, @Computername, $Password )
RunWait ( "registry.exe" )

The program "registry.exe" is a separate script that actually has your code in it that you posted.

  • Developers
Posted

Just restart the script with admin credentials ..

$USERNAME = "Administrator"
$PASSWORD = "Secret"
$RUN = 0       ; run indicator 
; retrieve the cycle from commandline
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
If $RUN = 0 Then
   RunAsSet($USERNAME, @ComputerName, $PASSWORD)
   Run('"' & @ScriptFullPath & '" " 1"') 
   If @error Then MsgBox(4096+32,"Error", "Error starting under admin mode")
   Exit
EndIf
; commands go here that require Administrator rights

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

Just restart the script with admin credentials ..

$USERNAME = "Administrator"
$PASSWORD = "Secret"
$RUN = 0       ; run indicator 
; retrieve the cycle from commandline
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
If $RUN = 0 Then
   RunAsSet($USERNAME, @ComputerName, $PASSWORD)
   Run('"' & @ScriptFullPath & '" " 1"') 
   If @error Then MsgBox(4096+32,"Error", "Error starting under admin mode")
   Exit
EndIf
; commands go here that require Administrator rights
I guess that would work too, but its really the same thing I posted except you added a messagebox. Edited by Tripredacus
  • Developers
Posted

I guess that would work too, but its really the same thing I posted except you added a messagebox.

Principal is the same but a lot easier to accomplish what the op wanted I would say ... :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...