Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Hide Drives from My Computer in Windows 7, Vista or XP


  • Please log in to reply
9 replies to this topic
Opie
  • Members
  • 101 posts
  • Last active: Feb 04 2011 08:55 PM
  • Joined: 02 Nov 2009
Something I threw together after I bought a SD card reader for dedicated ReadyBoost use in Windows 7-- I didn't want to see all the unused drives in My Computer, so this little util allows you to show or hide drives from view

sloppy code but it works :wink:


#NoEnv
#SingleInstance Force
menu tray, noicon
SetWorkingDir %A_ScriptDir%


alph := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alph_back := "ZYXWVUTSRQPONMLKJIHGFEDCBA"

Regread cur_nodrives, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoDrives
all_drives := cur_nodrives ? Bin(cur_nodrives) : "00000000"

gui font, s9 w400
gui add, text, x20 y13 , Check to show drive - Uncheck to hide:

xp := 30, yp = 40
loop parse, alph
{
	gui add, groupbox, % "x" xp-10 " y" yp-7 " w" 60 " h" 70
	gui add, picture, % "x" xp " y" yp+5 " vpic" a_loopfield " Icon9", C:\WINDOWS\system32\SHELL32.dll
	gui font, s23 w700
	gui add, text, % " cred x" xp+5 " y" yp+3 " vcrossout" a_loopfield " backgroundtrans", X
	gui, font, s9 w400
	guicontrol hide, crossout%a_loopfield%
	if ( substr(all_drives,0,1) == 1 )
	{
		%a_loopfield% := 0
		guicontrol show, crossout%a_loopfield%
	}
	else %a_loopfield% := 1
	stringtrimright all_drives, all_drives, 1   
	gui add, checkbox, % "x" xp + 5 " y" yp+40 " gchanged v" a_loopfield " checked" %a_loopfield%,% " " a_loopfield ":"  ;%
	xp := xp + 60
	if ( xp >= 400 )
		yp := yp + 65, xp = 30   
}
gui add, button, % "y" yp+40 " x" 360 " w85 h25 gapply", Apply   ;%
gui show, w460, Show Drive Letters
return


changed:
gui submit, nohide
guicontrol hide, crossout%a_guicontrol%
if ( %a_guicontrol% == 0 )
   guicontrol show, crossout%a_guicontrol%
   
new =
loop parse, alph_back
{
   if ( %a_loopfield% == 1 )
      new .= "0"
   else
      new .= "1"
}
SetFormat, Integer, H
new := Dec(new) 
SetFormat, Integer, D
new := substr(new,3)
return

apply:
; using reg file because I was having issues with RegWrite not actually writing values on Win7 machine ...
;  ... I think it has something to do with Administrative rights
fileappend,      
(
REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoDrives"=dword:%new%
),reg.reg
run regedit.exe /s reg.reg
sleep 250
while ( winexist("Registry Editor ahk_class #32770") )
   sleep 250
process close, explorer.exe 
sleep 350
run explorer.exe
filedelete reg.reg
return

GuiClose:
exitapp

Bin(x)         ; thanks to infogulch
{
   while x
      r:=1&x r,x>>=1
   return r
}

Dec(x)
{
   b:=StrLen(x),r:=0
   loop,parse,x
      r|=A_LoopField<<--b
   return r
}


Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
Very handy script
But it shows a whole list of letters even those that don't exist (not used), would be nice if you can make it detect that and show whats used.

Opie
  • Members
  • 101 posts
  • Last active: Feb 04 2011 08:55 PM
  • Joined: 02 Nov 2009

Very handy script
But it shows a whole list of letters even those that don't exist (not used), would be nice if you can make it detect that and show whats used.


I added it to the script -- thanks for the idea 8)

Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
One last bug I think, the apply button is on top of the last drive letter :D

Opie
  • Members
  • 101 posts
  • Last active: Feb 04 2011 08:55 PM
  • Joined: 02 Nov 2009
fixed?

i changed back to all drives as well

  • Guests
  • Last active:
  • Joined: --
Thanks nice! just a small thing ,if you abandon the registry change it will still kill explorer.

Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
I think you made it show all letters again, I edited a little part of your second post to fix button position, works, just one thing, how can you do this without windows crying messages?

