Sign in to follow this  
Followers 0
MCP

Hide / Show Desktop Icons

12 posts in this topic

#1 ·  Posted (edited)

Have ever wanted to hide every desktop icon?

Now, two UDFs can do it for you, easily.

The only icons I am not able to move are some Windows special folders:

  • MyComputer
  • My Network Places
  • My Bluetooth Places
  • Recycle Bin
  • My Documents
If you have any idea on how to move them, too... It could be great!

Happy scripting.

#include <Misc.au3>
#include <A3LString.au3>
#include <A3LListView.au3>

WinMinimizeAll()
_HideDesktopIcons()
MsgBox(0,'OK','Everything should be clean on the desktop')
_ShowDesktopIcons()
MsgBox(0,'OK','Everything should be back on the desktop')
Exit

Func _HideDesktopIcons()
    Local $handle = ControlGetHandle('Program Manager', '', 'SysListView321')
    Local $iniDir = _GetIniDir(), _
            $iniName = _GetIniName(), _ 
            $ShortcutName, _
            $ShortcutPosition
    Local $iniFilepath = $iniDir & '\' & $iniName & '.ini' 
    
    FileDelete($iniFilepath)
    DirCreate($iniDir & '\User Desktop')
    DirCreate($iniDir & '\System Desktop')
    For $i = 0 To _ListView_GetItemCount ($handle) - 1
        $ShortcutPosition = _ListView_GetItemPosition ($handle, $i)
        $ShortcutName = _ListView_GetItemText ($handle, $i)
        IniWrite($iniFilepath, 'Last Positions', $ShortcutName, $ShortcutPosition[0] & '|' & $ShortcutPosition[1])
    Next
    _MoveDirContentToDir (@DesktopDir, $iniDir & '\User Desktop')
    _MoveDirContentToDir (@DesktopCommonDir, $iniDir & '\System Desktop')
EndFunc   ;==>_HideDesktopIcons

Func _ShowDesktopIcons()
    Local $iniDir = _GetIniDir(), _
            $iniName = _GetIniName(), _
            $ShortcutName
    
    Local $iniFilepath = $iniDir & '\' & $iniName & '.ini' 
    
    _MoveDirContentToDir ($iniDir & '\User Desktop', @DesktopDir)
    _MoveDirContentToDir ($iniDir & '\System Desktop', @DesktopCommonDir)
    
    Local $handle = ControlGetHandle('Program Manager', '', 'SysListView321'), _
            $cords, $ShortcutPosition
    _ListView_BeginUpdate ($handle)
    For $i = 0 To _ListView_GetItemCount ($handle)
        $ShortcutName = _ListView_GetItemText ($handle, $i)
        $cords = IniRead($iniFilepath, 'Last Positions', $ShortcutName, 'Unknown')
        $ShortcutPosition = StringSplit($cords, '|')
        
        If $cords <> 'Unknown'  Then
            _ListView_SetItemPosition32 ($handle, $i, $ShortcutPosition[1], $ShortcutPosition[2])
        Else
            IniDelete($iniFilepath, 'Last Positions', $ShortcutName)
        EndIf
    Next
    _ListView_EndUpdate ($handle)
EndFunc   ;==>_ShowDesktopIcons

Func _GetIniDir()
    Return @AppDataDir & '\My Program'
EndFunc

Func _GetIniName()
    Return 'My Program'
EndFunc

