Jump to content
Sign in to follow this  

Delete Network Connections without drive letters

Recommended Posts


There is a way to delete network connections without drive letters with DriveMapDel and the UNC path but is there any way to enumerate these connections so you know they are there to be deleted?

I'm working on upgrading my login scripts from a combination of batch and kix scripts and want to know how to duplicate the net use * /delete /yes command.

Deleting network connections that have drive letters assigned is easy via DriveGetDrive("NETWORK") but that doesn't get connections without drive letters.

Anyone have any options other than running net use * /delete /yes from comspec?



Share this post

Link to post
Share on other sites

Hmmm, can not test it because I don't have shares here :D, but maybe WMI could help you.

Compare the result with the result of DriveGetDrive("NETWORK") and delete those which are not assigned to a drive letter with "net use NAME /delete /yes".

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output &= "Computer: " & $strComputer  & @CRLF
$Output &= "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Share", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output &= "AccessMask: " & $objItem.AccessMask & @CRLF
      $Output &= "AllowMaximum: " & $objItem.AllowMaximum & @CRLF
      $Output &= "Caption: " & $objItem.Caption & @CRLF
      $Output &= "Description: " & $objItem.Description & @CRLF
      $Output &= "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output &= "MaximumAllowed: " & $objItem.MaximumAllowed & @CRLF
      $Output &= "Name: " & $objItem.Name & @CRLF
      $Output &= "Path: " & $objItem.Path & @CRLF
      $Output &= "Status: " & $objItem.Status & @CRLF
      $Output &= "Type: " & $objItem.Type & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Share" )

Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))

Share this post

Link to post
Share on other sites

Sounds like a suggestion for DriveMapDel("*") to me. I've recently run across a situation where that would have come in handy.

Share this post

Link to post
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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.