mortog Posted July 28, 2011 Share Posted July 28, 2011 Hey folks, I'm trying to create a file copy tool which will manually copy files (because dircopy and such doesn't work due to network restrictions). However I'm trying to make sure that steps won't continue until windows are active, but for some reason it doesn't seem to work. Could anyone shed some light on what I'm doing wrong? Thanks in advance! Here's an extract of what I'm working on. expandcollapse popupWhile 1 $msg = GUIGetMsg() If $msg = $XIcon[1] Then Exit If $msg = $XIcon[2] Then GUISetState(@SW_MINIMIZE) If $msg = $Exit Then Exit If $msg = $Ok Then Ping(GUICtrlRead ($Input1), 2500) If @error = 0 Then $Lang_dll = DllOpen("kernel32.dll") $UserIntLang=DllCall ( $Lang_dll, "int", "GetUserDefaultUILanguage" ) If @error=0 Then $UserIntLang=Hex($UserIntLang[0],4) Else $UserIntLang="UNKNOWN" EndIf DllClose($Lang_dll) ; the language piece is kind of obsolete now, just left it there as a just in case precaution Sleep(1000) Run("c:\Migration\Error.exe") ; see below for the code of this .exe Sleep(1000) Send("#m") Sleep(2000) Send("#r") Sleep(1000) WinActive(StringInStr(WinGetTitle("[active]"), "Run" or "Exécuter")) Sleep(1000) Send("\\" & GUICtrlRead($Input1) & "\c$") Sleep(1500) Send("{Enter}") Sleep(1000) WinActive ("Connect to " & GUICtrlRead($Input1)) Sleep(1000) Send(GUICtrlRead($Input1) & "\i400550") Sleep(1000) Send("{tab}") Sleep(1000) Send("asdf1234") Sleep(1000) Send("{enter}") Sleep(1000) WinActive(StringInStr(WinGetTitle("[active]"), "c$")) Sleep(1000) Send("!+{F4}") Sleep(5000) Send("#m") Sleep(2000) Send("#r") Sleep(1000) WinActive(StringInStr(WinGetTitle("[active]"), "Run" or "Exécuter")) Sleep(1000) Send(@MyDocumentsDir) Sleep(1000) Send("{Enter}") Sleep(1000) WinActive(StringInStr(WinGetTitle("[active]"), "My Documents" or "Mes Documents")) Sleep(1000) Send("{Right}") Sleep(1000) Send("^a") Sleep(2000) Send("^c") Sleep(2000) Send("!+{F4}") Sleep(5000) Send("#r") Sleep(1000) WinActive(StringInStr(WinGetTitle("[active]"), "Run" or "Exécuter")) Sleep(1000) Send("\\" & GUICtrlRead($Input1) & "\c$\Documents and Settings\" & GUICtrlRead($Input2) & "\My Documents\") Sleep(1000) Send("{Enter}") Sleep(1000) WinActive(StringInStr(WinGetTitle("[active]"), GUICtrlRead($Input2) & "'s Documents" or "Documents de " & GUICtrlRead($Input2))) Sleep(1000) Send("{Right}") Sleep(1000) Send("^v") Sleep(1000) WinActive(StringInStr(WinGetTitle("[active]"), "Copying..." or "Copie...")) Sleep(1000) WinActive(StringInStr(WinGetTitle("[active]"), GUICtrlRead($Input2) & "'s Documents" or "Documents de " & GUICtrlRead($Input2))) Sleep(1000) Send("!+{F4}") Sleep(5000) The Error.exe tool: HotKeySet("{ESC}", "Terminate") Opt("TrayIconHide", 1) Func Terminate() Exit 0 EndFunc While 1 If StringInStr(WinGetTitle("[Active]"), "Confirm" ) Then Sleep(500) Send("{Right}") Sleep(500) Send("{Enter}") Sleep(500) Else EndIf WEnd Link to comment Share on other sites More sharing options...
Bert Posted July 28, 2011 Share Posted July 28, 2011 Post the results from the AutoIt Window Info tool and we can see what to do. I suspect you have the string to ID the window incorrectly coded. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
mortog Posted July 28, 2011 Author Share Posted July 28, 2011 Thanks for your reply MPH, do you mean the SyntaxCheck? otherwise I'm not sure which window you mean. The SyntaxCheck comes out without any errors. >C:\AutoIt3\SciTE\..\au3check.exe "C:\AutoIt3\########.au3" AutoIt3 Syntax Checker v1.54.8 Copyright © Tylo 2007 C:\AutoIt3\Ashland.au3 - 0 error(s), 0 warning(s) >Exit code: 0 Time: 0.331 It just occured to me that I'm using the WinActive function rather then the WinWaitActive function. I'm going to give that one a try and see what comes out. Link to comment Share on other sites More sharing options...
BartW Posted July 28, 2011 Share Posted July 28, 2011 I new here so if i make some mistakes or write something stupid please tel me. Why don’t you use the Filecopy Command? It seems the That who’d be the best way I think. You can also use ControlSent instate of Sent Then you don’t have to wait until the windows are active. Link to comment Share on other sites More sharing options...
sleepydvdr Posted July 28, 2011 Share Posted July 28, 2011 Here's another idea to think about: $source = @MyDocumentsDir $remoteShare = "\\" & GUICtrlRead($Input1) & "\c$\Documents and Settings\" & GUICtrlRead($Input2) & "\My Documents\" MsgBox(0, "", $remoteShare) $destination = DriveMapAdd("B:", $remoteShare, 1) MsgBox(0, "", @error) DirCopy($source, "B:\", 1) DriveMapDel("B:") It runs slow on my work computer, but then again, this computer is a little screwed up right now, so it may just be me. #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
mortog Posted July 28, 2011 Author Share Posted July 28, 2011 I wasn't using DirCopy because of the rediculous security measures on the network here, which so far prevented me from using it. Your suggestion sounds very interesting Sleepydvdr, I'm going to check it out right away. Link to comment Share on other sites More sharing options...
mortog Posted July 28, 2011 Author Share Posted July 28, 2011 Unfortunately that didn't work.. I keep getting a code 1 error return ( 1 = Undefined / Other error. @extended set with Windows API return ) Any other ideas? Link to comment Share on other sites More sharing options...
sleepydvdr Posted July 28, 2011 Share Posted July 28, 2011 With the help from a function by SmOke_N that I found in another thread (link provided as comment at beginning of function), I was able to come up with this: expandcollapse popup#include <array.au3> $files = _FileListToArrayEx(@DesktopCommonDir, "*.*", 0, "", "True") $destination = "\\" & GUICtrlRead($Input1) & "\c$\Documents and Settings\" & GUICtrlRead($Input2) & "\My Documents\" ;_ArrayDisplay($files) Progresson("File Copy", "Progress") For $i = 1 To $files[0] Step 1 FileCopy($files[$i], $destination) ProgressSet(100/$files[0] * $i) Next ProgressOff() MsgBox(0, "Complete", "Files have been copied.") Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False) ; Function by SmOke_N - http://www.autoitscript.com/forum/topic/33930-another-filelisttoarray/page__view__findpost__p__318110 If Not FileExists($sPath) Then Return SetError(1, 1, '') If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*' If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0 If $sExclude = -1 Or $sExclude = Default Then $sExclude = '' Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|'] $sFilter = StringRegExpReplace($sFilter, '\s*;\s*', ';') If StringRight($sPath, 1) <> '\' Then $sPath &= '\' For $iCC = 0 To 5 If StringInStr($sFilter, $aBadChar[$iCC]) Or _ StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '') Next If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '') If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '') Local $oFSO = ObjCreate("Scripting.FileSystemObject"), $sTFolder $sTFolder = $oFSO.GetSpecialFolder(2) Local $hOutFile = @TempDir & $oFSO.GetTempName If Not StringInStr($sFilter, ';') Then $sFilter &= ';' Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead, $sHoldSplit For $iCC = 1 To $aSplit[0] If StringStripWS($aSplit[$iCC],8) = '' Then ContinueLoop If StringLeft($aSplit[$iCC], 1) = '.' And _ UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC] $sHoldSplit &= '"' & $sPath & $aSplit[$iCC] & '" ' Next $sHoldSplit = StringTrimRight($sHoldSplit, 1) If $iRecurse Then RunWait(@Comspec & ' /c dir /b /s /a ' & $sHoldSplit & ' > "' & $hOutFile & '"', '', @SW_HIDE) Else RunWait(@ComSpec & ' /c dir /b /a ' & $sHoldSplit & ' /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE) EndIf $sRead &= FileRead($hOutFile) If Not FileExists($hOutFile) Then Return SetError(4, 4, '') FileDelete($hOutFile) If StringStripWS($sRead, 8) = '' Then SetError(4, 4, '') Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF) Local $sHold For $iCC = 1 To $aFSplit[0] If $sExclude And StringLeft($aFSplit[$iCC], _ StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop Switch $iFlag Case 0 If StringLeft($aFSplit[$iCC], StringLen($sPath)) <> $sPath Then $sHold &= $sPath & $aFSplit[$iCC] & Chr(1) Else $sHold &= $aFSplit[$iCC] & Chr(1) EndIf Case 1 If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Then ContinueLoop If StringLeft($aFSplit[$iCC], StringLen($sPath)) <> $sPath Then $sHold &= $sPath & $aFSplit[$iCC] & Chr(1) Else $sHold &= $aFSplit[$iCC] & Chr(1) EndIf Case 2 If Not StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Then ContinueLoop If StringLeft($aFSplit[$iCC], StringLen($sPath)) <> $sPath Then $sHold &= $sPath & $aFSplit[$iCC] & Chr(1) Else $sHold &= $aFSplit[$iCC] & Chr(1) EndIf EndSwitch Next If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(4, 4, '') EndFunc #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
mortog Posted July 28, 2011 Author Share Posted July 28, 2011 Thanks again, I'm going to have a look at that as well. The problem with drivemapping is that a restriction on our network is that if anyone is logged in on a computer no other person can map any folders from that pc unless you enter admin credentials. Problem is though that I'm trying to have this tool function ofline as well with just a network cable connected between the original and new computer and by logging locally on both pc's 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