Jump to content
Sign in to follow this  
firestrife23

Work if executed as .au3 but not as compiled .exe?

Recommended Posts

firestrife23

I'm having werid issue that I cannot figure out... It work great if I execute the script within SciTE editor... however it doesn't work if I tried to run it from compiled exe file...

This script is meant to run at the root of external HDD to backup important files.

#include <ProgressConstants.au3>

Opt("TrayIconHide", 1)

; This script must be excute at the root of external drive for this to work.
Global $SourceDir = @UserProfileDir, $DestinationDir = @ScriptDir & "Backup\", $OS

Processing()
OSVersion()
If $OS = "Modern" Then
   Backup("AppData")
   Backup("Contacts")
   Backup("Desktop")
   Backup("Documents")
   Backup("Downloads")
   Backup("Favorites")
   Backup("Links")
   Backup("Music")
   Backup("Pictures")
   Backup("Saved Games")
   Backup("Videos")
ElseIf $OS = "Legacy" Then
   Backup("Application Data")
   Backup("Desktop")
   Backup("My Documents")
EndIf
Processed()
Exit

Func Backup($folder)
   If Not FileExists($DestinationDir & @Username) Then
      DirCreate($DestinationDir & @Username)
   EndIf
   _CopyFolder($SourceDir & "\" & $folder, $DestinationDir & @UserName & "\" & $folder, $folder)
EndFunc

Func _CopyFolder($sSourceFolder,$sDestFolder, $foldername)
   DirRemove($sDestFolder,1)
   Local $iSourceSize = DirGetSize($sSourceFolder), $iDestSize
   Local $pid = Run(@AutoItExe & ' /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"')
   Do
      $iDestSize = dirgetsize($sDestFolder)
      Local $ipct = int(($iDestSize/$iSourceSize)*100)
      ProgressSet($ipct,$ipct & '% - Backing up ' & $foldername & "...")
      Sleep(20)
   Until Not ProcessExists($pid)
EndFunc

Func Processing()
   ProgressOn("Copying Progress", "Please Wait...")
EndFunc

Func Processed()
   ProgressOff()
EndFunc

Func OSVersion()
   if @OSVersion = "WIN_XP" Then
      $OS = "Legacy"
   ElseIf @OSVersion = "WIN_XPe" Then
      $OS = "Legacy"
   ElseIf @OSVersion  = "WIN_VISTA" Then
      $OS = "Modern"
   ElseIf @OSVersion = "WIN_7" Then
      $OS = "Modern"
   ElseIf @OSVersion = "WIN_8" Then
      $OS = "Modern"
   ElseIf @OSVersion = "WIN_81" Then
      $OS = "Modern"
   ElseIf @OSVersion = "WIN_2003" Then
      $OS = "Legacy"
   ElseIf @OSVersion = "WIN_2008" Then
      $OS = "Modern"
   ElseIf @OSVersion = "WIN_2008R2" Then
      $OS = "Modern"
   ElseIf @OSVersion = "WIN_2012" Then
      $OS = "Modern"
   ElseIf @OSVersion = "WIN_2012R2" Then
      $OS = "Modern"
   EndIf
   Return $OS
 EndFunc

Share this post


Link to post
Share on other sites
BrewManNH

Where does the problem occur in your script? If it works in SciTE, I'd assume it's probably permissions.


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 Gude
How 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

Share this post


Link to post
Share on other sites
firestrife23

Well I even added #RequireAdmin but the issue persisted. If I run it from SciTE target folders do get copied to destination folder, but as .exe file nothing get copied. So I think it may have something to do with this line:

Local $pid = Run(@AutoItExe & ' /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"')

Share this post


Link to post
Share on other sites
BrewManNH

First off, you need to use the pragma directive #pragma compile(AutoItExecuteAllowed, true) if you're going to use that line.

Secondly, why are you using that line at all? You should execute the DirCopy command IN your script, not as a secondary process. Unless you need to have a dozen or so processes running at the same time of course.


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 Gude
How 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

Share this post


Link to post
Share on other sites
firestrife23

Thank you for quick respond, I'm using that line to create $pid for Do...Until process no longer exist

Share this post


Link to post
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
Sign in to follow this  

×