clarinets101 Posted April 16, 2013 Posted April 16, 2013 Ok, so I'm working on a script to automate a task for my organization, something I've done many times. While writing the script I press "f5" to run and test. All is working well unless I "build/compile" the script into an executable. When I run the executable version the script stops after the copying process. Any help or suggestions? expandcollapse popup#include #include #include #include #include #include #include #include $drive = "" $cursor = mousegetcursor() while $drive = "" $drive = FileSelectFolder("select drive","") $drive2 = stringleft($drive,2) if $drive = "" Then msgbox(0,"Error", "no drive selected") EndIf WEnd $pid = run(@comspec & " /c" & 'format ' & $drive2 & ' /v:BaseDrive /Q /X /FS:NTFS',"",@sw_maximize) sleep(500) send("{enter}") while processexists($pid) WEnd ;~ msgbox(0,"test",@scriptdir) ;~ runwait("xcopy '" &@scriptdir & "\root files\*.*' /z /y /e /d " & $drive) ;~ filecopy(@scriptdir & "\root files\*.*",$drive) _filecopy(@scriptdir & "\root files\*.*",$drive) ;~ 4 Do not display a progress dialog box. ;~ 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists. ;~ 16 Respond with "Yes to All" for any dialog box that is displayed. ;~ 64 Preserve undo information, if possible. ;~ 128 Perform the operation on files only if a wildcard file name (*.*) is specified. ;~ 256 Display a progress dialog box but do not show the file names. ;~ 512 Do not confirm the creation of a new directory if the operation requires one to be created. ;~ 1024 Do not display a user interface if an error occurs. ;~ 2048 Version 4.71. Do not copy the security attributes of the file. ;~ 4096 Only operate in the local directory. Don't operate recursively into subdirectories. ;~ 9182 Version 5.0. Do not copy connected files as a group. Only copy the specified files. Func _fileCopy($fromFile,$tofile) Local $FOF_RESPOND_YES = 16 Local $FOF_SIMPLEPROGRESS = 256 $winShell = ObjCreate("shell.application") $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES) EndFunc dircreate($drive & "TrueCrypt") sleep(1000) _filecopy2(@scriptdir & "\truecrypt\*.*",$drive & "TrueCrypt\") Func _FileCopy2($fromFile2,$tofile2) Local $FOF_RESPOND_YES = 16 Local $FOF_SIMPLEPROGRESS = 256 $winShell = ObjCreate("shell.application") $winShell.namespace($tofile2).CopyHere($fromFile2,$FOF_RESPOND_YES) EndFunc Sleep(1000) Run($drive2 & "\TrueCrypt\TrueCrypt Format.exe", "",@SW_SHOW) winactivate("TrueCrypt","Select &File...") winwaitactive("TrueCrypt","Select &File...") SEND("!c") winactivate("TrueCrypt Volume Creation Wizard") WinWaitActive("TrueCrypt Volume Creation Wizard") send("!n") send("!n") WinWaitActive("TrueCrypt Volume Creation Wizard","Volume Location") $cursor = mousegetcursor() opt("mousecoordmode",0) $posarray = wingetpos("TrueCrypt Volume Creation Wizard","Volume Location") $xcenter = ($posarray[2]/2) $ycenter = ($posarray[3]/2) mousemove($xcenter,$ycenter) while $cursor <> 5 $cursor = mousegetcursor() ;~ sleep(1000) mousemove($xcenter,$ycenter,1) $ycenter -= 10 WEnd mouseclick("left") ;~ send("{esc}") send($drive & "Truecrypt\truecryptvolume") send("!n") send("!n") winwaitactive("TrueCrypt Volume Creation Wizard","Encryption Options") send("!n") send("!m") send("+{tab}") $space = Round(DriveSpaceFree($drive) -16) send($space) send("!n") send("password") send("{tab}") send("password") send("!n") winwaitactive("TrueCrypt Volume Creation Wizard","WARNING:",1) send("!y") $var = 0 while $var < 10 opt("mousecoordmode",0) $posarray = wingetpos("TrueCrypt Volume Creation Wizard","Volume Format") $xcenter = ($posarray[2]/2) $ycenter = ($posarray[3]/2) mousemove($xcenter,$ycenter) if $var < 10 Then mousemove($xcenter,$ycenter-100) $var += 1 EndIf WEnd ;~ sleep(5000) winactivate("TrueCrypt Volume Creation Wizard","Volume Format") send("!f") winwaitactive("TrueCrypt Volume Creation Wizard","The TrueCrypt volume has been successfully created.") send("{enter}") winactivate("TrueCrypt Volume Creation Wizard","Volume Created") send("!{f4}") sleep(1000) winactivate("TrueCrypt","Select &File...") winwaitactive("TrueCrypt","Select &File...") send("!x") filedelete($drive & "\auto encrypt.exe") filedelete($drive & "\encrypt_drive.bat") FileSetAttrib($drive & "\autorun.inf","+sh") filesetattrib($drive & "\truecrypt","+sh")
Moderators JLogan3o13 Posted April 16, 2013 Moderators Posted April 16, 2013 (edited) Take a look at TrayIconDebug in the help file. When enabled, it can give you some information about which line your script is stalling at. Edited April 16, 2013 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
clarinets101 Posted April 16, 2013 Author Posted April 16, 2013 I'll look into that but it's not "stalling" the script just closes out after the first "_filecopy" starts. It get's one file copied and that's it.
clarinets101 Posted April 16, 2013 Author Posted April 16, 2013 I tried the trayicondebug but like i mentioned the script just closes out as well as the tray icon. What's weird is it runs just fine from the script editor it only has issues when ran as an exe.
FireFox Posted April 16, 2013 Posted April 16, 2013 Hi, Debug your script with MessageBoxs (use the Ctrl+Shift+D hotkey in SciTE to check for functions return values), you can also check the @error macro. Br, FireFox.
clarinets101 Posted April 16, 2013 Author Posted April 16, 2013 even if it works before compiling? I guess i don't understand how to use those debugging processes because in the past if it's worked by pressing f5 to test then it's always worked after i've compiled it.
FireFox Posted April 16, 2013 Posted April 16, 2013 even if it works before compiling?Yes that's why I adviced to use MsgBox and not ConsoleWrite.
clarinets101 Posted April 16, 2013 Author Posted April 16, 2013 Ok, well I apologize for my ignorance, exactly how do i use the msgbox for debugging? I click the option from tools but nothing happens.
FireFox Posted April 16, 2013 Posted April 16, 2013 You need to click on the function to debug before firing the option.
clarinets101 Posted April 16, 2013 Author Posted April 16, 2013 ok, i don't know what i'm doing wrong but when i click the option from tools or i press the keys "ctrl+shift+d" nothing happens, is something supposed to?
FireFox Posted April 16, 2013 Posted April 16, 2013 (edited) I don't know why it does not work, it's supposed to add a MsgBox debug line. Do it manually like this : $iSleep = Sleep(500) ;func to debug MsgBox(262144, "Debug line ~" & @ScriptLineNumber, "Selection:" & @lf & "$i = Sleep(500)" & @lf & @lf & "Return: " & @lf & $iSleep & @lf & "Error: " & @error) ;### Debug MSGBOX Br, FireFox. Edited April 16, 2013 by FireFox
BrewManNH Posted April 16, 2013 Posted April 16, 2013 ok, i don't know what i'm doing wrong but when i click the option from tools or i press the keys "ctrl+shift+d" nothing happens, is something supposed to?You need to install the full version of Scite4Autoit3 and have a saved .au3 script in the editor. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
clarinets101 Posted April 16, 2013 Author Posted April 16, 2013 ok, thank you BrewMan installing the "full" version seem to have done the trick allowing me to add the msgbox debug, plus it looks like i've got a lot more options in the script editor. So now i need same assistance with my script. on $winShell.namespace($tofile).copyhere($fromfile,$fof_respond_yes) seems to be where it stops working but i don't get a msgbox after it runs because the script just closes out. Func _fileCopy($fromFile,$tofile) Local $FOF_RESPOND_YES = 16 Local $FOF_SIMPLEPROGRESS = 256 $winShell = ObjCreate("shell.application") MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & ' $winShell' & @lf & @lf & 'Return:' & @lf & $winShell) ;### Debug MSGBOX $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES) MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & ' $winShell.namespace' & @lf & @lf & 'Return:' & @lf & $winShell.namespace) ;### Debug MSGBOX EndFunc if i "F5" the script now the msgbox errors out and if i build it it does the same thing it's been doing where the script just closes out after it starts copying.
BrewManNH Posted April 16, 2013 Posted April 16, 2013 Are you trying to copy a file using this script? Because there are a lot easier ways to do it than using objects. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
clarinets101 Posted April 16, 2013 Author Posted April 16, 2013 I am trying to copy files, but i wanted a progress bar ... i am open to suggestions though.
clarinets101 Posted April 16, 2013 Author Posted April 16, 2013 Ok, I think i've got it figured out. I had a "autorun.inf" file to be copied. for some reason that file was causing the script to end. rename it to something else works just fine. The strange thing is it would work just fine unless ran as an executable. so i guess i'll have it copy it over as a "tmp file" then rename it. and suggestions as to why this "broke" the script?
BrewManNH Posted April 16, 2013 Posted April 16, 2013 There's no progress bar in the script you posted, but you can easily add one. There's a link in my signature that points to a customizable GUI with embedded progress bar and label that would help. expandcollapse popup#include <File.au3> Global $aFileList = _FileListToArray("C:\Windows", "*", 1) ; list of files only Global $sDestinationFoler = "C:\Temp" Global $iCount = $aFileList[0] $aProgressGUI= _ProgressGUI("Copying file # 1 of " & $iCount, 1) For $Loop = 1 to $iCount ;here's where you're copying the files ;FileCopy(""C:\Windows\" & $aFileList[$Loop], $sDestinationFolder) GUICtrlSetData($aProgressGUI[1], Int(($Loop/$iCount)* 100)) ; updates the progress bar GUICtrlSetData($aProgressGUI[2], "Copying file # " & $Loop & " of " & $iCount & @CRLF & "Filename - " & $aFileList[$Loop]) ; updates the label text Sleep(100) ; only used for the demo, not needed in a real script Next ; #FUNCTION# ==================================================================================================================== ; Name...........: _ProgressGui ; Description ...: A small splash screen type GUI with a progress bar and a configurable label ; Syntax.........: _ProgressGUI($s_MsgText = "Text Message", $s_MarqueeType = 0, $i_Fontsize = 14, $s_Font = "Arial", $i_XSize = 290, $i_YSize = 100, $b_GUIColor = -1, $b_FontColor = -1) ; Parameters ....: $s_MsgText - Text to display on the GUI ; $s_MarqueeType - [optional] Style of Progress Bar you want to use ; 0 = Marquee style [default] ; 1 = Normal Progress Bar style ; $i_Fontsize - [optional] The font size that you want to display the $s_MsgText at [default = 14] ; $s_Font - [optional] The font you want the message to use [default = "Arial"] ; $i_XSize - [optional] Width of the GUI [Default = 290] - Minimum size is 80 ; $i_YSize - [optional] Height of the GUI [Default = 100] - Minimum size is 100 ; $b_GUIColor - [optional] Background color of the GUI [default = 0x00080FF = Blue] ; $s_FontColor - [optional] Color of the text message [default = 0x0FFFC19 = Yellow] ; Return values .: Success - An array containing the following information ; $Array[0] - ControlID of the GUI created ; $Array[1] - ControlID of the ProgressBar control ; $Array[2] - ControlID of the label ; Failure - 0 and @error to 1 if the GUI couldn't be created ; ; Author ........: Bob Marotte (BrewManNH) ; Remarks .......: This will create a customizable GUI with a progress bar. The default style of the progress bar using this function is the ; Marquee style of progress bar. If you call this function with any positive, non-zero number in the $s_MarqueeType ; parameter it will use the normal progress bar style. All optional parameters will accept the "Default" keyword, an empty ; string "", or -1 if passed to the function. Use the return value to delete the GUI when you're done using it ; (ex. GUIDelete($Returnvalue[0])) ; Related .......: None ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _ProgressGUI($s_MsgText = "Text Message", $s_MarqueeType = 0, $i_Fontsize = 14, $s_Font = "Arial", $i_XSize = 290, $i_YSize = 100, $b_GUIColor = -1, $b_FontColor = -1) Local $PBMarquee[3] ;~ UDF Constants so no includes are needed Local Const $PG_WS_POPUP = 0x80000000 ; same as the $WS_POPUP constant in WindowsConstants.au3 Local Const $PG_WS_DLGFRAME = 0x00400000 ; same as the $WS_DLGFRAME constant in WindowsConstants.au3 Local Const $PG_PBS_MARQSMTH = 9 ; BitOr of $PBS_SMOOTH and $PBS_MARQUEE Local Const $PG_PBS_SMTH = 1 ; same as the $PBS_SMOOTH constant in ProgressConstants.au3 Local Const $PG_PBM_SETMARQUEE = 1034 ; same as the $PBM_SETMARQUEE constant in ProgressConstants.au3 ; bounds checking/correcting If $i_Fontsize = "" Or $i_Fontsize = Default Or $i_Fontsize = "-1" Then $i_Fontsize = 14 ; use the default setting of 14 for font size If $i_Fontsize < 1 Then $i_Fontsize = 1 ; minimum font size is 1 If $i_XSize = "" Or $i_XSize = "-1" Or $i_XSize = Default Then $i_XSize = 290 ; use the default setting for X dimension of the GUI If $i_XSize < 80 Then $i_XSize = 80 ; minimum X dimension is 80 If $i_XSize > @DesktopWidth - 50 Then $i_XSize = @DesktopWidth - 50 ; maximum X dimension is Desktop Width - 50 If $i_YSize = "" Or $i_YSize = "-1" Or $i_YSize = Default Then $i_YSize = 100 ; use the default setting for Y dimension of the GUI If $i_YSize > @DesktopHeight - 50 Then $i_YSize = @DesktopHeight - 50 ; maximum y dimension is Desktop Height - 50 If $i_YSize < 100 Then $i_YSize = 100 ; minimum Y dimension is 100 If $s_Font = "" Or $s_Font = "-1" Or $s_Font = "Default" Then $s_Font = "Arial" ; use the default font type ;create the GUI $PBMarquee[0] = GUICreate("", $i_XSize, $i_YSize, -1, -1, BitOR($PG_WS_DLGFRAME, $PG_WS_POPUP)) If @error Then Return SetError(@error, 0, 0) ; if there's any error with creating the GUI, return the error code Switch $b_GUIColor ; background color of the GUI Case "-1", Default; Used to set the default color GUISetBkColor(0x00080FF, $PBMarquee[0]) Case "" ; don't set a default color, use the theme's coloring Case Else ; set the BG color of the GUI to the user provided color GUISetBkColor($b_GUIColor, $PBMarquee[0]) EndSwitch ; Create the progressbar If $s_MarqueeType < 1 Then ; if $s_MarqueeType < 1 then use the Marquee style progress bar $PBMarquee[1] = GUICtrlCreateProgress(20, $i_YSize - 20, $i_XSize - 40, 15, $PG_PBS_MARQSMTH) ; uses the $PBS_SMOOTH and $PBS_MARQUEE style GUICtrlSendMsg($PBMarquee[1], $PG_PBM_SETMARQUEE, True, 20) ; change last parameter to change update speed of marquee style PB Else ; If $s_MarqueeType > 0 then use the normal style progress bar $PBMarquee[1] = GUICtrlCreateProgress(20, $i_YSize - 20, $i_XSize - 40, 15, $PG_PBS_SMTH) ; Use the $PBS_SMOOTH style EndIf ; Create the label $PBMarquee[2] = GUICtrlCreateLabel($s_MsgText, 20, 20, $i_XSize - 40, $i_YSize - 45) ; create the label for the GUI GUICtrlSetFont($PBMarquee[2], $i_Fontsize, 400, Default, $s_Font) Switch $b_FontColor Case "-1", Default; Used to set the default color of the label GUICtrlSetColor($PBMarquee[2], 0x0FFFC19) Case "" ; don't set a default color, use the theme's coloring Case Else GUICtrlSetColor($PBMarquee[2], $b_FontColor) EndSwitch GUISetState() Return SetError(0, 0, $PBMarquee) ;Return an array containing the ControlIDs of the GUI, Progress bar, and the Label (in that order) EndFunc ;==>_ProgressGUI Here's a quick demo that shows one way to do it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
clarinets101 Posted April 16, 2013 Author Posted April 16, 2013 _filecopy(@scriptdir & "\truecrypt\*.*",$drive & "TrueCrypt\") Func _FileCopy($fromFile,$tofile) Local $FOF_RESPOND_YES = 16 Local $FOF_SIMPLEPROGRESS = 256 $winShell = ObjCreate("shell.application") $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES) EndFunc I'll take a look at your script but this is a snipit from mine... basically it opens the windows file copy dialogue. and like i mentioned it works great if i don't have that autorun.inf file in the directory. and i just tried a filemove to rename the file but same thing the script closes out. autoit just does not like autorun.inf files it looks like.
BrewManNH Posted April 16, 2013 Posted April 16, 2013 AutoIt isn't being used to do the file copy, Windows is. You're using an Windows shell object to copy the file, AutoIt is only giving you access to it. Use FileCopy and get out of the VBScript mindset. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
clarinets101 Posted April 16, 2013 Author Posted April 16, 2013 even with filecopy it's still killing the script. I don't know why but i can use filecopy just fine without the autorun.inf file in the directory that i am copying the files from... but if there is a file in there named autorun.inf it kills the script, but not if i use f5 out of script editor. I don't understand this doesn't make sense.
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