mr-es335 Posted 9 hours ago Posted 9 hours ago Good day, My I as "Why?" this script is NOT workikng? expandcollapse popup; ----------------------------------------------- #RequireAdmin ; ----------------------------------------------- ; Update provided by ioa747, with gratitude...07/16/25 ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Local $iULx = 150, $iULy = 150, $iULw = 400, $iULh = 400 Local $iUCx = 325, $iUCy = 265, $iUCw = 400, $iUCh = 400 Local $iURx = 500, $iURy = 380, $iURw = 400, $iURh = 400 ; ------------------------ LaunchFirstFolder() LaunchSecondFolder() LaunchThirdFolder() PauseMe() ExitThirdFolder() ExitSecondFolder() ExitFirstFolder() ; ----------------------------------------------- Func LaunchFirstFolder() Local $sSrcPath = "C:\Users\RML_User" ; ----------------------------------------------- ShellExecute($sSrcPath) Local $hWnd = WinWaitActive("[CLASS:CabinetWClass; TITLE:" & StringLeft($sSrcPath, 90) & "]", "", 1) If $hWnd Then WinMove($hWnd, "", $iULx, $iULy, $iULw, $iULh) EndFunc ;==>LaunchFirstFolder ; ----------------------------------------------- Func LaunchSecondFolder() Local $sSrcPath = "E:\" ; ----------------------------------------------- ShellExecute($sSrcPath) Local $hWnd = WinWaitActive("[CLASS:CabinetWClass; TITLE:" & StringLeft($sSrcPath, 90) & "]", "", 1) If $hWnd Then WinMove($hWnd, "", $iUCx, $iUCy, $iUCw, $iUCh) EndFunc ;==>LaunchSecondFolder ; ----------------------------------------------- Func LaunchThirdFolder() Local $sSrcPath = "F:\" ; ----------------------------------------------- ShellExecute($sSrcPath) Local $hWnd = WinWaitActive("[CLASS:CabinetWClass; TITLE:" & StringLeft($sSrcPath, 90) & "]", "", 1) If $hWnd Then WinMove($hWnd, "", $iURx, $iURy, $iURw, $iURh) EndFunc ;==>LaunchThirdFolder ; ----------------------------------------------- Func PauseMe() Local $sMessage1 = "Please wait a moment..." & @CRLF & @CRLF, $iWidth = 250, $iHeight = 45 Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14 ; ----------------------------------------------- SplashTextOn("", $sMessage1, $iWidth, $iHeight, 725, 300, $iOpt, $sFontName, $iFontSize) ;~ SplashTextOn("", $sMessage1, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize) ; ----------------------------------------------- Sleep(2000) SplashOff() EndFunc ;==>PauseMe ; ----------------------------------------------- Func ExitThirdFolder() Local $sSrcPath = "F:\" Local $iFileExists = FileExists($sSrcPath) ; ----------------------------------------------- If $iFileExists Then WinClose($sSrcPath) EndIf EndFunc ;==>ExitThirdFolder ; ----------------------------------------------- Func ExitSecondFolder() Local $sSrcPath = "E:\" Local $iFileExists = FileExists($sSrcPath) ; ----------------------------------------------- If $iFileExists Then WinClose($sSrcPath) EndIf EndFunc ;==>ExitSecondFolder ; ----------------------------------------------- Func ExitFirstFolder() Local $sSrcPath = "C:\Users\RML_User" Local $iFileExists = FileExists($sSrcPath) ; ----------------------------------------------- If $iFileExists Then WinClose($sSrcPath) EndIf EndFunc ;==>ExitFirstFolder ; ----------------------------------------------- Observations The Second and Third folders work as expected...but NOT the first folder! Why?!? What am I missing here? As always...any assistance in this matter would be greatly appreciated! mr-es335 Sentinel Music Studios
ioa747 Posted 8 hours ago Posted 8 hours ago (edited) is because your function Func LaunchFirstFolder() Local $sSrcPath = "C:\Users\RML_User" ; ----------------------------------------------- ShellExecute($sSrcPath) Local $hWnd = WinWaitActive("[CLASS:CabinetWClass; TITLE:" & StringLeft($sSrcPath, 90) & "]", "", 1) If $hWnd Then WinMove($hWnd, "", $iULx, $iULy, $iULw, $iULh) EndFunc ;==>LaunchFirstFolder expects a window with a title that starts with "C:\Users\RML_User", but your window does not have such a title Edit: So for clarification, you need to tell us what the title of the window say Edited 8 hours ago by ioa747 I know that I know nothing
mr-es335 Posted 3 hours ago Author Posted 3 hours ago (edited) I have two log-ons on this system, "Dell" and RML_user. I am currently logged-in as "Dell" When I launch the script, and If I employ, Local $sSrcPath = "C:\Users\RML_User" - the folder launches and exits as expected. However, when I employ, Local $sSrcPath = "C:\Users\Dell", a different folder view appears and the folder does not exist. The title for "C:\Users\RML_User" is "C:\Users\RML_User". However the title for "C:\Users\Dell" appears to be just "Dell"! Is this because "Dell" is the currently logged-on user? All other folders launch and exit fine...it is just the logged-in user that I seem to having issues with! Please advise. Edited 3 hours ago by mr-es335 ioa747 1 mr-es335 Sentinel Music Studios
Trong Posted 3 hours ago Posted 3 hours ago You can try the following code and change it according to your needs: expandcollapse popup#include <MsgBoxConstants.au3> ; ---------------------------------------------------------------------------------------------------------------------- ; Name: _FindNewExplorerWindow ; Function: Finds the handle of the newest Explorer window that was created. ; Returns: ; The handle of the new window if found, otherwise returns 0. ; ---------------------------------------------------------------------------------------------------------------------- Func _FindNewExplorerWindow() Local $aInitialList = WinList("[CLASS:CabinetWClass]") Local $hWnd = 0 Local $iTimeout = 10 ; 10 second timeout Local $iStartTime = TimerInit() Do Sleep(255) ; Wait a bit before checking again Local $aCurrentList = WinList("[CLASS:CabinetWClass]") If UBound($aCurrentList) > UBound($aInitialList) Then ; Loop through the current list to find the window not in the initial list For $i = 1 To $aCurrentList[0][0] Local $bFound = False For $j = 1 To $aInitialList[0][0] If $aCurrentList[$i][1] == $aInitialList[$j][1] Then $bFound = True ExitLoop EndIf Next ; If the window is not in the initial list, this is the new one If Not $bFound Then $hWnd = $aCurrentList[$i][1] ExitLoop EndIf Next EndIf Until $hWnd <> 0 Or TimerDiff($iStartTime) > ($iTimeout * 1000) Return $hWnd EndFunc ;==>_FindNewExplorerWindow ; ---------------------------------------------------------------------------------------------------------------------- ; Name: _PerformTask ; Function: A custom function to perform tasks on a window. ; Parameters: ; $hWnd - The handle of the window ; Returns: ; None ; ---------------------------------------------------------------------------------------------------------------------- Func _PerformTask($hWnd) ; Example: Move the window to a random position Local $iX = Random(0, @DesktopWidth - 500, 1) Local $iY = Random(0, @DesktopHeight - 400, 1) WinMove($hWnd, "", $iX, $iY) ; Example: Activate the window WinActivate($hWnd) ; Example: Pause briefly for observation Sleep(500) EndFunc ;==>_PerformTask ; ---------------------------------------------------------------------------------------------------------------------- ; The list of folders you want to open and manipulate ; ---------------------------------------------------------------------------------------------------------------------- Local $aFoldersToOpen[] = [ _ "C:\", _ "D:\", _ "C:\Users\" & @UserName & "\Desktop" _ ] ; Array to store the handles of the opened windows Local $aOpenedWindows[0] ; Initialize with a size of 0 ; ---------------------------------------------------------------------------------------------------------------------- ; Main Loop: Open all folders and perform tasks ; ---------------------------------------------------------------------------------------------------------------------- For $i = 0 To UBound($aFoldersToOpen) - 1 Local $sFolderPath = $aFoldersToOpen[$i] ShellExecute($sFolderPath) ; Find the new window and get its handle Local $hWnd = _FindNewExplorerWindow() If $hWnd <> 0 Then ; If the window is found, add the handle to the array ReDim $aOpenedWindows[UBound($aOpenedWindows) + 1] $aOpenedWindows[UBound($aOpenedWindows) - 1] = $hWnd ; Move the window to a specific position and perform the task _PerformTask($hWnd) ConsoleWrite("Successfully opened folder: " & $sFolderPath & @CRLF) Else ConsoleWrite("Error: Could not find the window for folder: " & $sFolderPath & @CRLF) EndIf Next MsgBox($MB_ICONINFORMATION, "Information", "All windows have been opened and tasks performed. Click OK to close them.") ; ---------------------------------------------------------------------------------------------------------------------- ; Final Loop: Close all opened windows ; ---------------------------------------------------------------------------------------------------------------------- If UBound($aOpenedWindows) > 0 Then For $i = 0 To UBound($aOpenedWindows) - 1 Local $hWndToClose = $aOpenedWindows[$i] If WinExists($hWndToClose) Then WinClose($hWndToClose) ConsoleWrite("Closed window with handle: " & $hWndToClose & @CRLF) EndIf Next EndIf MsgBox($MB_ICONINFORMATION, "Complete", "All opened windows have been closed.") Regards,
mr-es335 Posted 3 hours ago Author Posted 3 hours ago Thanks, but how do I get the windows to "tile" as in my example? mr-es335 Sentinel Music Studios
ioa747 Posted 2 hours ago Posted 2 hours ago (edited) 3 hours ago, mr-es335 said: Is this because "Dell" is the currently logged-on user? yes that's what it is for. For standard folders (Desktop, Documents, Downloads, Music, Pictures, ...) it cuts the path and makes a friendlier name What do you want? as user Dell, it will go to C:\Users\Dell and as user RML_User, it will go to C:\Users\RML_User expandcollapse popup; https://www.autoitscript.com/forum/topic/213091-users-folder-issue/#findComment-1545474 ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Local $aUL = [150, 150, 400, 400] Local $aUC = [325, 265, 400, 400] Local $aUR = [500, 380, 400, 400] ; ------------------------ LaunchFolder(@UserProfileDir, $aUL) LaunchFolder("E:\", $aUC) LaunchFolder("F:\", $aUR) PauseMe() ExitFolder("F:\") ExitFolder("E:\") ExitFolder(@UserProfileDir) ; ----------------------------------------------- Func LaunchFolder($sSrcPath, ByRef $aPos) ShellExecute("Explorer.exe", $sSrcPath) Local $hWnd = WinWaitActive("[CLASS:CabinetWClass; TITLE:" & StringLeft($sSrcPath, 90) & "]", "", 1) If $hWnd Then WinMove($hWnd, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3]) EndFunc ;==>LaunchFirstFolder ; ----------------------------------------------- Func PauseMe() Local $sMessage1 = "Please wait a moment..." & @CRLF & @CRLF, $iWidth = 250, $iHeight = 45 Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14 SplashTextOn("", $sMessage1, $iWidth, $iHeight, 725, 300, $iOpt, $sFontName, $iFontSize) ;~ SplashTextOn("", $sMessage1, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize) Sleep(2000) SplashOff() EndFunc ;==>PauseMe ; ----------------------------------------------- Func ExitFolder($sSrcPath) WinClose("[CLASS:CabinetWClass; TITLE:" & StringLeft($sSrcPath, 90) & "]") EndFunc ;==>ExitThirdFolder ; ----------------------------------------------- Edit: I tricked it by opening it, not as a user but as Explorer. Edited 11 minutes ago by ioa747 I know that I know nothing
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