gahhon Posted February 6, 2019 Posted February 6, 2019 _Metro_SplashTextScreen(1, "", $iMsg) AdlibRegister("_Metro_LoopInProgress") DirRemove($DIR_WA_FOLDER, 1) Local $iCopy = _WinAPI_ShellFileOperation($CUR_WA_FOLDER, $DIR_WA_FOLDER, $FO_COPY, BitOr($FOF_SIMPLEPROGRESS, $FOF_NOCONFIRMMKDIR)) AdlibUnRegister("_Metro_LoopInProgress") _Metro_SplashTextScree If @error Then _Metro_MsgBox(0, "", $iCopy) _FileWriteLog($LOG_INSTALLATION, "Error: " & $iCopy) Else _Metro_MsgBox(0, "", "Application is up to date!") _FileWriteLog($LOG_INSTALLATION, "Debug: Application is up to date.") EndIf According to the help file of _WinAPI_ShellFileOperation there are a lot of failure and error code. But how can I handle all of them and display corresponding error message based on the help file? The incident is like this: I'll lock the folder with permission, so when I execute the _WinAPI_ShellFileOperation to copy and overwrite the folder contents, it popped me an error message saying that permission issue to caused I can't access the folder and overwrite the contents. Then I clicked Cancel button, and my AutoIT application exit immediately and it's not execute the function _Metro_MsgBox(0, "", $iCopy) to display the message. Anyway, I did also tried the code below, the it still display "Application is up to date!" According to the help file, 120 - Security settings denied access to the source. If @error = 120 Then _Metro_MsgBox(0, "", $iCopy) _FileWriteLog($LOG_INSTALLATION, "Error: " & $iCopy) Else _Metro_MsgBox(0, "", "Application is up to date!") _FileWriteLog($LOG_INSTALLATION, "Debug: Application is up to date.") EndIf
careca Posted February 6, 2019 Posted February 6, 2019 You could try adding @error to the log, or to a consolewrite to see what number it gives, maybe it's not 120. You could also do something like If $icopy = @error Then Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
gahhon Posted February 6, 2019 Author Posted February 6, 2019 (edited) 9 minutes ago, careca said: You could try adding @error to the log, or to a consolewrite to see what number it gives, maybe it's not 120. You could also do something like If $icopy = @error Then I have no idea why can't use ConsoleWrite because it don't print anything. But I try display it via _Metro_MsgBox and it showed "10" Then I tried If @error = 10 Then display the corresponding error message, but it still jump to "Application is up to date!" Local $iCopy = _WinAPI_ShellFileOperation($CUR_WA_FOLDER, $DIR_WA_FOLDER, $FO_COPY, BitOr($FOF_SIMPLEPROGRESS, $FOF_NOCONFIRMMKDIR)) _Metro_MsgBox(0, "", @error & ' - ' & $iCopy) Edited February 6, 2019 by gahhon
pixelsearch Posted February 6, 2019 Posted February 6, 2019 Hi gahhon, Don't forget that @error is reassigned to 0 each time a new function is encountered (help file, topic SetError) So trying to reuse @error a few lines after it happened often fails. Just keep it in a variable immediately after it occurs or you'll experience this kind of issue : #include <MsgBoxConstants.au3> Local $sFileRead = FileRead("C:\temp\this file name doesn't exist.txt") If @error Then MsgBox($MB_ICONERROR + $MB_TOPMOST, "2nd script", "@error = " & @error) ; displays 1 MsgBox($MB_ICONERROR + $MB_TOPMOST, "2nd script", "@error = " & @error) ; displays 0 Endif gahhon 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
gahhon Posted February 6, 2019 Author Posted February 6, 2019 11 minutes ago, pixelsearch said: Hi gahhon, Don't forget that @error is reassigned to 0 each time a new function is encountered (help file, topic SetError) So trying to reuse @error a few lines after it happened often fails. Just keep it in a variable immediately after it occurs or you'll experience this kind of issue : #include <MsgBoxConstants.au3> Local $sFileRead = FileRead("C:\temp\this file name doesn't exist.txt") If @error Then MsgBox($MB_ICONERROR + $MB_TOPMOST, "2nd script", "@error = " & @error) ; displays 1 MsgBox($MB_ICONERROR + $MB_TOPMOST, "2nd script", "@error = " & @error) ; displays 0 Endif So you are saying that I should store the error code and the error message when after executed the particular function? All right, but I do have one question that error is actually don't declare in the help file, so I don't get any error message from the help file. It is normal? So that I can declare my own error message?
careca Posted February 6, 2019 Posted February 6, 2019 1 hour ago, gahhon said: I have no idea why can't use ConsoleWrite because it don't print anything. Are you using #requireadmin? Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
gahhon Posted February 6, 2019 Author Posted February 6, 2019 Just now, careca said: Are you using #requireadmin? Yeah.
careca Posted February 6, 2019 Posted February 6, 2019 There you go, comment it. gahhon 1 Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
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