creamers Posted August 12, 2013 Share Posted August 12, 2013 (edited) So I have a variable $Driveletter and I have a file ./includes/tc/tc.exe.What I need to do is run ./includes/tc/tcc.exe ./include/scripts/ownership.bat $DriveletterI may need to run it as a relative path to tcc.exe which is easy to do but the biggest problem I have is running the script with the $Driveletter variable.expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=test.exe #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Process.au3> #include <GuiButton.au3> #include <GuiToolBar.au3> #include "./scripts/_IsUACAdmin.au3" $g = GUICreate("Are we UAC", 200, 100) $b = GUICtrlCreateButton("Elevate", 200-72, 100-27, 70, 25) $Submit = GUICtrlCreateButton("Continue", 56, 100-27, 70, 25) _GUICtrlButton_SetShield($ B) $admin = _IsUACAdmin() $canelevate = @extended GUICtrlCreateLabel("IsAdmin (built-in): " & (IsAdmin() = 1), 4, 4) GUICtrlCreateLabel("_IsUACAdmin (full admin): " & ($admin = 1), 4, 24) GUICtrlCreateLabel("Process can elevate: " & ($canelevate = 1), 4, 44) If $admin Or (Not $canelevate) Then GUICtrlSetState($b, $GUI_DISABLE) GUISetState() #Region ### START Koda GUI section ### Form=c:\users\wesley\desktop\backup script\koda\main interface.kxf $Form1_1 = GUICreate("Automated Backup Script", 598, 421, 192, 124) $Pic1 = GUICtrlCreatePic("./images/harddisk.jpg", 0, 0, 612, 468) GUICtrlSetState(-1, $GUI_DISABLE) $Label1 = GUICtrlCreateLabel("Computer Works Automated Backup", 0, 0, 391, 33) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) $viewerlogs = GUICtrlCreateButton("Log File", 520, 0, 75, 25) $deletelogs = GUICtrlCreateButton("Delete Log", 420, 0, 95, 25) $Script = GUICtrlCreateProgress(376, 296, 150, 17) $ownership = GUICtrlCreateButton("Step 1: Ownership", 8, 136, 115, 25) $permissions = GUICtrlCreateButton("Step 2: Permissions", 8, 168, 115, 25) $symlinks = GUICtrlCreateButton("Step 3: Symlinks", 8, 200, 115, 25) $backupmove = GUICtrlCreateButton("Step 4: Backup Move", 8, 232, 115, 25) $backupcopy = GUICtrlCreateButton("Step 4: Backup Copy", 8, 264, 115, 25) $Customer = GUICtrlCreateInput("Customer", 224, 216, 129, 21) $Technician = GUICtrlCreateInput("Technician", 224, 240, 70, 21) $Driveletter = GUICtrlCreateInput("DriveLetter", 224, 264, 60, 21) Dim $Form1_1_AccelTable[3][2] = [["^p", $permissions],["^!s", $symlinks],["^b", $backupmove]] GUISetAccelerators($Form1_1_AccelTable) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case -3 ExitLoop Case $b ; restart elevated If @Compiled Then ShellExecute(@ScriptFullPath, "", @WorkingDir, "runas") Else ShellExecute(@AutoItExe, '/AutoIt3ExecuteScript "' & @ScriptFullPath & '"', @WorkingDir, "runas") EndIf Exit EndSwitch $msg=GUIGetMsg() if $msg=-3 Then Exit if $msg=$viewerlogs then viewerlogs() if $msg=$ownership then ownership() if $msg=$deletelogs then deletelogs() WEnd # ;****This wil open tail to view the logfile. **** Func viewerlogs() if FileExists("./log.txt") then ;****Checks to see if the log file exists**** Run ("./includes/tail.exe -f log.txt") ;****Runs tail.exe if the log file was found to view the log file**** Else MsgBox(0,"Error", "There is no log file") ;****if There is no log file displays "There is not log file*** EndIf EndFunc # ;****This will delete the logfile. **** Func deletelogs() If FileExists("./log.txt") then ;****Checks to see if the log files exists***** FileDelete("log.txt") ;****If the log file exits then it will attempt to delete it**** If FileExists("./log.txt") then ;****Now we check to see if the file was actualy deleted**** MsgBox (0,"Oops", "Something went wrong") ;****If the file stil exists then display "Something went wrong" Else MsgBox(0,"File Deleted","Log File Removed Successfully") ;****If the file does not exist then it was successfully and displays "Removed successfully"**** EndIf Else MsgBox(0,"Error", "There is no log file") ;****If there there was not log file originally displays "There is not log file"***** EndIf EndFunc # ;****This will take ownership of the $driveleter drive. **** Func ownership() run("./includes/tc/tcc.exe cls") EndFunc # ;****This will take ownership of the $driveleter drive. **** Func ownership() ;****run("./includes/tc/tcc.exe cls") Run("@ComSpec & " /c " & "./includes/tc/tcc.exe " & $driveletter &"") EndFunc Edited August 12, 2013 by creamers Link to comment Share on other sites More sharing options...
BrewManNH Posted August 12, 2013 Share Posted August 12, 2013 (edited) If the files are relative to the script's directory, I'd use @ScriptDir instead of hoping the working directory is set correctly. Second, I'd use backslashes for the file paths because I'm not sure which Windows commands will accept a forward slash instead of using the correct character. I know that some, probably most, will but why take chances by writing them wrong to start with.  BTW, you have two functions named ownership in your script Edited August 12, 2013 by BrewManNH 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 Link to comment Share on other sites More sharing options...
creamers Posted August 12, 2013 Author Share Posted August 12, 2013 (edited) If the files are relative to the script's directory, I'd use @ScriptDir instead of hoping the working directory is set correctly. Second, I'd use backslashes for the file paths because I'm not sure which Windows commands will accept a forward slash instead of using the correct character. I know that some, probably most, will but why take chances by writing them wrong to start with.  BTW, you have two functions named ownership in your scriptI am having trouble implementing that.Can you point me with a sample code that would do this?I dont think @scriptdir is exactly what I am looking for either since I am not needing to know the working directory.start .includestctcc.exe .ownership.bat $DriveLetterThat would be the simplist form I can think of though I am still having massive trouble defining everything. I can launch tcc.exe but can not get it to run ownership.bat at the very least. It comes up and says ownership.bat20 not found using the code.Run(@ComSpec & " /c start ./includes/tc/tcc.exe ownership.bat" & $Driveletter, '' , @SW_HIDE) Edited August 12, 2013 by creamers Link to comment Share on other sites More sharing options...
MHz Posted August 12, 2013 Share Posted August 12, 2013 $Driveletter is a Control ID number which is 20 for your script. Use GuiCtrlRead to read from the ID. Ensure a space after bat as well. Run('"' & @ComSpec & '" /c start ./includes/tc/tcc.exe ownership.bat ' & GUICtrlRead($Driveletter), '' , @SW_HIDE) Link to comment Share on other sites More sharing options...
kylomas Posted August 12, 2013 Share Posted August 12, 2013 (edited) creamers, Also, this _GUICtrlButton_SetShield($ B) Should probably be this _GUICtrlButton_SetShield($b) And this Run("@ComSpec & " / c " & " . / includes / tc / tcc.exe " & $driveletter &"") Is using the input controlid variable $driveletter wrong. It should probably be something like Run(@ComSpec & " / c " & " . / includes / tc / tcc.exe " & guictrlread($driveletter) & "") kylomas edit: MHz got in before me... Edited August 12, 2013 by kylomas Forum Rules        Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
creamers Posted August 12, 2013 Author Share Posted August 12, 2013 All of you all helped dramatically! thank youThough my code is real dirty now# ;****This will take ownership of the $driveleter drive. **** Func ownership() ;**** All this below commented is useless code that I was experimenting with ;****run("./includes/tc/tcc.exe cls") ;****Run("@ComSpec & " /c " & "./includes/tc/tcc.exe " & $driveletter &"") ;****Run(@ComSpec & " /c start ./includes/tc/tcc.exe ownership.bat" & $Driveletter, '' , @SW_HIDE) ;****Run(@ComSpec & " /c " & '"\includes\tc\tcc.exe" '& $Driveletter &',' @SW_HIDE) RunWait(takeownership()) EndFunc Func Permissions() Run(takepermissions()) EndFunc Func Symlinks() takesym() EndFunc ;**** each script just has a copy of the previous script and it is linked into a new function using the declared vairables $Driveleter through GUICTRLRead($Driveletter) Func takeownership() Run('"' & @ComSpec & '" /c start ./includes/tc/tcc.exe ownership.bat ' & GUICtrlRead($Driveletter), '' , @SW_HIDE) EndFunc Func takepermissions() Run('"' & @ComSpec & '" /c start ./includes/tc/tcc.exe permissions.bat ' & GUICtrlRead($Driveletter), '' , @SW_HIDE) EndFunc Func takesym() Run('"' & @ComSpec & '" /c start ./includes/tc/tcc.exe symlinks.bat ' & GUICtrlRead($Driveletter), '' , @SW_HIDE) EndFuncI ended up adding all the functions to each bat file though what I would like to do istakeownership() takepermissions() takesym()though If I run it like that or with runwait it never executes take permissions. I need them to progress in order.I have it working in a crude way like I mentioned earlier. Link to comment Share on other sites More sharing options...
Solution MHz Posted August 12, 2013 Solution Share Posted August 12, 2013 takeownership() takepermissions() takesym() Though this is how you call functions. You do not Run() them but rather call them. So you seem to do something correct and then you do something quite odd in other places in your script. This makes it difficult to clean up your code as it is not quite finished? We can only try though with with what seems like a strong *nix style and the use of tcc.exe for this. You could possibly run tcc.exe as you described in your 1st post. It is like a 4DOS interpreter so I would expect it to run on its own without needing @ComSpec to assist. Now I have considered that you can do it with the concerned actions listed in 1 function. It is perhaps not so cool as it runs tcc.exe 3 times though it may be good enough for your GUI application. ; any of these or all of them _Take('own', GUICtrlRead($Driveletter)) _Take('permissions', GUICtrlRead($Driveletter)) _Take('symlinks', GUICtrlRead($Driveletter)) ; or _Take('all', GUICtrlRead($Driveletter)) Func _Take($action, $driveletter) Switch $action Case 'own', 'all' RunWait('./includes/tc/tcc.exe ownership.bat ' & $driveletter, '', @SW_HIDE) If $action = 'all' Then ContinueCase Case 'permissions' RunWait('./includes/tc/tcc.exe permissions.bat ' & $driveletter, '' , @SW_HIDE) If $action = 'all' Then ContinueCase Case 'symlinks' RunWait('./includes/tc/tcc.exe symlinks.bat ' & $driveletter, '' , @SW_HIDE) Case Else Return SetError(1, 0, 0) EndSwitch EndFunc Getting rid of @ComSpec and the use of Start helps RunWait to not return until tcc.exe has finished in each instance. I do not use tcc.exe to know its behavior so some presumption exists that this may work. Link to comment Share on other sites More sharing options...
JCEF Posted August 13, 2013 Share Posted August 13, 2013 Good night! First of all I apologize for bad English. I'm Portuguese and I never had training in English. This is my first post. I do not have extensive knowledge in AutoIt3, but I take the risk and leave you this idea: - Why not create the file ".bat" during the execution of the program? So no need to pass parameters to the batch file, because these are already there embedded. Example: expandcollapse popupLocal $driveletter = "c:" Local $driveletter2 = "d:" MakeBat($driveletter) RunWait(@TempDir & "\ownership.bat") MakeBat2($driveletter, $driveletter2) RunWait(@TempDir & "\ownership.bat") Func MakeBat($driveletter) Local $BatFile = @TempDir & "\ownership.bat" Local $BatFileText If FileExists($BatFile) Then FileDelete($BatFile) $BatFileText = 'Echo Now executing ' & $BatFile & @CRLF _ & 'Dir ' & $driveletter & @CRLF _ & 'Echo End of ' & $BatFile & @CRLF _ & 'Pause' & @CRLF _ & ':loop' & @CRLF _ & 'del /F /Q "' & $BatFile & @CRLF _ & 'if exist "' & $BatFile & '" goto loop' FileWrite($BatFile, $BatFileText) EndFunc ;==>MakeBat Func MakeBat2($driveletter, $driveletter2) Local $BatFile = @TempDir & "\ownership.bat" Local $BatFileText If FileExists($BatFile) Then FileDelete($BatFile) $BatFileText = 'Echo Now executing ' & $BatFile & @CRLF _ & 'Dir ' & $driveletter & @CRLF _ & 'Pause' & @CRLF _ & 'Dir ' & $driveletter2 & @CRLF _ & 'Echo End of ' & $BatFile & @CRLF _ & 'Pause' & @CRLF _ & ':loop' & @CRLF _ & 'del /F /Q "' & $BatFile & @CRLF _ & 'if exist "' & $BatFile & '" goto loop' FileWrite($BatFile, $BatFileText) EndFunc ;==>MakeBat2 Link to comment Share on other sites More sharing options...
JCEF Posted August 13, 2013 Share Posted August 13, 2013 Sorry but had errors on lines 27 and 43. This is correct code: expandcollapse popupLocal $driveletter = "c:" Local $driveletter2 = "d:" MakeBat($driveletter) RunWait(@TempDir & "\ownership.bat") MakeBat2($driveletter, $driveletter2) RunWait(@TempDir & "\ownership.bat") Func MakeBat($driveletter) Local $BatFile = @TempDir & "\ownership.bat" Local $BatFileText If FileExists($BatFile) Then FileDelete($BatFile) $BatFileText = 'Echo Now executing ' & $BatFile & @CRLF _ & 'Dir ' & $driveletter & @CRLF _ & 'Echo End of ' & $BatFile & @CRLF _ & 'Pause' & @CRLF _ & ':loop' & @CRLF _ & 'del /F /Q "' & $BatFile & '"' & @CRLF _ & 'if exist "' & $BatFile & '" goto loop' FileWrite($BatFile, $BatFileText) EndFunc ;==>MakeBat Func MakeBat2($driveletter, $driveletter2) Local $BatFile = @TempDir & "\ownership.bat" Local $BatFileText If FileExists($BatFile) Then FileDelete($BatFile) $BatFileText = 'Echo Now executing ' & $BatFile & @CRLF _ & 'Dir ' & $driveletter & @CRLF _ & 'Pause' & @CRLF _ & 'Dir ' & $driveletter2 & @CRLF _ & 'Echo End of ' & $BatFile & @CRLF _ & 'Pause' & @CRLF _ & ':loop' & @CRLF _ & 'del /F /Q "' & $BatFile & '"' & @CRLF _ & 'if exist "' & $BatFile & '" goto loop' FileWrite($BatFile, $BatFileText) EndFunc ;==>MakeBat2 Link to comment Share on other sites More sharing options...
creamers Posted August 14, 2013 Author Share Posted August 14, 2013 Good night!First of all I apologize for bad English. I'm Portuguese and I never had training in English.This is my first post.I do not have extensive knowledge in AutoIt3, but I take the risk and leave you this idea:- Why not create the file ".bat" during the execution of the program? So no need to pass parameters to the batch file, because these are already there embedded.Example:expandcollapse popupLocal $driveletter = "c:" Local $driveletter2 = "d:" MakeBat($driveletter) RunWait(@TempDir & "\ownership.bat") MakeBat2($driveletter, $driveletter2) RunWait(@TempDir & "\ownership.bat") Func MakeBat($driveletter) Local $BatFile = @TempDir & "\ownership.bat" Local $BatFileText If FileExists($BatFile) Then FileDelete($BatFile) $BatFileText = 'Echo Now executing ' & $BatFile & @CRLF _ & 'Dir ' & $driveletter & @CRLF _ & 'Echo End of ' & $BatFile & @CRLF _ & 'Pause' & @CRLF _ & ':loop' & @CRLF _ & 'del /F /Q "' & $BatFile & @CRLF _ & 'if exist "' & $BatFile & '" goto loop' FileWrite($BatFile, $BatFileText) EndFunc ;==>MakeBat Func MakeBat2($driveletter, $driveletter2) Local $BatFile = @TempDir & "\ownership.bat" Local $BatFileText If FileExists($BatFile) Then FileDelete($BatFile) $BatFileText = 'Echo Now executing ' & $BatFile & @CRLF _ & 'Dir ' & $driveletter & @CRLF _ & 'Pause' & @CRLF _ & 'Dir ' & $driveletter2 & @CRLF _ & 'Echo End of ' & $BatFile & @CRLF _ & 'Pause' & @CRLF _ & ':loop' & @CRLF _ & 'del /F /Q "' & $BatFile & @CRLF _ & 'if exist "' & $BatFile & '" goto loop' FileWrite($BatFile, $BatFileText) EndFunc ;==>MakeBat2 This was something that was thrown around in the air and was decided against due to the amount of temp files and then I would have to trigger a delete command to clear the function. It will be used on about 6 machines each machine being used 2-3 days. Preferably off a unc share so at a max it would be 18 files created in a day and each machine will have the same drive letters attached. Thank you very much though. Also your english was perfect for me.  Though this is how you call functions. You do not Run() them but rather call them. So you seem to do something correct and then you do something quite odd in other places in your script. This makes it difficult to clean up your code as it is not quite finished? We can only try though with with what seems like a strong *nix style and the use of tcc.exe for this. You could possibly run tcc.exe as you described in your 1st post. It is like a 4DOS interpreter so I would expect it to run on its own without needing @ComSpec to assist. Now I have considered that you can do it with the concerned actions listed in 1 function. It is perhaps not so cool as it runs tcc.exe 3 times though it may be good enough for your GUI application.; any of these or all of them _Take('own', GUICtrlRead($Driveletter)) _Take('permissions', GUICtrlRead($Driveletter)) _Take('symlinks', GUICtrlRead($Driveletter)) ; or _Take('all', GUICtrlRead($Driveletter)) Func _Take($action, $driveletter) Switch $action Case 'own', 'all' RunWait('./includes/tc/tcc.exe ownership.bat ' & $driveletter, '', @SW_HIDE) If $action = 'all' Then ContinueCase Case 'permissions' RunWait('./includes/tc/tcc.exe permissions.bat ' & $driveletter, '' , @SW_HIDE) If $action = 'all' Then ContinueCase Case 'symlinks' RunWait('./includes/tc/tcc.exe symlinks.bat ' & $driveletter, '' , @SW_HIDE) Case Else Return SetError(1, 0, 0) EndSwitch EndFuncGetting rid of @ComSpec and the use of Start helps RunWait to not return until tcc.exe has finished in each instance. I do not use tcc.exe to know its behavior so some presumption exists that this may work.I will be integrating this for sure. Infact I already did and it is much cleaner thank you!. The only issue I found was thisFunc Permissions() _Take('own', GUICtrlRead($driveletter)) _Take('permissions', GUICtrlRead($driveletter)) EndFunc ;==>PermissionsI trigger two takes, I tried modifiying the case and have since then trashed the code .Also for the record tcc.exe is Take Command a command line replacement with extra functions! Link to comment Share on other sites More sharing options...
MHz Posted August 14, 2013 Share Posted August 14, 2013 Â Func Permissions() _Take('own', GUICtrlRead($driveletter)) _Take('permissions', GUICtrlRead($driveletter)) EndFunc ;==>Permissions This will call _Take() twice as it is 2 function calls. So ownership.bat and permissions.bat will be run. You could perhaps send more then 1 parameter to the bat file and do it in a single instance. CMD supports "command1 & command2" in one line though I am not sure if tcc.exe does as well. I did see the mention of & in the online help for tcc.exe on the page about Multiple commands. It looks like you can use /C to invoke a command line using tcc.exe. This is where I got the basic information of tcc.exe. If & can be used then you could try this. Just builds the string complete and then passes it to RunWait(). ; any of these _Take('-own', GUICtrlRead($Driveletter)) _Take('-permissions', GUICtrlRead($Driveletter)) _Take('-symlinks', GUICtrlRead($Driveletter)) ; or many on one line. Whitespace is of no concern for this _Take('-own-permissions -symlinks', GUICtrlRead($Driveletter)) Func _Take($action, $driveletter) Local $string If StringInStr($action, '-own') Then If $string Then $string &= ' &' $string &= ' ownership.bat ' & $driveletter EndIf If StringInStr($action, '-permissions') Then If $string Then $string &= ' &' $string &= ' permissions.bat ' & $driveletter EndIf If StringInStr($action, '-symlinks') Then If $string Then $string &= ' &' $string &= ' symlinks.bat ' & $driveletter EndIf If Not $string Then Return SetError(1, 0, 0) RunWait('./includes/tc/tcc.exe /c ' & $string, '', @SW_HIDE) EndFunc The script you posted does not match what you want, e.g. no all of own, permissions and symlinks together so I am still unsure how complete it. Perhaps if you can sort what buttons needed, test what works etc then I may be able to help with your code to do this. Link to comment Share on other sites More sharing options...
MHz Posted August 14, 2013 Share Posted August 14, 2013 creamers, I did a hack with your code. I have not tested the tcc.exe stuff etc., just starting the GUI. See if it works for you. The modification etc can be done and hopefully something to build on. You may notice that I set ownership button to "-own", set permissions button to "-own -permissions" and set symlinks button to "-symlinks". expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=test.exe #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Process.au3> #include <GuiButton.au3> #include <GuiToolBar.au3> #include "./scripts/_IsUACAdmin.au3" ; if no command line switch was used then do this block of code If Not $CMDLINE[0] Then $g = GUICreate("Are we UAC", 200, 100) $b = GUICtrlCreateButton("Elevate", 200-72, 100-27, 70, 25) $Submit = GUICtrlCreateButton("Continue", 56, 100-27, 70, 25) _GUICtrlButton_SetShield($B) $admin = _IsUACAdmin() $canelevate = @extended GUICtrlCreateLabel("IsAdmin (built-in): " & (IsAdmin() = 1), 4, 4) GUICtrlCreateLabel("_IsUACAdmin (full admin): " & ($admin = 1), 4, 24) GUICtrlCreateLabel("Process can elevate: " & ($canelevate = 1), 4, 44) If $admin Or (Not $canelevate) Then GUICtrlSetState($b, $GUI_DISABLE) GUISetState() ; While 1 Switch GUIGetMsg() Case -3 Exit Case $Submit GUIDelete() ExitLoop Case $b ; restart elevated with /restart switch (parameter) ShellExecute('"' & @AutoItExe & '"', '/AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart', '', "runas") Exit EndSwitch WEnd EndIf #Region ### START Koda GUI section ### Form=c:\users\wesley\desktop\backup script\koda\main interface.kxf $Form1_1 = GUICreate("Automated Backup Script", 598, 421, 192, 124) $Pic1 = GUICtrlCreatePic("./images/harddisk.jpg", 0, 0, 612, 468) GUICtrlSetState(-1, $GUI_DISABLE) $Label1 = GUICtrlCreateLabel("Computer Works Automated Backup", 0, 0, 391, 33) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) $viewerlogs = GUICtrlCreateButton("Log File", 520, 0, 75, 25) $deletelogs = GUICtrlCreateButton("Delete Log", 420, 0, 95, 25) $Script = GUICtrlCreateProgress(376, 296, 150, 17) $ownership = GUICtrlCreateButton("Step 1: Ownership", 8, 136, 115, 25) $permissions = GUICtrlCreateButton("Step 2: Permissions", 8, 168, 115, 25) $symlinks = GUICtrlCreateButton("Step 3: Symlinks", 8, 200, 115, 25) $backupmove = GUICtrlCreateButton("Step 4: Backup Move", 8, 232, 115, 25) $backupcopy = GUICtrlCreateButton("Step 4: Backup Copy", 8, 264, 115, 25) $Customer = GUICtrlCreateInput("Customer", 224, 216, 129, 21) $Technician = GUICtrlCreateInput("Technician", 224, 240, 70, 21) $Driveletter = GUICtrlCreateInput("DriveLetter", 224, 264, 60, 21) Dim $Form1_1_AccelTable[3][2] = [["^p", $permissions],["^!s", $symlinks],["^b", $backupmove]] GUISetAccelerators($Form1_1_AccelTable) GUISetState() #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case -3 ExitLoop Case $viewerlogs _Viewerlogs() Case $deletelogs _Deletelogs() Case $ownership $exitcode = _Take('-own', GUICtrlRead($Driveletter)) ; tcc.exe runs ownership.bat If @error Or Not $exitcode Then MsgBox(0x30, 'Error', 'Ownership failed', 0, $Form1_1) Case $permissions $exitcode = _Take('-own -permissions', GUICtrlRead($Driveletter)) ; tcc.exe runs ownership.bat and permissions.bat If @error Or Not $exitcode Then MsgBox(0x30, 'Error', 'Permissions failed') Case $symlinks $exitcode = _Take('-symlinks', GUICtrlRead($Driveletter)) ; tcc.exe runs symlinks.bat If @error Or Not $exitcode Then MsgBox(0x30, 'Error', 'Symlinks failed', 0, $Form1_1) EndSwitch WEnd # ;****This wil open tail to view the logfile. **** Func _ViewerLogs() if FileExists("./log.txt") then ;****Checks to see if the log file exists**** Run ("./includes/tail.exe -f log.txt") ;****Runs tail.exe if the log file was found to view the log file**** Else MsgBox(0x30,"Error", "There is no log file") ;****if There is no log file displays "There is not log file*** EndIf EndFunc # ;****This will delete the logfile. **** Func _Deletelogs() If FileExists("./log.txt") then ;****Checks to see if the log files exists***** FileDelete("./log.txt") ;****If the log file exits then it will attempt to delete it**** If FileExists("./log.txt") then ;****Now we check to see if the file was actualy deleted**** MsgBox (0x30,"Oops", "Something went wrong") ;****If the file stil exists then display "Something went wrong" Else MsgBox(0,"File Deleted", "Log File Removed Successfully") ;****If the file does not exist then it was successfully and displays "Removed successfully"**** EndIf Else MsgBox(0,"Error", "There is no log file") ;****If there there was not log file originally displays "There is not log file"***** EndIf EndFunc # ;****This takes ownership, permissions and does symlinks Func _Take($action, $driveletter) Local $string ; if -own is a substring of $action then add to $string If StringInStr($action, '-own') Then ; if $string is something then add an & (and) to it If $string Then $string &= ' &' ; add bat file to the string $string &= ' ownership.bat ' & $driveletter EndIf If StringInStr($action, '-permissions') Then If $string Then $string &= ' &' $string &= ' permissions.bat ' & $driveletter EndIf If StringInStr($action, '-symlinks') Then If $string Then $string &= ' &' $string &= ' symlinks.bat ' & $driveletter EndIf ; if $string is an empty string then set @error to 1 and return 0 If $string == '' Then Return SetError(1, 0, 0) ; run the command string and return the exit code Return RunWait('./includes/tc/tcc.exe /c ' & $string, '', @SW_HIDE) EndFunc 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