#164096 - 2006-07-06 05:49 PM
Hide Drives Function - Maths Bofin Needed :-)
|
Richie19Rich77
Seasoned Scripter
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
Hi,
I have created a function that will hide drive depending on drive letter inputted via function.
Code:
Function HideDrive($Drive) Select Case $Drive = A $Hex = 1 Case $Drive = B $Hex = 2 Case $Drive = C $Hex = 4 Case $Drive = D $Hex = 8 Case $Drive = E $Hex = 16 Case $Drive = F $Hex = 32 Case $Drive = G $Hex = 64 Case $Drive = H $Hex = 128 Case $Drive = I $Hex = 256 Case $Drive = J $Hex = 512 Case $Drive = K $Hex = 1024 Case $Drive = L $Hex = 2048 Case $Drive = M $Hex = 4096 Case $Drive = N $Hex = 8192 Case $Drive = O $Hex = 16384 Case $Drive = P $Hex = 32768 Case $Drive = Q $Hex = 65536 Case $Drive = R $Hex = 131072 Case $Drive = S $Hex = 262144 Case $Drive = T $Hex = 524288 Case $Drive = U $Hex = 1048576 Case $Drive = V $Hex = 2097152 Case $Drive = W $Hex = 4194304 Case $Drive = X $Hex = 8388608 Case $Drive = Y $Hex = 16777216 Case $Drive = Z $Hex = 33554432 EndSelect $RegValue = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" WriteValue($RegValue,"NoDrives",Val($Hex) + Val(ReadValue($RegValue,"NoDrives")),"REG_DWORD")
EndFunction
For users that don't understand "NoDrive", I have included a quote from Microsoft.
Quote:
The "NoDrives" value uses a 32-bit word to define local and network drive visibility for each logical drive in the computer. The lower 26 bits of the 32-bit word correspond to drive letters A through Z. Drives are visible when set to 0 and hidden when set to 1.
If your not happy working in Hex, add these decimal numbers to hide the drive(s):
A: 1, B: 2, C: 4, D: 8, E: 16, F: 32, G: 64, H: 128, I: 256, J: 512, K: 1024, L: 2048, M: 4096, N: 8192, O: 16384, P: 32768, Q: 65536, R: 131072, S: 262144, T: 524288, U: 1048576, V: 2097152, W: 4194304, X: 8388608, Y: 16777216, Z: 33554432, ALL: 67108863
For example to hide drive A and drive D, you would add 1 (A) + 8 (D) which means the value should be set to "9".
To disable all the drives set the value to "67108863".
Now the problem with my function, is it cannot not detect if that drive is already hidden. So say my registry entry is set to 6 (B & C hidden), and I then say I want to hide drive C, it will add 2 to the registry value giving you a total of 8.
You see my problem.
Now if I was any good at maths, I could work out a procedure to say if registry = 8, then drives B & C must be hidden.
Hope this makes sence, and if anyone could come up with a bright idea ?
Thanks
Richard
Edited by Richie19Rich77 (2006-07-06 05:50 PM)
|
Top
|
|
|
|
#164100 - 2006-07-07 08:50 AM
Re: Hide Drives Function - Maths Bofin Needed :-)
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
This basically is also done by he GPO, you could edit %windir%\inf\system.adm to include the drives you want to hide or prevent access to.
Code:
POLICY !!NoDrives #if version >= 4 SUPPORTED !!SUPPORTED_Win2k #endif
EXPLAIN !!NoDrives_Help PART !!NoDrivesDropdown DROPDOWNLIST NOSORT REQUIRED VALUENAME "NoDrives" ITEMLIST NAME !!ABOnly VALUE NUMERIC 3 NAME !!COnly VALUE NUMERIC 4 NAME !!DOnly VALUE NUMERIC 8 NAME !!ABConly VALUE NUMERIC 7 NAME !!ABCDOnly VALUE NUMERIC 15 NAME !!ALLDrives VALUE NUMERIC 67108863 DEFAULT ; low 26 bits on (1 bit per drive) NAME !!RestNoDrives VALUE NUMERIC 0 END ITEMLIST END PART END POLICY
You can add as many drives as you want using the same hex codes. ABC would be 1 + 2 + 4 = 7 Keep in mind that every line you add to that that you also have to specify that in the [strings] section of the system.adm file.
|
Top
|
|
|
|
#164102 - 2006-07-07 10:48 AM
Re: Hide Drives Function - Maths Bofin Needed :-)
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
Stop the roaming profiles and go easy on GPO
Roaming is just DOG SLOW even on 100MB links. GPO are good for some things, but I think a lot of shops go HOG WILD with them and just plain slow user productivity to a crawl.
|
Top
|
|
|
|
#164103 - 2006-07-07 11:34 AM
Re: Hide Drives Function - Maths Bofin Needed :-)
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
Relocating the "My Documents" folder is not a Roaming profile, profiles remain local just the my documents folder is located on the server.
|
Top
|
|
|
|
#164105 - 2006-07-07 06:11 PM
Re: Hide Drives Function - Maths Bofin Needed :-)
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
Quote:
NO! Never ever edit the default ADMs. Create your own custom ADMs but leave the defaults as they are.
LOL!! this never failed me, unless there is a service pack update, but it would be wise to backup your original system.adm, off course you could be as paranoid as Les
|
Top
|
|
|
|
#164107 - 2006-07-07 06:54 PM
Re: Hide Drives Function - Maths Bofin Needed :-)
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
Quote:
Relocating the "My Documents" folder is not a Roaming profile, profiles remain local just the my documents folder is located on the server.
Yes I know that but a MANDATORY profile is much like a roaming profile in that it comes from a sever location as well - only the user doesn't get a choice on making any updates to it.
I was answering to both statements
|
Top
|
|
|
|
#164109 - 2006-07-17 12:06 PM
Re: Hide Drives Function - Maths Bofin Needed :-)
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
You don't need to convert to binary - if fact it's not very helpful.
Here is one way to do it, the example shows how to set the bits for drive letters M,N and O. The bitwise OR (|) ensures that the bit is set - you cannot set the bit more than once if you use bitwise operators. Code:
$dNoDrives=ReadValue(KEY,VALUE) $dNoDrives=$dNoDrives | udfDriveToDWORD("MNO") $=WriteValue(KEY,VALUE,$dNoDrives) Function udfDriveToDWORD($sDrives) $udfDriveToDWORD=0 While $sDrives $udfDriveToDWORD=$udfDriveToDWORD | Exp(2,ASC(UCase($sDrives))-ASC("A")) $sDrives=SubStr($sDrives,2) Loop EndFunction Function Exp($x,$y) $Exp=1 While $y>0 $Exp=$Exp*$x $y=$y-1 Loop EndFunction
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 507 anonymous users online.
|
|
|