jpru Posted June 1, 2007 Share Posted June 1, 2007 Hi ! this is the code: RunAsSet($username, @Computername, $pass) pid = Run($app) local $run_error = @error local $run_extended = @extended this gives me run_error = 1 run_extended = 267 I could not find anything usefull about the error codes. What happens there ? The error not always showing up, if I change the account of the logged in user and use another one to run the script it works without problems. So I think it is an external problem, but I do have to understand _what_ kind of problem so that I can fix it. TIA, Jürgen Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 1, 2007 Share Posted June 1, 2007 From the help file for Run()"By default the script will terminate with a fatal error if the Run function fails. To set @error 1, @extended to GetLastError() Windows API and return 0 as an indication of failure, see AutoItSetOption.So, you must have Opt("RunErrorsFatal", 0) in there somewhere, and @extended = 267 came from Windows, not AutoIt. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Zedna Posted June 1, 2007 Share Posted June 1, 2007 Use Opt("RunErrorsFatal", 0) as PsaltyDS said and after your Run() command use this function to show error: ;=============================================== ; _GetLastErrorMessage($DisplayMsgBox="") ; Format the last windows error as a string and return it ; if $DisplayMsgBox <> "" Then it will display a message box w/ the error ; Return Window's error as a string ;=============================================== Func _GetLastErrorMessage($DisplayMsgBox="") Local $ret,$s Local $p = DllStructCreate("char[4096]") Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000 If @error Then Return "" $ret = DllCall("Kernel32.dll","int","GetLastError") $ret = DllCall("kernel32.dll","int","FormatMessage",_ "int",$FORMAT_MESSAGE_FROM_SYSTEM,_ "ptr",0,_ "int",$ret[0],_ "int",0,_ "ptr",DllStructGetPtr($p),_ "int",4096,_ "ptr",0) $s = DllStructGetData($p,1) DllStructDelete($p) If $DisplayMsgBox <> "" Then MsgBox(0,"_GetLastErrorMessage",$DisplayMsgBox & @CRLF & $s) return $s EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 1, 2007 Share Posted June 1, 2007 Handy function, Zedna! RunAsSet($username, @ComputerName, $pass) $pid = Run($app) If @error Then MsgBox(16, "Error", "Run() produced and error:" & @CRLF & _GetLastErrorMessage ()) ;=============================================== ; _GetLastErrorMessage($DisplayMsgBox="") ; Format the last windows error as a string and return it ; if $DisplayMsgBox <> "" Then it will display a message box w/ the error ; Return Window's error as a string ;=============================================== Func _GetLastErrorMessage ($DisplayMsgBox = "") Local $ret, $s Local $p = DllStructCreate("char[4096]") Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000 If @error Then Return "" $ret = DllCall("Kernel32.dll", "int", "GetLastError") $ret = DllCall("kernel32.dll", "int", "FormatMessage", _ "int", $FORMAT_MESSAGE_FROM_SYSTEM, _ "ptr", 0, _ "int", $ret[0], _ "int", 0, _ "ptr", DllStructGetPtr($p), _ "int", 4096, _ "ptr", 0) $s = DllStructGetData($p, 1) DllStructDelete ($p) If $DisplayMsgBox <> "" Then MsgBox(0, "_GetLastErrorMessage", $DisplayMsgBox & @CRLF & $s) Return $s EndFunc ;==>_GetLastErrorMessage Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Zedna Posted June 1, 2007 Share Posted June 1, 2007 (edited) Sorry. This my function is very old so there was obsolete: DllStructDelete()Here is full corrected script also with Opt() addedOpt("RunErrorsFatal", 0) RunAsSet($username, @ComputerName, $pass) $pid = Run($app) If @error Then MsgBox(16, "Error", "Run() produced and error:" & @CRLF & _GetLastErrorMessage ()) ;=============================================== ; _GetLastErrorMessage($DisplayMsgBox="") ; Format the last windows error as a string and return it ; if $DisplayMsgBox <> "" Then it will display a message box w/ the error ; Return Window's error as a string ;=============================================== Func _GetLastErrorMessage ($DisplayMsgBox = "") Local $ret, $s Local $p = DllStructCreate("char[4096]") Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000 If @error Then Return "" $ret = DllCall("Kernel32.dll", "int", "GetLastError") $ret = DllCall("kernel32.dll", "int", "FormatMessage", _ "int", $FORMAT_MESSAGE_FROM_SYSTEM, _ "ptr", 0, _ "int", $ret[0], _ "int", 0, _ "ptr", DllStructGetPtr($p), _ "int", 4096, _ "ptr", 0) $s = DllStructGetData($p, 1) $p = 0 If $DisplayMsgBox <> "" Then MsgBox(0, "_GetLastErrorMessage", $DisplayMsgBox & @CRLF & $s) Return $s EndFunc ;==>_GetLastErrorMessageEDIT: This function probably is not my but I accomodated some scripts from forum or some similar function I don't remember exactly...I used this function only several times to debug some problem API calls.It's very usefull especially after problem DllCall() Edited June 1, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
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