Jemboy Posted June 8, 2022 Share Posted June 8, 2022 Im am deploying an update on several computers. All the users have the old shortcut on their desktop, but have moved it the the screenpart they want. Updating the program, I have to delete the old shortcut and create a new one,however, I want to put the new icon on the location of the old icon. What I want to to, is: save the location for a specific file or icon on the desktop. move the new shortcut to the saved location I have been Googling several days, but I do not seem to get the grasp how some others are moving. saving or restoring the desktop icons. Could someone give me some pointers ? Link to comment Share on other sites More sharing options...
Nine Posted June 8, 2022 Share Posted June 8, 2022 Desktop is a ListView (SysListView321) of shortcuts. You can use ControlListView and ListView UDF to interact with it. Only catch is you need to run x64 if you comp is 64 bits. Jemboy 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Subz Posted June 8, 2022 Share Posted June 8, 2022 An example of capturing and moving a shortcuts position: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GuiListView.au3> #include <Array.au3> Global $g_sSearch = "HP Support Assistant" ;~ Show all shortcut positions Global $aShortcutIcon = _GetShortcutPos() If Not @error Then _ArrayDisplay($aShortcutIcon) ;~ Example for searching and moving "HP Support Assistant" shortcut position Global $aShortcutIcon = _GetShortcutPos($g_sSearch) If Not @error Then _ArrayDisplay($aShortcutIcon) ;~ Move the "HP Support Assistant" shortcut to a new position _SetShortcutPos($g_sSearch, 500, 100) MsgBox(4096, "Check New Position", "Check " & $g_sSearch & " position has moved") ;~ Move the "HP Support Assistant" shortcut back to it's original position _SetShortcutPos("HP Support Assistant", $aShortcutIcon[0][1], $aShortcutIcon[0][2]) Func _SetShortcutPos($_sShortcutName = "", $_iXPos = 0, $_iYPos = 0) If $_sShortcutName = "" Then Return ;~ Desktop handle Local $hDesktopListview = ControlGetHandle("[CLASS:Progman]", "", "[CLASS:SysListView32;INSTANCE:1]") If @error Then Exit Local $iShortcutPos = _GUICtrlListView_FindInText($hDesktopListview, $_sShortcutName) _GUICtrlListView_SetItemPosition($hDesktopListview, $iShortcutPos, $_iXPos, $_iYPos) EndFunc Func _GetShortcutPos($_sShortcutName = "") Local $sShortcutName Local $bShortcut = $_sShortcutName = "" ? False : True ;~ Desktop handle Local $hDesktopListview = ControlGetHandle("[CLASS:Progman]", "", "[CLASS:SysListView32;INSTANCE:1]") If @error Then Return SetError(1, 0) ;~ Desktop shortcut count Local $iShortcutCount = _GUICtrlListView_GetItemCount($hDesktopListview) If $iShortcutCount > 0 Then Local $aShortcutPos[$iShortcutCount][3] For $i = 0 To UBound($aShortcutPos, 1) - 1 If $bShortcut Then Dim $aShortcutPos[0][3] $sShortcutName = _GUICtrlListView_GetItemText($hDesktopListview, $i) If $sShortcutName = $_sShortcutName Then Dim $aShortcutPos[1][3] $aShortcutPos[0][0] = $sShortcutName $aShortcutPos[0][1] = _GUICtrlListView_GetItemPositionX($hDesktopListview, $i) $aShortcutPos[0][2] = _GUICtrlListView_GetItemPositionY($hDesktopListview, $i) Return SetError((UBound($aShortcutPos) > 0 ? 0 : 1), 0, $aShortcutPos) EndIf Else $aShortcutPos[$i][0] = _GUICtrlListView_GetItemText($hDesktopListview, $i) $aShortcutPos[$i][1] = _GUICtrlListView_GetItemPositionX($hDesktopListview, $i) $aShortcutPos[$i][2] = _GUICtrlListView_GetItemPositionY($hDesktopListview, $i) EndIf Next Else Return SetError(1, 0) EndIf Return SetError((UBound($aShortcutPos) > 0 ? 0 : 1), 0, $aShortcutPos) EndFunc Jemboy 1 Link to comment Share on other sites More sharing options...
Jemboy Posted June 9, 2022 Author Share Posted June 9, 2022 @SubzThanks for the script, it is realy amazing. Especially because I really do not understand whats is going on and yet it works😀 My script requires to be run as admin or system and the extra amazing part is that even running as admin, it find all the shortcuts. I have however 1 tiny question. The list of "shortcuts" names have no extension. Is there a way to get the list of all files on thes desktop with their extension, so I can differentiate between files with the same name but different extension ? Link to comment Share on other sites More sharing options...
Subz Posted June 10, 2022 Share Posted June 10, 2022 There are four columns in the list view you can use: Name: Shortcuts do not show the extension, other file types do for example filename.txt or filename.msi File Size: example 1.31 KB File Type: example Shortcut, TXT file, File Folder etc... Created Date: xx/xx/xxxx x:xx AM/PM The following would show you the file type of each desktop item: expandcollapse popupFunc _GetShortcutPos($_sShortcutName = "") Local $sShortcutName Local $bShortcut = $_sShortcutName = "" ? False : True ;~ Desktop handle Local $hDesktopListview = ControlGetHandle("[CLASS:Progman]", "", "[CLASS:SysListView32;INSTANCE:1]") If @error Then Return SetError(1, 0) ;~ Desktop shortcut count Local $iShortcutCount = _GUICtrlListView_GetItemCount($hDesktopListview) If $iShortcutCount > 0 Then Local $aShortcutPos[$iShortcutCount][4] For $i = 0 To UBound($aShortcutPos, 1) - 1 If $bShortcut Then Dim $aShortcutPos[0][4] $sShortcutName = _GUICtrlListView_GetItemText($hDesktopListview, $i) If $sShortcutName = $_sShortcutName Then Dim $aShortcutPos[1][4] ;~ Desktop item name $aShortcutPos[0][0] = $sShortcutName ;~ Desktop item x position $aShortcutPos[0][1] = _GUICtrlListView_GetItemPositionX($hDesktopListview, $i) ;~ Desktop item y position $aShortcutPos[0][2] = _GUICtrlListView_GetItemPositionY($hDesktopListview, $i) ;~ Desktop item file type $aShortcutPos[0][3] = _GUICtrlListView_GetItemText($hDesktopListview, $i, 2) Return SetError((UBound($aShortcutPos) > 0 ? 0 : 1), 0, $aShortcutPos) EndIf Else $aShortcutPos[$i][0] = _GUICtrlListView_GetItemText($hDesktopListview, $i) $aShortcutPos[$i][1] = _GUICtrlListView_GetItemPositionX($hDesktopListview, $i) $aShortcutPos[$i][2] = _GUICtrlListView_GetItemPositionY($hDesktopListview, $i) $aShortcutPos[$i][3] = _GUICtrlListView_GetItemText($hDesktopListview, $i, 2) EndIf Next Else Return SetError(1, 0) EndIf Return SetError((UBound($aShortcutPos) > 0 ? 0 : 1), 0, $aShortcutPos) EndFunc Link to comment Share on other sites More sharing options...
Jemboy Posted June 10, 2022 Author Share Posted June 10, 2022 (edited) @SubzThe extension is only shown when the Explorer "Hide Extension" is disabled. I have added the following snippet to enabele "Show Extension" The change is only activated after the screen has been refreshed by sending a F5 via Controlsend. $RegKey="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" RegWrite($RegKey,"HideFileExt","REG_DWORD",0) ;0="how ext" 1="hide ext" ControlSend('Program Manager', '', '', '{F5}') The above only seems to works if it has been applied before running the script as an admin. Adding it to the admin script however give me an error. So I am relying on the third column you added and just look up the shortcut/file type. Edited June 10, 2022 by Jemboy Link to comment Share on other sites More sharing options...
Subz Posted June 10, 2022 Share Posted June 10, 2022 Does using the file type help (see last post)? You could also use _FileListToArray within _GetShortcutPos() to find all files with $sShortcutName & ".*" to get a list of files with same name, without changing the registry: Local $aShortcuts = _FileListToArrayRec(@DesktopCommonDir, $sShortcutName & ".*", 1, 0, 0) Jemboy 1 Link to comment Share on other sites More sharing options...
Jemboy Posted June 10, 2022 Author Share Posted June 10, 2022 Yes, using _FileListToArrayRec, will yield the shortcuts/files on the desktop, but it won't be matchable to the shortcut if there are more with the same name. E.g. if i have "accounting.docx" and "accounting.xlsx" on my desktop, both will be found as "accounting". The only possibility to match positions of the these files, seems to be using the type in Col3. Resp. "Micrsoft Office Word-Document" and "Micrsoft Office Excel-Document". The only drawback is that the file type language uses the installed Windows language (in my case Dutch), however all my computers have the Dutch Windows 10 installed, so that is not really a problem for me.@SubzWith your help, I have completed my program and for next stage, I am going to deploy it within my organization. Thanks. Link to comment Share on other sites More sharing options...
Jemboy Posted June 13, 2022 Author Share Posted June 13, 2022 For future users, beware. Moving an icon directly after creation seems to fail. The icon will not be found. To overcome this problem, I do a sleep(2500) after the schortcut creation, though on my cuurrent computers 2000ms seems enough wait. 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