Func _MoveDirContentToDir($sSrc, $sDest)
    If Not FileExists($sDest) Then DirCreate($sDest)
    If Not FileExists($sSrc) Or Not FileExists($sDest) Or Not _IsDir($sSrc) Or Not _IsDir($sDest) Then Return False
    
    Local $nHandle = FileFindFirstFile($sSrc & '\*.*')
    If -1 == $nHandle Then Return False
    
    Local $sElement, $sDir, $sFile
    While 1
        $sElement = FileFindNextFile($nHandle)
        If @error Then ExitLoop
        If _IsDir($sSrc & '\' & $sElement) Then
            DirCreate($sDest & '\' & $sElement)
            DirMove($sSrc & '\' & $sElement, $sDest & '\' & $sElement, 1)  
        Else
            FileMove($sSrc & '\' & $sElement, $sDest & '\', 1+8)
        EndIf
    WEnd
    FileClose($nHandle)
    Return True
EndFunc

Func _IsDir($sTarget)
    Return _Iif(StringInStr(FileGetAttrib($sTarget), 'd', 0)>0, True, False)
EndFuncoÝ÷ Ø@ÈM:-+&zØhvØZ¶­²ÉhÁêÚ²Ø^²,Þ¡ûayø¥zË-¢·{ay׬Ú)º0±)ãi®âuçZ'ªè©ÝzW j{l¢[­í«H­êh®Ø^­æÞ¢·³'âا©Ý­çÞ­éÜy«­¢+Ù
½¹Ñɽ±!¥ ÅÕ½ÐíAɽɴ5¹ÈÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðím
1MM98éM!1111}Y¥ÜÅtÅÕ½Ðì¤)M±À ÔÀÀÀ¤)
½¹Ñɽ±M¡½Ü ÅÕ½ÐíAɽɴ5¹ÈÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðím
1MM98éM!1111}Y¥ÜÅtÅÕ½Ðì¤oÝ÷ Ù8^¦·¯¬)Þ±Ú-ëkÉ7Ü޶׫²n¶*'¶­(!¶Øn²Ö¤y©e¶¶«Ëayú%"!2-Â)e®éßw¨Ê&¦ë^¯­åÊÞv+)¬¢»-YZéä'¶­æ¬¢r,2¬xÖwhÂÄÚ²FÚ¬ú,بڲz-Âä§jÇ¢w]Êek(¬jÛZrêíêâ÷¬¶(*'²·ªº*Þu«­¢+Ø¥¹±Õ±Ðí5¥Í¹ÔÌÐììÉÅÕ¥Éä}%¥ ¤()}9Ùɹ¥¹1½½À ÄÀ¤()Õ¹}9Ùɹ¥¹1½½À ÀÌØí¸ôÔ¤(ÀÌØí¸¨ôÄÀ(]¡¥±Ä(M±À ÀÌØí¸¤(%}%Í5½ÕÍ%¹]¥¹½ÝÍQÍ­ÉA½Í¥Ñ¥½¸ ¤Q¡¸(}M¡½ÝͭѽÀ ¤(±Í(}!¥Í­Ñ½À ¤(¹%(]¹)¹Õ¹ìôôÐí}9Ùɹ¥¹1½½À()Õ¹}%Í5½ÕÍ%¹]¥¹½ÝÍQÍ­ÉA½Í¥Ñ¥½¸ ¤(1½°ÀÌØí5½ÕÍA½Ìô5½ÕÍÑA½Ì ¤(1½°ÀÌØí¹5`ôÀÌØí5½ÕÍA½ÍlÁt°ÀÌØí¹5dôÀÌØí5½ÕÍA½ÍlÅt((1½°ÀÌØíQÍ­ÉA½Ìô
½¹Ñɽ±ÑA½Ì ÅÕ½ÐíAɽɴ5¹ÈÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðím
1MM98éM!1111}Y¥ÜÅtÅÕ½Ðì¤(1½°ÀÌØí¹]Q    `ôÀÌØíQÍ­ÉA½ÍlÁt°ÀÌØí¹]Q   dôÀÌØíQÍ­ÉA½ÍlÅt°ÀÌØí¹]Q   ]¥Ñ ôÀÌØíQÍ­ÉA½ÍlÁt¬ÀÌØíQÍ­ÉA½ÍlÉt°ÀÌØí¹]Q    !¥¡ÐôÀÌØíQÍ­ÉA½ÍlÅt¬ÀÌØíQÍ­ÉA½ÍlÍt((IÑÕɸ}%¥  ÀÌØí¹5`ÐìôÀÌØí¹]Q  `¹ÀÌØí¹5`±ÐìôÀÌØí¹]Q ]¥Ñ ¤¹ ÀÌØí¹5dÐìôÀÌØí¹]Q   d¹ÀÌØí¹5d±ÐìôÀÌØí¹]Q !¥¡Ð¤°±Í°QÉÕ¤)¹Õ¹ìôôÐí}%Í5½ÕÍ%¹]¥¹½ÝÍQÍ­ÉA½Í¥Ñ¥½¸()Õ¹}!¥Í­Ñ½Á%½¹Ì ¤(
½¹Ñɽ±!¥ ÅÕ½ÐíAɽɴ5¹ÈÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðím
1MM98éM!1111}Y¥ÜÅtÅÕ½Ðì¤)¹Õ¹ìôôÐí}!¥Í­Ñ½Á%½¹Ì()Õ¹}M¡½ÝͭѽÁ%½¹Ì ¤(
½¹Ñɽ±M¡½Ü ÅÕ½ÐíAɽɴ5¹ÈÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðím
1MM98éM!1111}Y¥ÜÅtÅÕ½Ðì¤)¹Õ¹ìôôÐí}M¡½ÝͭѽÁ%½¹Ì()Õ¹}!¥]¥¹½ÝÍQÍ­È ¤(1½°ÀÌØí¹AÉÙ¥½ÕÍMÑÑô=ÁÐ Ìäí]¥¹Q¥Ñ±5Ñ¡5½Ìäì°Ð¤(]¥¹MÑMÑÑ ÅÕ½Ðí±Í͹µõM¡±±}QÉå]¹ÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°M]}!%¤(=ÁÐ Ìäí]¥¹Q¥Ñ±5Ñ¡5½Ìäì°ÀÌØí¹AÉÙ¥½ÕÍMÑѤ)¹Õ¹ìôôÐí}!¥]¥¹½ÝÍQÍ­È()Õ¹}M¡½Ý]¥¹½ÝÍQÍ­È ¤(1½°ÀÌØí¹AÉÙ¥½ÕÍMÑÑô=ÁÐ Ìäí]¥¹Q¥Ñ±5Ñ¡5½Ìäì°Ð¤(]¥¹MÑMÑÑ ÅÕ½Ðí±Í͹µõM¡±±}QÉå]¹ÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°M]}M!=¤(=ÁÐ Ìäí]¥¹Q¥Ñ±5Ñ¡5½Ìäì°ÀÌØí¹AÉÙ¥½ÕÍMÑѤ)¹Õ¹ìôôÐí}M¡½Ý]¥¹½ÝÍQÍ­È()Õ¹}!¥Í­Ñ½À ¤(]¥¹5¥¹¥µ¥é±° ¤(}!¥]¥¹½ÝÍQÍ­È ¤(}!¥Í­Ñ½Á%½¹Ì ¤)¹Õ¹ìôôÐí}!¥Í­Ñ½À()Õ¹}M¡½ÝͭѽÀ ¤(}M¡½Ý]¥¹½ÝÍQÍ­È ¤(}M¡½ÝͭѽÁ%½¹Ì ¤(]¥¹5¥¹¥µ¥é±±U¹¼ ¤)¹Õ¹ìôôÐí}M¡½ÝͭѽÀ