#NoEnv
#SingleInstance Force
menu tray, noicon
SetWorkingDir %A_ScriptDir%

DriveGet alph, List
a_num := strlen(alph)
while ( a_num )
{   
   alph_back .= substr(alph,a_num,1)
   a_num--
}

Regread cur_nodrives, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoDrives
all_drives := cur_nodrives ? Bin(cur_nodrives) : "00000000"

gui font, s9 w400
gui add, text, x20 y13 , Check to show drive - Uncheck to hide:

xp := 30, yp = 40
loop parse, alph
{
   gui add, groupbox, % "x" xp-10 " y" yp-7 " w" 60 " h" 70
   gui add, picture, % "x" xp " y" yp+5 " vpic" a_loopfield " Icon9", C:\WINDOWS\system32\SHELL32.dll
   gui font, s23 w700
   gui add, text, % " cred x" xp+5 " y" yp+3 " vcrossout" a_loopfield " backgroundtrans", X
   gui, font, s9 w400
   guicontrol hide, crossout%a_loopfield%
   if ( substr(all_drives,0,1) == 1 )
   {
      %a_loopfield% := 0
      guicontrol show, crossout%a_loopfield%
   }
   else %a_loopfield% := 1
   gui add, checkbox, % "x" xp + 5 " y" yp+40 " gchanged v" a_loopfield " checked" %a_loopfield%,% " " a_loopfield ":"  ;%
   xp := xp + 60
   if ( xp >= 400 )
      yp := yp + 65, xp = 30   
   stringtrimright all_drives, all_drives, 1   
}
gui add, button, % "y" yp[color=red]+80[/color] " x" 370 " w85 h25 gapply", Apply   ;%
gui show, w460, Show Drive Letters
return


changed:
gui submit, nohide
guicontrol hide, crossout%a_guicontrol%
if ( %a_guicontrol% == 0 )
   guicontrol show, crossout%a_guicontrol%
   
new =
loop parse, alph_back
{
   if ( %a_loopfield% == 1 )
      new .= "0"
   else
      new .= "1"
}
SetFormat, Integer, H
new := Dec(new) 
SetFormat, Integer, D
new := substr(new,3)
return

apply:
; using reg file because I was having issues with RegWrite not actually writing values on Win7 machine ...
;  ... I think it has something to do with Administrative rights
fileappend,      
(
REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoDrives"=dword:%new%
),reg.reg
run reg.reg
sleep 250
while ( winexist("Registry Editor ahk_class #32770") )
   sleep 250
process close, explorer.exe    ; kill explorer to show immediate changes - xp/vista/win7 should restart it
sleep 350
filedelete reg.reg
return

GuiClose:
exitapp

Bin(x)         ; thanks to infogulch
{
   while x
      r:=1&x r,x>>=1
   return r
}

Dec(x)
{
   b:=StrLen(x),r:=0
   loop,parse,x
      r|=A_LoopField<<--b
   return r
}


emmanuel d
  • Members
  • 519 posts
  • Last active: Dec 28 2013 12:48 PM
  • Joined: 29 Jan 2009
No regedit msg:
#NoEnv
#SingleInstance Force
menu tray, noicon
SetWorkingDir %A_ScriptDir%

DriveGet alph, List
a_num := strlen(alph)
while ( a_num )
{   
   alph_back .= substr(alph,a_num,1)
   a_num--
}

Regread cur_nodrives, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoDrives
all_drives := cur_nodrives ? Bin(cur_nodrives) : "00000000"

gui font, s9 w400
gui add, text, x20 y13 , Check to show drive - Uncheck to hide:

