Javik Posted April 6, 2011 Share Posted April 6, 2011 Is there some way to read the state of an Explorer window, so that if it is already in List view, Sorted by Name, in Ascending order, then I don't need to Send those keys to the window every time the script runs? I am writing a very simple script that will show an Explorer folder with shortcuts to all installed applications. (This basically duplicates the appearance of the Novell Application Launcher that we are no longer using, after migrating to Active Directory.) This is what I have so far. It works, but I don't like the flickering caused by Send()-ing menu keys to the window, unless I have to do that. expandcollapse popup; Name of Applications folder on desktop $AppFolder ="Applications" $W7_Path = "C:\Users\Public\Desktop\" & $AppFolder $XP_Path = "C:\Documents and Settings\All Users\Desktop\" & $AppFolder $W7 = False $XP = False ; Custom title to apply for this Explorer window ; Note, for Win 7 this is not shown except in Classic View desktop mode $CustomTitle = "Application Launcher window for our school district" ; Check to see if we already have this window open and named. ; If yes then just make it active again, and exit IF WinExists($CustomTitle) then WinActivate ($CustomTitle) Exit EndIf ; Check to see if the full path will be the Explorer window name $FullPathInExplorerTitle = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState","FullPath") ; Assuming folder name for window name by default: $WinTitle = $AppFolder ; Check if we're on Windows 7 (may work on Vista) IF FileExists($W7_Path) Then ShellExecute($W7_Path) IF $FullPathInExplorerTitle > 0 then $WinTitle = $W7_Path $W7 = TRUE Else ; Check if we're on Windows XP (may work on Win 2000) ; Doing this in an "Else" since Win7 has symlinks for Docs and ; Settings, so this part could trigger again under Win7. IF FileExists($XP_Path) Then ShellExecute($XP_Path) IF $FullPathInExplorerTitle > 0 then $WinTitle = $XP_Path $XP = TRUE EndIf EndIf ; if neither of the above are true, then unknown state, just exit IF Not $XP and Not $W7 Then Exit ; Apps Window may take a long time to become active when booting ; and then immediately logging on, due to virus scanning.. WinWaitActive ($WinTitle,"",120) ; If there's been a delay for opening, get focus again before sending keys WinActivate ($WinTitle) ; Change window appearance by piping keys to explorer window ; ; Note: If already sorted by name, choosing it again will sort descending. ; Solution: sort by something else, and then by name to get ascending IF $W7 THEN ; {Alt}VOS - Alt -> Menu View -> Order by -> Size ; {Alt}VL - Alt -> Menu View -> List View ; {Alt}VON - Alt -> Menu View -> Order by -> Name Send("{Alt}VOS{Alt}VL{Alt}VON") EndIf IF $XP THEN ; {Alt}VIS - Alt -> Menu View -> Arrange Icons By -> Size ; {Alt}VL - Alt -> Menu View -> List View ; {Alt}VIN - Alt -> Menu View -> Arrange Icons By -> Name Send("{Alt}VIS{Alt}VL{Alt}VIN") EndIf ; Center window on screen, 100 pixel border on all sides WinMove($WinTitle,"",100,100, @DesktopWidth - 200, @DesktopHeight - 200) ; Give it a custom window name WinSetTitle($WinTitle,"",$CustomTitle) 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