Log in

No account? Create an account

Previous Entry | Next Entry

Gawd, I'm becoming a script geek...

It looks so ... simple!

strComputer = "."
strShareName = "\CID"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkConnection",,48)
For Each objItem in colItems
    strCompareString = Ucase(Right(objItem.RemotePath,Len(strShareName)))
    If strCompareString = strShareName Then
        Dim WshNetwork
        Set WshNetwork = WScript.CreateObject("WScript.Network")
        WshNetwork.RemoveNetworkDrive objItem.LocalName,True,True
    End if

Why did this (with comments) take two hours then! Well, because I'm learning. I think this is going to be much of my life here real soon, especially as I learn more and more how to do this. BTW, the above stript looks at all network mapped drives, looks for the last couple of characters, compares that to the search string (\CID), and if it matches, delete the drive. Of course, you knew that...

Okay, no more posts of code to my journal. If I feel I have to do this, I'll start a new journal.