ErezSch Posted March 4, 2022 Posted March 4, 2022 (edited) 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 March 4, 2022 by Jos added codebox
Developers Jos Posted March 4, 2022 Developers Posted March 4, 2022 (edited) 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 March 4, 2022 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.
ErezSch Posted March 4, 2022 Author Posted March 4, 2022 so what's you offer actually? which change i need? this code was created with the example template that on this website
Solution Trong Posted March 4, 2022 Solution Posted March 4, 2022 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) ErezSch 1 Regards,
TheXman Posted March 4, 2022 Posted March 4, 2022 (edited) 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 March 4, 2022 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
ErezSch Posted March 4, 2022 Author Posted March 4, 2022 ok i understand the problem now, it's my first time that i wrote script with autoit, i will read again the tutorial how to use
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now