Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

-ComObject WScript.Network doesn't remove drives mapped with VBScript.

Status
Not open for further replies.

DTracy

Programmer
Feb 20, 2002
844
US
This function doesn't remove drives that were mapped using vbscript. Why?

#
# Function RemoveMappedDrives() -->
#
FUNCTION RemoveMappedDrives{
# ---------------------------------------------------------------------
PROCESS{
$oNet = New-Object -ComObject WScript.Network
$n1 = 0
$cDrive = ""

# Remove only drives mapped F-Z to network.
FOR ( $n1 = 70; $n1 -lt 91; $n1 ++ )
{
# Debug write-host "n1= " $n1
$cDrive = [char]$n1 + ":"
IF( $oNet.EnumNetworkDrives() -contains $cDrive )
{
# Debug write-host "$cDrive= " $cDrive
$oNet = New-Object -ComObject WScript.Network
$oNet.RemoveNetworkDrive( $cDrive, $True )
}
}
Start-Sleep -m 500
} #end process
} #end removemappeddrives.


Thanks,
David.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top