Jump to content

Issue deleting MountedDevices registry entries


aleph01
 Share

Recommended Posts

This script doesn't seem to be doing it:

#RequireAdmin

For $i = 1 To 100
    $sVar = RegEnumVal("HKEY_LOCAL_MACHINE\System\MountedDevices", $i)
    If @error <> 0 Then ExitLoop
    RegDelete("HKEY_LOCAL_MACHINE\System\MountedDevices", $sVar)
    Sleep (101)
Next

The above script apparently has no affect.  Setting is a library.  When the MountedDevices list becomes large (due to patrons using thumb drives) it seemingly becomes corrupted and Windows stops recognizing USB drives.  Clearing the list manually  resolves the issue.  Now I would like to automate the process.  Does anyone see my error?  I'm running this on my laptop where I am an administrator.  The script runs, but no registry deletions occur.

Thanks,

Edited by aleph01

Meds.  They're not just for breakfast anymore. :'(

Link to comment
Share on other sites

For future reference:

I was mistaken.  The above code doesn't work as intended.  It runs into the same problem as any For...Next loop with a line Delete function.  If it counts forward from 1 to 500, deleting as it goes, the even numbered lines in the original list don't get deleted because the list scrolls up as items are deleted.  Instead of reworking it to place the mounted devices in an array and using UBound to get the size of the array and then loop backward, I chose a much simpler route.  I use a script run under my user's account to RunAs a script that does the registry manipulation.  That script is

RegDelete("HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices")
Sleep (1001)
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices")

After running, my MountedDevices list consists of the default entry only and Windows is able to recognize USB drives.

Thanks

Meds.  They're not just for breakfast anymore. :'(

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...