xp := 30, yp = 40
loop parse, alph
{
   gui add, groupbox, % "x" xp-10 " y" yp-7 " w" 60 " h" 70
   gui add, picture, % "x" xp " y" yp+5 " vpic" a_loopfield " Icon9", C:\WINDOWS\system32\SHELL32.dll
   gui font, s23 w700
   gui add, text, % " cred x" xp+5 " y" yp+3 " vcrossout" a_loopfield " backgroundtrans", X
   gui, font, s9 w400
   guicontrol hide, crossout%a_loopfield%
   if ( substr(all_drives,0,1) == 1 )
   {
      %a_loopfield% := 0
      guicontrol show, crossout%a_loopfield%
   }
   else %a_loopfield% := 1
   gui add, checkbox, % "x" xp + 5 " y" yp+40 " gchanged v" a_loopfield " checked" %a_loopfield%,% " " a_loopfield ":"  ;%
   xp := xp + 60
   if ( xp >= 400 )
      yp := yp + 65, xp = 30   
   stringtrimright all_drives, all_drives, 1   
}
gui add, button, % "y" yp+80 " x" 370 " w85 h25 gapply", Apply   ;%
gui show, w460, Show Drive Letters
return


changed:
gui submit, nohide
guicontrol hide, crossout%a_guicontrol%
if ( %a_guicontrol% == 0 )
   guicontrol show, crossout%a_guicontrol%
   
new =
loop parse, alph_back
{
   if ( %a_loopfield% == 1 )
      new .= "0"
   else
      new .= "1"
}
SetFormat, Integer, H
new := Dec(new)
SetFormat, Integer, D
new := substr(new,3)
return

apply:
; using reg file because I was having issues with RegWrite not actually writing values on Win7 machine ...
;  ... I think it has something to do with Administrative rights
fileappend,     
(
REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoDrives"=dword:%new%
),reg.reg
run,regedit.exe /s reg.reg ; Run regedit with silent swich
sleep 250
while ( winexist("Registry Editor ahk_class #32770") )
   sleep 250
process close, explorer.exe    ; kill explorer to show immediate changes - xp/vista/win7 should restart it
sleep 350
filedelete reg.reg
return

GuiClose:
exitapp

Bin(x)         ; thanks to infogulch
{
   while x
      r:=1&x r,x>>=1
   return r
}

Dec(x)
{
   b:=StrLen(x),r:=0
   loop,parse,x
      r|=A_LoopField<<--b
   return r
}


emmanuel d
  • Members
  • 519 posts
  • Last active: Dec 28 2013 12:48 PM
  • Joined: 29 Jan 2009
For those that do want to try a regwrite(in xp works fine):
#NoEnv

#SingleInstance Force

menu tray, noicon

SetWorkingDir %A_ScriptDir%



DriveGet alph, List

a_num := strlen(alph)

while ( a_num )

{   

   alph_back .= substr(alph,a_num,1)

   a_num--

}



Regread cur_nodrives, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoDrives

all_drives := cur_nodrives ? Bin(cur_nodrives) : "00000000"



gui font, s9 w400

gui add, text, x20 y13 , Check to show drive - Uncheck to hide:



xp := 30, yp = 40

loop parse, alph

{

   gui add, groupbox, % "x" xp-10 " y" yp-7 " w" 60 " h" 70

   gui add, picture, % "x" xp " y" yp+5 " vpic" a_loopfield " Icon9", C:\WINDOWS\system32\SHELL32.dll

   gui font, s23 w700

   gui add, text, % " cred x" xp+5 " y" yp+3 " vcrossout" a_loopfield " backgroundtrans", X

   gui, font, s9 w400

   guicontrol hide, crossout%a_loopfield%

   if ( substr(all_drives,0,1) == 1 )

   {

      %a_loopfield% := 0

      guicontrol show, crossout%a_loopfield%

   }

   else %a_loopfield% := 1

   gui add, checkbox, % "x" xp + 5 " y" yp+40 " gchanged v" a_loopfield " checked" %a_loopfield%,% " " a_loopfield ":"  ;%

   xp := xp + 60

   if ( xp >= 400 )

      yp := yp + 65, xp = 30   

   stringtrimright all_drives, all_drives, 1   

}

gui add, button, % "y" yp+80 " x" 370 " w85 h25 gapply", Apply   ;%

gui show, w460, Show Drive Letters

return





changed:

gui submit, nohide

guicontrol hide, crossout%a_guicontrol%

if ( %a_guicontrol% == 0 )

   guicontrol show, crossout%a_guicontrol%

   

new =

loop parse, alph_back

