Jump to content

script not work as administrator


Go to solution Solved by Trong,

Recommended Posts

sharing my code:

#cs ----------------------------------------------------------------------------

 Author: Erez Schwartz

 Script Function: Install Shekel OPOS as administrator

#ce ----------------------------------------------------------------------------

#include <ScaleSetup.au3>

ScaleInstall()

Func ScaleInstall()
    ; Change the username and password to the appropriate values for your system.
    Local $sUserName = "administrator"
    Local $sPassword = "mypassword"

    ; Install Shekel OPOS with the window maximized. Program will run under the user previously specified.
    Local $iPID = RunAs($sUserName, $sPassword, "d:\install\Weight\Megalen_scale.exe", "", @SW_SHOWMAXIMIZED)

    ; Wait for 4 seconds.
    Sleep(4000)

    ; Close the setup process using the PID returned by RunAs.
    ProcessClose($iPID)
EndFunc   ;==>ScaleInstall

 

the script doing nothing, it's trying to run as the current user and not the administrator account that i put on the script (the real password was replaced only for this forum)

Edited by Jos
added codebox
Link to comment
Share on other sites

  • Developers

You are not testing the success of RunAs() so we have no idea whether that was successful:

Quote

 

Return Value

Success: the PID of the process that was launched.
Failure: 0 and sets the @error flag to non-zero.

 

Please also check how to post code properly. :) 

 

Edited by Jos

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

Link to comment
Share on other sites

  • Solution

Wrong RunAs  Parameters

 

#include <ScaleSetup.au3>
#include <AutoItConstants.au3>

ScaleInstall()

Func ScaleInstall()
    ; Change the username and password to the appropriate values for your system.
    Local $sUserName = "administrator"
    Local $sPassword = "mypassword"
    Local $ComputerName = @ComputerName
    Local $FilePath = "d:\install\Weight\Megalen_scale.exe"

    ; Install Shekel OPOS with the window maximized. Program will run under the user previously specified.
    Local $iPID = RunAs($sUserName, $ComputerName, $sPassword,  $RUN_LOGON_NOPROFILE, $FilePath, "", @SW_SHOWMAXIMIZED)
    ConsoleWrite("+ PID: " & $iPID & ' - Error:'& @error & @CRLF)
    ; Wait for 4 seconds.
    Sleep(4000)

    ; Close the setup process using the PID returned by RunAs.
    ProcessClose($iPID)
EndFunc   ;==>ScaleInstall

 

or 

#RequireAdmin
    Local $FilePath = "d:\install\Weight\Megalen_scale.exe"
    Local $iPID = Run( $FilePath, "", @SW_SHOWMAXIMIZED)
    ConsoleWrite("+ PID: " & $iPID & ' - Error:'& @error & @CRLF)

 

Regards,
 

Link to comment
Share on other sites

7 hours ago, ErezSch said:

Local $iPID = RunAs($sUserName, $sPassword, "d:\install\Weight\Megalen_scale.exe", "", @SW_SHOWMAXIMIZED)

Go back and look at the definition of the RunAs function in the Help File.  Pay CLOSE attention to the parameter list.  Then take a look at your parameters.  Do you see a problem?

Edited by TheXman
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...