EDIT: Added the previous working sample

EDIT: Added, in the previous working sample, support for the taskbar position, that can be positioned anywhere (up,down,right,left)

EDIT: Removed an unused local variable in the previous sample

EDIT: Warning on computers running with multiple displays

Edited by MCP

Share this post


Link to post
Share on other sites



Nice very usefull thing....Thx <_<

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Have ever wanted to hide every desktop icon?

Now, two UDFs can do it for you, easily.

The only icons I am not able to move are some Windows special folders:

  • MyComputer
  • My Network Places
  • My Bluetooth Places
  • Recycle Bin
  • My Documents
If you have any idea on how to move them, too... It could be great!

Happy scripting.

Isn't it also possible to just use WinSetState("Program Manager") or whatever to hide all the icons?

RE: magician13134 Bah, why bring up something so fantastically simple when I just spent so long putting together a script for MCP's desktop stuff <_<

Const $MyComputer = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
Const $MyDocuments = "{450D8FBA-AD25-11D0-98A8-0800361B1103}"
Const $MyNetworkPlaces = "{208D2C60-3AEA-1069-A2D7-08002B30309D}"
Const $InternetExplorer = "{871C5380-42A0-1069-A2EA-08002B30309D}"
Const $RecycleBin = "{645FF040-5081-101B-9F08-00AA002F954E}"

Dim $MyCompSub1, $MyCompSub2, $MyDocsSub1, $MyDocsSub2, $MyNetSub1, $MyNetSub2, $IESub1, $IESub2, $RecBinSub1, $RecBinSub2

$rootkey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons"
$subkey1= "\ClassicStartMenu"
$subkey2= "\NewStartPanel"

_GetOriginalState()
_HideDesktopIcons()
Sleep(5000)
_ShowDesktopIcons()

Func _GetOriginalState()
    $MyCompSub1= _ReadIt($subkey1,$MyComputer)
    $MyCompSub2= _ReadIt($subkey2,$MyComputer)
    $MyDocsSub1 = _ReadIt($subkey1,$MyDocuments)
    $MyDocsSub2 = _ReadIt($subkey2, $MyDocuments)
    $MyNetSub1 = _ReadIt($subkey1, $MyNetworkPlaces)
    $MyNetSub2 = _ReadIt($subkey2, $MyNetworkPlaces)
    $IESub1 = _ReadIt($subkey1, $InternetExplorer)
    $IESub2 = _ReadIt($subkey2, $InternetExplorer)
    $RecBinSub1 = _ReadIt($subkey1, $RecycleBin)
    $RecBinSub2 = _ReadIt($subkey2,$RecycleBin)