{

   if ( %a_loopfield% == 1 )

      new .= "0"

   else

      new .= "1"

}

SetFormat, Integer, H

new := Dec(new)

SetFormat, Integer, D

new := substr(new,3)

return



apply:

; using reg file because I was having issues with RegWrite not actually writing values on Win7 machine ...

;  ... I think it has something to do with Administrative rights

   RegWrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Policies\Explorer,NoDrives,%new%

   process close, explorer.exe    ; kill explorer to show immediate changes - xp/vista/win7 should restart it

return



GuiClose:

exitapp



Bin(x)         ; thanks to infogulch

{

   while x

      r:=1&x r,x>>=1

   return r

}



Dec(x)

{

   b:=StrLen(x),r:=0

   loop,parse,x

      r|=A_LoopField<<--b

   return r

}
restarting explorer has no effect in xp for hiding the drive you might need to log off

  • Guests
  • Last active:
  • Joined: --

No regedit msg:

#NoEnv
#SingleInstance Force
menu tray, noicon
SetWorkingDir %A_ScriptDir%

DriveGet alph, List
a_num := strlen(alph)
while ( a_num )
{   
   alph_back .= substr(alph,a_num,1)
   a_num--
}

Regread cur_nodrives, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoDrives
all_drives := cur_nodrives ? Bin(cur_nodrives) : "00000000"

gui font, s9 w400
gui add, text, x20 y13 , Check to show drive - Uncheck to hide:

xp := 30, yp = 40
loop parse, alph
{
   gui add, groupbox, % "x" xp-10 " y" yp-7 " w" 60 " h" 70
   gui add, picture, % "x" xp " y" yp+5 " vpic" a_loopfield " Icon9", C:\WINDOWS\system32\SHELL32.dll
   gui font, s23 w700
   gui add, text, % " cred x" xp+5 " y" yp+3 " vcrossout" a_loopfield " backgroundtrans", X
   gui, font, s9 w400
   guicontrol hide, crossout%a_loopfield%
   if ( substr(all_drives,0,1) == 1 )
   {
      %a_loopfield% := 0
      guicontrol show, crossout%a_loopfield%
   }
   else %a_loopfield% := 1
   gui add, checkbox, % "x" xp + 5 " y" yp+40 " gchanged v" a_loopfield " checked" %a_loopfield%,% " " a_loopfield ":"  ;%
   xp := xp + 60
   if ( xp >= 400 )
      yp := yp + 65, xp = 30   
   stringtrimright all_drives, all_drives, 1   
}
gui add, button, % "y" yp+80 " x" 370 " w85 h25 gapply", Apply   ;%
gui show, w460, Show Drive Letters
return


changed:
gui submit, nohide
guicontrol hide, crossout%a_guicontrol%
if ( %a_guicontrol% == 0 )
   guicontrol show, crossout%a_guicontrol%
   
new =
loop parse, alph_back
{
   if ( %a_loopfield% == 1 )
      new .= "0"
   else
      new .= "1"
}
SetFormat, Integer, H
new := Dec(new)
SetFormat, Integer, D
new := substr(new,3)
return

apply:
; using reg file because I was having issues with RegWrite not actually writing values on Win7 machine ...
;  ... I think it has something to do with Administrative rights
fileappend,     
(
REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoDrives"=dword:%new%
),reg.reg
run,regedit.exe /s reg.reg ; Run regedit with silent swich
sleep 250
while ( winexist("Registry Editor ahk_class #32770") )
   sleep 250
process close, explorer.exe    ; kill explorer to show immediate changes - xp/vista/win7 should restart it
sleep 350
filedelete reg.reg
return

GuiClose:
exitapp

Bin(x)         ; thanks to infogulch
{
   while x
      r:=1&x r,x>>=1
   return r
}

Dec(x)
{
   b:=StrLen(x),r:=0
   loop,parse,x
      r|=A_LoopField<<--b
   return r
}


thanks for that

btw...

if you use the code with the drives detected, the drives wont be properly hidden. When rewriting the binary reg data (10001001001) it needs to be the whole alphabet -- thats why i reverted it back to "ABCDEFGHIJ.."

That could be the reason why you dont see the changes immediately...