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)