Locking Drive Content

by Jun 12, 2012

In a previous tip we showed how you can hide drive letters in Windows Explorer. You may have discovered, though, that a user can still open files and folders on hidden drives if he knows the path.

So here's a very similar function. It will not hide drive letters but prohibit access to drive content. You need administrative privileges to set this setting.

function Hide-DriveContent {

    $key = @{
        Path = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer'
        Name = 'NoViewOnDrive'

    if ($DriveLetter -eq $null) {
        Remove-ItemProperty @key
    } else {
        $mask = 0
        $DriveLetter | 
            ForEach-Object { $_.toUpper()[0] } |
            Sort-Object |
            ForEach-Object { $mask += [Math]::Pow(2,(([Byte]$_) -65)) }

        Set-ItemProperty @key -Value $mask -type DWORD

Use the function like so:

PS> Hide-DriveContent D,Z    # prohibits access to drives D: and Z:
PS> Hide-DriveContent    # removes all restrictions

Log off and on again, or kill explorer.exe for changes to take effect.

Twitter This Tip! ReTweet this Tip!