VelvetElvis Posted August 17, 2011 Posted August 17, 2011 (edited) I've written a script to create a folder on the desktop and populate it with shortcuts, but the folder view is "Details". How do I change the view to "Icons"? The only catch is that the users running this script will not have admin access, so if my only option is a registry change, it has to work for all users. Thanks. Edited August 17, 2011 by VelvetElvis
VelvetElvis Posted August 18, 2011 Author Posted August 18, 2011 I've written a script to create a folder on the desktop and populate it with shortcuts, but the folder view is "Details". How do I change the view to "Icons"? The only catch is that the users running this script will not have admin access, so if my only option is a registry change, it has to work for all users. Thanks. Can anyone help? Here's what I have using a bunch of Send's. It's ugly. I'd prefer not to have the users see this. I just need to change the folder view to "Icons". I've searched the forum, but not joy. ; Set desktop folder view from "details" to "icons" Send("!V") Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}") Sleep(1000) Send("{ENTER}") Send("!F") Send("C") Exit
LurchMan Posted August 18, 2011 Posted August 18, 2011 Have a look at _GUICtrlListView_SetView() in the help file. Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
VelvetElvis Posted August 18, 2011 Author Posted August 18, 2011 Have a look at _GUICtrlListView_SetView() in the help file. Thank you so much. But I'm having trouble getting the handle of the desktop folder that I created. Here's what I have: #Include <GuiListView.au3> $handle = ControlGetHandle("[CLASS:SysListView32; INSTANCE:1]", "FolderView", "1") _GUICtrlListView_SetView($handle, 3) This doesn't work. I used the Window Info tool to get the control info for the folder (which is closed), but I'm either not using the right info, or I've got the wrong function to get that handle. Can you (or anyone) give me a nudge in the right direction? I've attached the Window Info for the folder. Again, thanks for the help.
LurchMan Posted August 18, 2011 Posted August 18, 2011 (edited) Look at the parms for ControlGetHandle () in the help file again.ControlGetHandle ( "title", "text", controlID )You have the control ID in the Title parameter. Also, this will only work if the window is open.Edit: If you run this with the "Program Manager" as the title you're going to change all the icons on your desktop. The window has to be open and you have to use the title of the window. Edited August 18, 2011 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
rover Posted August 18, 2011 Posted August 18, 2011 I've written a script to create a folder on the desktop and populate it with shortcuts, but the folder view is "Details". How do I change the view to "Icons"? The only catch is that the users running this script will not have admin access, so if my only option is a registry change, it has to work for all users. Thanks. Hi VelvetElvis, LurchMan If a permanent solution is required, this code will change the view of an explorer window and store the change in the user profile. (based on code by Siao) It uses undocumented shell constants I've added the constants for Vista/7 Tested on XP and Vista x86 expandcollapse popup#include <WindowsConstants.au3> ;; reverse-engineered command codes for SHELLDLL_DefView (Paul DiLascia, MSDN Magazine — March 2004) ;http://msdn.microsoft.com/en-us/magazine/cc164009.aspx ;W2K/XP Global Const $ODM_VIEW_ICONS = 0x7029 Global Const $ODM_VIEW_LIST = 0x702b Global Const $ODM_VIEW_DETAIL = 0x702c Global Const $ODM_VIEW_THUMBS = 0x702d Global Const $ODM_VIEW_TILES = 0x702e ;Vista/Win 7 Global Const $FVM_EXTRALARGE = 0x704d Global Const $FVM_TILES = 0x704c Global Const $FVM_MEDIUMICON = 0x704e Global Const $FVM_LARGE = 0x704f Global Const $FVM_SMALL = 0x7050 Global Const $FVM_LIST = 0x7051 Global Const $FVM_DETAILS = 0x704b Global Const $FVM_CONTENT = 0x7052 ;Win 7 Global $sFolderName = "Desktop Folder Shortcut Name" _ExplorerSetView($sFolderName, $FVM_MEDIUMICON, 1) ;explorer is run minimized, then closed _ExplorerSetView($sFolderName, $FVM_MEDIUMICON, 0) ;explorer is run normally Exit Func _ExplorerSetView($ExpFolder, $iView = 0, $iMode = 0) ;$ExpFolder: use Desktop folder name or a handle to an Explorer window ;$iView: Shell view constant ;$iMode = 0: explorer window not closed ;$iMode = 1: $ExpFolder = Desktop folder name: explorer window opened minimized and closed on return ;$iMode = 1: $ExpFolder = handle to an Explorer window: explorer window closed on return ;rover 2k11 If IsHWnd($ExpFolder) = 0 Then Local $sDesktopFolder = @DesktopDir & "\" & $ExpFolder If FileExists($sDesktopFolder) = 0 Then Return SetError(1, 0, 0) If $iView <= 0 Then Return SetError(2, 0, 0) Local $iOpt = Opt("WinTitleMatchMode", 2) ;for explorer folders with fullpath or folder name only Local $sWin = "[TITLE:" & $ExpFolder & "; REGEXPCLASS:(Explore|Cabinet)WClass]" If $iMode Then ShellExecute($sDesktopFolder, "", "", "open", @SW_MINIMIZE) Else ShellExecute($sDesktopFolder, "", "", "open") EndIf $ExpFolder = WinWait($sWin, "", 5) Opt("WinTitleMatchMode", $iOpt) If IsHWnd($ExpFolder) = 0 Then Return SetError(3, 0, 0) EndIf Local $hSHELLDLL_DefView = ControlGetHandle($ExpFolder, "", "[CLASS:SHELLDLL_DefView; INSTANCE:1]") If IsHWnd($hSHELLDLL_DefView) = 0 Then If $iMode Then WinClose($ExpFolder) Return SetError(4, 0, 0) EndIf DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hSHELLDLL_DefView, _ "uint", $WM_COMMAND, "wparam", $iView, "lparam", 0) If @error Then If $iMode Then WinClose($ExpFolder) Return SetError(5, 0, 0) EndIf If $iMode Then WinClose($ExpFolder) Return 1 EndFunc ;==>_ExplorerSetView I see fascists...
VelvetElvis Posted August 19, 2011 Author Posted August 19, 2011 Wow, this turned out to be way more complicated than I expected. @LurchMan; I thought my line was contrary to the help, but I was going by this example in the help: $handle = ControlGetHandle("[CLASS:Notepad]", "", "Edit1") where Class was in the first parameter. I tried _GUICtrlListView_SetView() as you advised in your first reply, with the folder open, it didn't work with this code: #Include <GuiListView.au3> $handle = WinGetHandle("Hospital Internet Links") _GUICtrlListView_SetView($handle, 1) @rover; First, I didn't understand why the section "Vista/Win 7" had variables that the "W2K/XP" section didn't. At first, I thought I could delete the "Vista/Win/7" section, as I'm using XP, but of course that didn't fly. In any event, I tried your code in XP as submitted, just changing the folder name parameter. It didn't work. Worse, I didn't understand it (my limitation). The idea of using 60 lines of code to accomplish something that one would think trivial blew me away too. Thank you both very much for your help with this, but I think I'll have to admit defeat and stick with my handful of Send commands.
rover Posted August 19, 2011 Posted August 19, 2011 Wow, this turned out to be way more complicated than I expected. @LurchMan; I thought my line was contrary to the help, but I was going by this example in the help: $handle = ControlGetHandle("[CLASS:Notepad]", "", "Edit1") where Class was in the first parameter. I tried _GUICtrlListView_SetView() as you advised in your first reply, with the folder open, it didn't work with this code: #Include <GuiListView.au3> $handle = WinGetHandle("Hospital Internet Links") _GUICtrlListView_SetView($handle, 1) @rover; First, I didn't understand why the section "Vista/Win 7" had variables that the "W2K/XP" section didn't. At first, I thought I could delete the "Vista/Win/7" section, as I'm using XP, but of course that didn't fly. In any event, I tried your code in XP as submitted, just changing the folder name parameter. It didn't work. Worse, I didn't understand it (my limitation). The idea of using 60 lines of code to accomplish something that one would think trivial blew me away too. Thank you both very much for your help with this, but I think I'll have to admit defeat and stick with my handful of Send commands. Hi Firstly, what version of AutoIt are you using? In the SciTE editor, 'Tools' menu, 'Compile', first tab 'AutoIt version to use:' This example was coded with production version 3.3.6.1 and tested in XP Pro SP3 x86/Vista Ultimate x86 There could/will be issues if you are using an older version e.g. a pre-unicode version This code uses the unicode version of sendmessage etc. Are you using the SciTE editor that comes with AutoIt, and did you download the full SciTE package? The example uses a Vista/Win 7 constant - $FVM_MEDIUMICON If using XP use - $ODM_VIEW_ICONS Vista/Win 7 have more options for view than previous OS's like XP so just use the XP options and remove all of the Vista/Win 7 global constants Furthermore, I showed two example lines without commenting out one of them and they were both for Vista/Win 7. Run this example, it has a consolewrite and a message box To preclude any missing space in the shortcut folder name, copy and paste the shortcut name into your script. Right click the desktop folder shortcut, select 'Rename' Right click, select 'Copy' Right click in the SciTE editor in your script, paste and overwrite the shortcut name in $sFolderName Global $sFolderName = "Desktop Folder Shortcut Name" The script will launch your desktop folder. Did the folder of shortcuts open up in explorer? What is the return value and error code value in the message box? If the folder did not open up then the shortcut name is wrong or there is a problem with desktop location or the shellexecute line. Add error checking to any code and it can easily increase by 50% look at the insides of some of the UDF include functions. The few lines of code you use are the tip of an iceberg. Massive amounts of code underlie everything you do in AutoIt. I will check back here later today, do try to get this working, perhaps someone else can help. expandcollapse popup;; reverse-engineered command codes for SHELLDLL_DefView (Paul DiLascia, MSDN Magazine — March 2004) ;http://msdn.microsoft.com/en-us/magazine/cc164009.aspx ;W2K/XP Global Const $ODM_VIEW_ICONS = 0x7029 Global Const $ODM_VIEW_LIST = 0x702b Global Const $ODM_VIEW_DETAIL = 0x702c Global Const $ODM_VIEW_THUMBS = 0x702d Global Const $ODM_VIEW_TILES = 0x702e Global $sFolderName = "Desktop Folder Shortcut Name" ; do not add path here, just name Global $iRet = _ExplorerSetView($sFolderName, $ODM_VIEW_ICONS, 0) ;explorer is run normally MsgBox(4096, "_ExplorerSetView", "Return: " & $iRet & @CRLF & "Error: " & @error) ConsoleWrite(@error & @CRLF) Exit Func _ExplorerSetView($ExpFolder, $iView = 0, $iMode = 0) ;$ExpFolder: use Desktop folder name or a handle to an Explorer window ;$iView: Shell view constant ;$iMode = 0: explorer window not closed ;$iMode = 1: $ExpFolder = Desktop folder name: explorer window opened minimized and closed on return ;$iMode = 1: $ExpFolder = handle to an Explorer window: explorer window closed on return ;rover 2k11 Local Const $_WM_COMMAND = 0x0111 If IsHWnd($ExpFolder) = 0 Then Local $sDesktopFolder = @DesktopDir & "\" & $ExpFolder If FileExists($sDesktopFolder) = 0 Then Return SetError(1, 0, 0) If $iView <= 0 Then Return SetError(2, 0, 0) Local $iOpt = Opt("WinTitleMatchMode", 2) ;for explorer folders with fullpath or folder name only Local $sWin = "[TITLE:" & $ExpFolder & "; REGEXPCLASS:(Explore|Cabinet)WClass]" If $iMode Then ShellExecute($sDesktopFolder, "", "", "open", @SW_MINIMIZE) Else ShellExecute($sDesktopFolder, "", "", "open") EndIf $ExpFolder = WinWait($sWin, "", 5) Opt("WinTitleMatchMode", $iOpt) If IsHWnd($ExpFolder) = 0 Then Return SetError(3, 0, 0) EndIf Local $hSHELLDLL_DefView = ControlGetHandle($ExpFolder, "", "[CLASS:SHELLDLL_DefView; INSTANCE:1]") If IsHWnd($hSHELLDLL_DefView) = 0 Then If $iMode Then WinClose($ExpFolder) Return SetError(4, 0, 0) EndIf DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hSHELLDLL_DefView, _ "uint", $_WM_COMMAND, "wparam", $iView, "lparam", 0) If @error Then If $iMode Then WinClose($ExpFolder) Return SetError(5, 0, 0) EndIf If $iMode Then WinClose($ExpFolder) Return 1 EndFunc ;==>_ExplorerSetView I see fascists...
VelvetElvis Posted August 19, 2011 Author Posted August 19, 2011 I'm using the latest version of both AutoIt and the full SciTE install. Tried your second code example, and it worked fine. Re-tried the first one, removing the Vista constants, and again no joy. I noticed that this code opens the folder and leaves it open, which I didn't want. I temporarily worked around it: If $iMode Then ShellExecute($sDesktopFolder, "", "", "open", @SW_MINIMIZE) Else ShellExecute($sDesktopFolder, "", "", "open", @SW_MINIMIZE) EndIf by changing the Else above to @SW_MINIMIZE just to see if it works as I wanted. I will play with this code, for the learning experience. Massive amounts of code underlie everything you do in AutoIt.That's why I was hoping to find a simple function that would keep those massive amounts of code in the background I still think there's a quick and dirty way of doing this via the registry, but I couldn't figure it out. Thank you Rover (and LurchMan too) for your time and patience.
rover Posted August 19, 2011 Posted August 19, 2011 Velvet Elvis I have to run out the door soon, so I'll make this quick. Good to hear you have it working. The function already supports running the explorer window minimized then closing it, so use it with mode option 1 instead of 0 See the comment line in the function _ExplorerSetView() $iMode = 1: $ExpFolder = Desktop folder name: explorer window opened minimized and closed on return Global $iRet = _ExplorerSetView($sFolderName, $ODM_VIEW_ICONS, 1) ;explorer window opened minimized and closed on return I see fascists...
LurchMan Posted August 19, 2011 Posted August 19, 2011 (edited) @LurchMan; I thought my line was contrary to the help, but I was going by this example in the help: $handle = ControlGetHandle("[CLASS:Notepad]", "", "Edit1") where Class was in the first parameter. I tried _GUICtrlListView_SetView() as you advised in your first reply, with the folder open, it didn't work with this code: #Include <GuiListView.au3> $handle = WinGetHandle("Hospital Internet Links") _GUICtrlListView_SetView($handle, 1) VelvetElvis - I'll try and explain this again for reference...Open the Folder, use ControlGetHandle to get the handle of the control not the window. Telling it to change the display of the window isn't going to work. Try this: #include <guilistview.au3> Run ("explorer.exe " & "c:\path\to\folder") ;Open Folder $handle = ControlGetHandle ("Hospital Internet Links", "", "[CLASS:SysListView32; INSTANCE:1]") ;Get Handle _GUICtrlListView_SetView($handle, 1) ;Make Changes WinClose("Hospital Internet Links");Close Window Edited August 19, 2011 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
VelvetElvis Posted August 19, 2011 Author Posted August 19, 2011 Hi LurchMan; It didn't work. Here's what I have: #include <guilistview.au3> Run ("explorer.exe " & @DesktopDir & "\Hospital Internet Links\") ;Open Folder $handle = ControlGetHandle ("Hospital Internet Links", "", "[CLASS:SysListView32; INSTANCE:1]") ;Get Handle ; Throws up error on this line If @error Then MsgBox(0, "", "ERROR") _GUICtrlListView_SetView($handle, 1) ;Make Changes WinClose("Hospital Internet Links");Close Window It opens the folder, but then nothing happens. I put the @Error check in, and it triggered the MsgBox. The WinClose() didn't happen either.
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