EndFunc

Func _HideDesktopIcons()
    _WriteIt($subkey1,$MyComputer,"1")
    _WriteIt($subkey2,$MyComputer,"1")
    _WriteIt($subkey1,$MyDocuments,"1")
    _WriteIt($subkey2,$MyDocuments,"1")
    _WriteIt($subkey1,$MyNetworkPlaces,"1")
    _WriteIt($subkey2,$MyNetworkPlaces,"1")
    _WriteIt($subkey1,$InternetExplorer,"1")
    _WriteIt($subkey2,$InternetExplorer,"1")
    _WriteIt($subkey1,$RecycleBin,"1")
    _WriteIt($subkey2,$RecycleBin,"1")
    ControlSend("Program Manager","","","{F5}")
EndFunc

Func _ShowDesktopIcons()
    _WriteIt($subkey1,$MyComputer,$MyCompSub1)
    _WriteIt($subkey2,$MyComputer,$MyCompSub2)
    _WriteIt($subkey1,$MyDocuments,$MyDocsSub1)
    _WriteIt($subkey2,$MyDocuments,$MyDocsSub2)
    _WriteIt($subkey1,$MyNetworkPlaces,$MyNetSub1)
    _WriteIt($subkey2,$MyNetworkPlaces,$MyNetSub2)
    _WriteIt($subkey1,$InternetExplorer,$IESub1)
    _WriteIt($subkey2,$InternetExplorer,$IESub2)
    _WriteIt($subkey1,$RecycleBin,$RecBinSub1)
    _WriteIt($subkey2,$RecycleBin,$RecBinSub2)
    ControlSend("Program Manager","","","{F5}")
EndFunc

Func _ReadIt($sub,$valuename)
    $value = RegRead($rootkey & $sub, $valuename)
    If @error Then
        Return "0"
    Else
        Return $value
    EndIf
EndFunc

Func _WriteIt($sub,$destkey,$value)
    RegWrite($rootkey &$sub,$destkey,"REG_DWORD",$value)
EndFunc

Edit: Add in a "bah" for SmOke_N (see next post), too :) - very simple, very nice.

Edited by Monamo

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

RE: magician13134 Bah, why bring up something so fantastically simple when I just spent so long putting together a script for MCP's desktop stuff <_<

I posted this ... earlier this morning in his thread he started on it...

http://www.autoitscript.com/forum/index.php?showtopic=55801 (at the bottom)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Does this work with huge folders on the desktop? I have a folder thats 8GB.

Share this post


Link to post
Share on other sites

Does this work with huge folders on the desktop? I have a folder thats 8GB.

For that you'd wanna use something like SmOke_N's route, which simple hides the content instead of moving it to a temp storage location.

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

Thank you for messing up my very organized desktop ¬_¬

Share this post


Link to post
Share on other sites

Const $MyComputer = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
Const $MyDocuments = "{450D8FBA-AD25-11D0-98A8-0800361B1103}"
Const $MyNetworkPlaces = "{208D2C60-3AEA-1069-A2D7-08002B30309D}"
Const $InternetExplorer = "{871C5380-42A0-1069-A2EA-08002B30309D}"
Const $RecycleBin = "{645FF040-5081-101B-9F08-00AA002F954E}"
...
Thank you!

Share this post


Link to post
Share on other sites

Thank you for messing up my very organized desktop ¬_¬

<_< Oooops....

Share this post


Link to post
Share on other sites

Func _GetIniDir()
    Return @AppDataDir & '\My Program'
EndFunc

Func _GetIniName()
    Return 'My Program'
EndFunc

I'm not sure about having functions like that in your code... seems rather pointless.

Good work on what you have now. <_<


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

Func _GetIniDir()
         Return @AppDataDir & '\My Program'
     EndFunc
     
     Func _GetIniName()
         Return 'My Program'
     EndFunc

I'm not sure about having functions like that in your code... seems rather pointless.

Well, I use them to have a single point to look at for any path change and when the application gets large enough to be overwhelming it helps me a lot.

Good work on what you have now. <_<

Thank you.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0