#RequireAdmin ; Runs script as admin user #include #include #include #include #include #include #Include #include #include #include #include #include #include #include #include #Include #include #Include #include #include #include #include #include #include #include #include #include ; #Include <_DBUG.au3> ; Used for debugging script #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Run_AU3Check=N ; #Autoit3Wrapper_Testing=Y Opt("MouseCoordMode", 2) ; define standard drives and network share folders Global $usbFixedDrive = "F:\" Global $usbRemovDrive = "I:\" Global $mappedNWShareDrive = "\\g-cad1\Storage\ShellbagsTest\" Global $mappedShareptDrive = "https://gcpartners-my.sharepoint.com/personal/dcrozier_g-cpartners_com/_layouts/15/onedrive.aspx" Global $maxNum = 2 Global $WinHandOrig[9] Global $NotepadHand[9] Global $FldrWinHand[9] Global $WinHand3 Global $WinHand4 Global $i = 0 Global $j = 0 Global $k = 0 Global $m = 0 ; get desktop width and height to orient explorer windows Global $iWidth = @DesktopWidth / 2 Global $iHeight = @DesktopHeight - 50 ; ; Create a constant variable with the filepath ; Global $FilePath[9] $FilePath[0] = @DesktopDir $FilePath[1] = @MyDocumentsDir $FilePath[2] = "C:\Users\DavidaCrozier\AppData\Local\Temp" $FilePath[3] = @WindowsDir $FilePath[4] = @SystemDir $FilePath[5] = $usbFixedDrive $FilePath[6] = $usbRemovDrive $FilePath[7] = $mappedNWShareDrive $FilePath[8] = $mappedShareptDrive Sleep(500) ; ; Create a constant variable with the window title ; Global $FileTitle[9] $FileTitle[0] = "Desktop" $FileTitle[1] = "Documents" $FileTitle[2] = "Temp" $FileTitle[3] = "Windows" $FileTitle[4] = "System32" $FileTitle[5] = "J:\" $FileTitle[6] = $usbRemovDrive $FileTitle[7] = $mappedNWShareDrive $FileTitle[8] = $mappedShareptDrive Sleep(500) ; ; Define file names for different directories ; Global $runDate = @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC Global $FileName[9] For $h = 0 To $maxNum Step 1 $FileName[$h] = $FilePath[$h] & "\" & $runDate & ".txt" Next Sleep(500) Main() Func Main() ; Open file to write to ; Create a constant variable in Local scope of the filepath that will be read/written to. Local Const $sFilePath = $FilePath[0] & "\" & $runDate & ".me" ; Create a temporary file to write data to. If Not FileWrite($sFilePath, "Start of the FileWrite Main Function, line 1. " & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf ; Open the file for writing (append to the end of a file) and store the handle to a variable. Global $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox(0, "Error -1=hFileOpen", "Main - An error occurred whilst writing the temporary file.") Return False EndIf ; End of Open file to write log data For $m = 0 To $maxNum Step 1 $WinHandOrig[$m] = CreateFilePath($FilePath[$m], $FileTitle[$m]) FileWrite($hFileOpen, "CreateFilePath " & $m & " Done " & $WinHandOrig[$m] & @CRLF) Sleep(500) CreateRundateFolder($WinHandOrig[$m]) Next ; m For $i = 0 To $maxNum Step 1 ; delete temporary/rundate directory created DeleteFileOrDirectory($FilePath[$i], $WinHandOrig[$i], "P") Next ; i EndFunc ;==> Main Func CreateFilePath($filePath, $fileTitle) ; opens explorer window and returns the windows handle for the file path specified Sleep(500) Local $iPid = Run ("explorer.exe " & $filePath) Sleep(500) If $iPid = 0 Then ; Run failed MsgBox(0, "Error -1", "CreateFilePath run explorer failed.") FileWrite($hFileOpen, "Error -1 CreateFilePath run explorer failed." & @CRLF) Exit(-1) Else Sleep(500) Local $WinHand = WinGetHandle ($fileTitle, "") Sleep(500) If @error = 0 Then ; WinGetHandle worked FileWrite($hFileOpen, "CreateFilePath $WinHand: " & $WinHand & " $filePath: " & $filePath & " @error: " & @error & @CRLF) Sleep(500) Return $WinHand Else MsgBox(0, "Error -2", "CreateFilePath WinGetHandle failed.") FileWrite($hFileOpen, "Error -2 CreateFilePath WinGetHandle failed." & @CRLF) Exit(-2) EndIf Sleep(500) EndIf Sleep(500) EndFunc ;==>CreateFilePath Func CreateRundateFolder($fromWinHand) ; create a new folder (temporary one) with rundate as the name ControlSend ($fromWinHand, "", "[CLASS:NetUIHWND]", "!H") Sleep(500) ControlSend ($fromWinHand, "", "[CLASS:NetUIHWND]", "N") Sleep(500) ControlSend ($fromWinHand, "", "", $runDate) Sleep(500) ControlSend ($fromWinHand, "", "", "{ENTER}") Sleep(500) EndFunc ;==> CreateRundateFolder Func DeleteFileOrDirectory($filePath, $WinHand, $fileOrPath) ; delete the file or directory passed in FileWrite($hFileOpen, "DeleteFileOrDirectory Start. $filePath: " & $FilePath & " $WinHand: " & $WinHand & " $fileOrPath: " & $fileOrPath & @CRLF) ; ensure the desired file path window is active Local $retVal3 = WinActivate($WinHand, "") If $retVal3 = 0 Then ; Winactivate window not found or cannot activate MsgBox(0, "Error -140", "DeleteFileOrDirectory WinWaitActive time out.") FileWrite($hFileOpen, "Error -140 DeleteFileOrDirectory WinWaitActive time out." & @CRLF) Exit(-140) EndIf Sleep(500) If $fileOrPath = "P" Then ; deleting a path GetFolderFocus($filePath & "\" & $runDate, $WinHand) ControlSend ($WinHand, "", "[CLASS:NetUIHWND]", "!H") Else ; deleting the text or readme file ; GetFileFocus sets the focus to the $filename and clears the focus for all other items in the folder GetFileFocus($filePath, $WinHand) ; ensure the desired file path window is active Sleep(500) $retValue9 = WinWaitActive($WinHand, "", 30) ;Sleep(500) If $retValue9 = 0 Then ; WinActive timed out MsgBox(0, "Error -15", "DeleteFileOrDirectory WinWaitActive time out.") FileWrite($hFileOpen, "Error -15 DeleteFileOrDirectory WinWaitActive time out." & @CRLF) Exit(-15) EndIf EndIf ; Sleep(500) ; SendDeleteSeq ($WinHand) Sleep(500) FileWrite($hFileOpen, "DelteFileOrDirectory End." & @CRLF) EndFunc ;==> DeleteFileOrDirectory Func SendDeleteSeq ($WinHand) ; delete the temporary folder or file ; sends alt H, D, and enter to windows handle specified ; FileWrite($hFileOpen, "SendDeleteSeq Start." & @CRLF) ; Sleep(500) ControlSend ($WinHand, "", "[CLASS:NetUIHWND]", "!H") Sleep(500) ControlSend ($WinHand, "", "[CLASS:NetUIHWND]", "D") Sleep(500) ControlSend ($WinHand, "", "[CLASS:NetUIHWND]", "{ENTER}") Sleep(500) Send("!Y") Sleep(500) FileWrite($hFileOpen, "SendDeleteSeq End." & @CRLF) EndFunc ;==> SendDeleteSeq