Page 1 of 1 1
Topic Options
#164096 - 2006-07-06 05:49 PM Hide Drives Function - Maths Bofin Needed :-)
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 622
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
#164097 - 2006-07-06 05:56 PM Re: Hide Drives Function - Maths Bofin Needed :-)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
No real math needed, just a bitwise &. See this example:
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=81649&an=0&page=0#81649
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#164098 - 2006-07-06 06:04 PM Re: Hide Drives Function - Maths Bofin Needed :-)
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 622
Loc: London, England
Thanks Les, I will go through it and post a updated working function.

Thanks

Top
#164099 - 2006-07-06 07:30 PM Re: Hide Drives Function - Maths Bofin Needed :-)
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11557
Loc: CA
And here is a larger discussion on the subject that might prove helpful to you.


what is this binary not operand
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=146279
 
And a bit more on the subject

Help converting VBS code to KiXtat
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=158770

Top
#164100 - 2006-07-07 08:50 AM Re: Hide Drives Function - Maths Bofin Needed :-)
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1844
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
#164101 - 2006-07-07 09:57 AM Re: Hide Drives Function - Maths Bofin Needed :-)
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 622
Loc: London, England
Thanks for the replies, internet at home was down last night so haven't had a chance to look at it.

I know what NoDrive does, and we don't use GP's as they run like a snail on Windows 2000 when using mandatory profiles.

Top
#164102 - 2006-07-07 10:48 AM Re: Hide Drives Function - Maths Bofin Needed :-)
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11557
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_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1844
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
#164104 - 2006-07-07 02:35 PM Re: Hide Drives Function - Maths Bofin Needed :-)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

...you could edit %windir%\inf\system.adm...



NO!
Never ever edit the default ADMs. Create your own custom ADMs but leave the defaults as they are.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#164105 - 2006-07-07 06:11 PM Re: Hide Drives Function - Maths Bofin Needed :-)
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1844
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
#164106 - 2006-07-07 06:39 PM Re: Hide Drives Function - Maths Bofin Needed :-)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
One bitten, twice shy. Paranoia is just reality on a finer scale.
Unless you specifically turn off the feature, any admin that touches a GPO will replace the ADMs on sysvol if they have newer ones. If you modify an ADM it will have a newer date and it WILL replace every GPO you touch. I had a French admin screw up my GPOs because he modified his ADMs and his French ADMs overwrote mine.

When MS updates the ADMs through a newer OS or SP, they too will (may) automagically overwrite your custom ADMs. Laugh if you will at my paranoia but I might have the last laugh.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#164107 - 2006-07-07 06:54 PM Re: Hide Drives Function - Maths Bofin Needed :-)
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11557
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
#164108 - 2006-07-08 09:42 PM Re: Hide Drives Function - Maths Bofin Needed :-)
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 622
Loc: London, England
OK I am really stuck trying to get my head around this,

I have a login script that maps drives depending on service, so if user is part of that security group and the client software is installed locally then the drive is mapped.

Say that drive for the application uses drive O:, so my function will add "16384" to the "NoDrives" REG_DWORD within the registry and the drive is now hidden.

But say I have another service that also uses drive O:, and I use my function again, it will add "16384" to the "NoDrives" REG_DWORD and I will end up with a total of 32768.

I have no error checking within my function, to check if drive O: is aready hidden.

Is there a way to convert the "NoDrives" REG_DWORD value into binary.

Say drive O: was hidden the binary would be: 00000000000100000000000000.

From this I could split the binary into array, and check each drive to see if it was hidden or not.

I hope this makes more sence.

The binary layout will allways be a 26 bit.
Thanks

Top
#164109 - 2006-07-17 12:06 PM Re: Hide Drives Function - Maths Bofin Needed :-)
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
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
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 177 anonymous users online.
Newest Members
dboozcruise, 2786707460, Marc57, EricMyers, siddharthinfosy
17519 Registered Users

Generated in 0.127 seconds in which 0.076 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org