Would like to convert this remove printer [part of script] to do the same thing, but for network drives.

I have a sub that removes all the network printers connected to our file and print server.  I have another section in the login script that removes network drives.  However, the network drives part isn't a sub, and its 'clunky'.  I am going thru the script and trying to clean things up, and what I'm looking for, is some assitance in converting the removeal of the network drives, and adding it in similar to the removeal of the network printers.  Any help in this matter is greatly appreciated, as I've been recently tasked with making the scripting changes, so I'm trying to learn as much as I can as quickly as I can, who loves a crash course!?!?!  Thanks again!
Set objNetwork = CreateObject("WScript.Network") 
On Error Resume Next
	objNetwork.RemoveNetworkDrive "H:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "J:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "K:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "M:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "P:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "Q:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "S:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "T:", _
	bforce, bUpdateProfile
 
RemovePrintersFromServer "ugmpdc"
 
sub RemovePrintersFromServer(sServerName)
    dim oPrinters, aPrinter
    if bolWriteLog then objLogFile.WriteLine(Now() & ": Removing all printers from: " & ucase(sServerName))
    Set oPrinters = objNetwork.EnumPrinterConnections
    For iLoop = 0 to oPrinters.Count - 1 Step 2
        on error resume next
            aPrinter = split(uCase(oPrinters.Item(iLoop+1)),"\",-1, 1)  '"
            if not UBound(aPrinter) = 0 then 'this is not a local printer, process code
                if aPrinter(2) = ucase(sServerName) then
                    objNetwork.RemovePrinterConnection oPrinters.Item(iLoop+1), true, true
                    If Err.Number = 0 Then
                        if bolWriteLog then objLogFile.WriteLine(Now() & ": Success: Remove printer: " & oPrinters.Item(iLoop+1))
                    else
                        if bolWriteLog then objLogFile.WriteLine(Now() & ": Failed:  Remove printer: " & oPrinters.Item(iLoop+1))
                    end if
                end if
            end if
        aPrinter = ""
        on error goto 0
    next
    if bolWriteLog then objLogFile.WriteLine(Now() & ": Removed  all printers from: " & ucase(sServerName))
end sub

Open in new window

ugm-itAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

exx1976Commented:
Like this?

removeNetworkDrives
RemovePrintersFromServer "ugmpdc"
 
sub RemovePrintersFromServer(sServerName)
    dim oPrinters, aPrinter
    if bolWriteLog then objLogFile.WriteLine(Now() & ": Removing all printers from: " & ucase(sServerName))
    Set oPrinters = objNetwork.EnumPrinterConnections
    For iLoop = 0 to oPrinters.Count - 1 Step 2
        on error resume next
            aPrinter = split(uCase(oPrinters.Item(iLoop+1)),"\",-1, 1)  '"
            if not UBound(aPrinter) = 0 then 'this is not a local printer, process code
                if aPrinter(2) = ucase(sServerName) then
                    objNetwork.RemovePrinterConnection oPrinters.Item(iLoop+1), true, true
                    If Err.Number = 0 Then
                        if bolWriteLog then objLogFile.WriteLine(Now() & ": Success: Remove printer: " & oPrinters.Item(iLoop+1))
                    else
                        if bolWriteLog then objLogFile.WriteLine(Now() & ": Failed:  Remove printer: " & oPrinters.Item(iLoop+1))
                    end if
                end if
            end if
        aPrinter = ""
        on error goto 0
    next
    if bolWriteLog then objLogFile.WriteLine(Now() & ": Removed  all printers from: " & ucase(sServerName))
end Sub
 
 
Sub removeNetworkDrives
	Set objNetwork = CreateObject("WScript.Network") 
	On Error Resume Next
	objNetwork.RemoveNetworkDrive "H:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "J:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "K:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "M:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "P:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "Q:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "S:", _
	bforce, bUpdateProfile
	objNetwork.RemoveNetworkDrive "T:", _
	bforce, bUpdateProfile
End Sub

Open in new window

0
ugm-itAuthor Commented:
Well...  Kinda...  More like attached code.  Granted, this prolly wouldn't work.  Because I don't know how to specify individual drive letters, however...  I wouldn't mind if it just looped thru the alphabet and removed any network drives it came across.  If that is possible.
sub RemoveNetworkDrives
    dim oNetworkDrive, aNetworkDrive
    if bolWriteLog then objLogFile.WriteLine(Now() & ": Removing all Network Drives")
    Set oNetworkDrive = objNetwork.EnumNetworkDriveConnections
    For iLoop = 0 to oNetworkDrive.Count - 1 Step 2
        on error resume next
            aNetworkDrive = split(uCase(oNetworkDrive.Item(iLoop+1)),"\",-1, 1)  '"
            if not UBound(aNetworkDrive) = 0 then
                if aNetworkDrive(2) = ucase(??WHATSHOULDGOHERE??) then
                    objNetwork.RemoveNetworkDrives oNetworkDrive.Item(iLoop+1), true, true
                    If Err.Number = 0 Then
                        if bolWriteLog then objLogFile.WriteLine(Now() & ": Success: Removed network drive: " & oNetworkDrive.Item(iLoop+1))
                    else
                        if bolWriteLog then objLogFile.WriteLine(Now() & ": Failed:  Removeing network drive: " & oNetworkDrive.Item(iLoop+1))
                    end if
                end if
            end if
        aNetworkDrive = ""
        on error goto 0
    next
    if bolWriteLog then objLogFile.WriteLine(Now() & ": Removed  all network drives")
end Sub

Open in new window

0
ugm-itAuthor Commented:
Ok...  I feel bad now, haven't paid too much attention to my subs till now (like I said, found most of this stuff online, and still learning all this)

But it looks like it already removes the network drive, before attempting to connect the new (if applicable) network drive.  Am I correct in this?  If so, how would I go about changing it so that it just removed all the network drives, then omitting that part from the mapping a network drive (since they have all been removed already) from the following snippet.

Thanks again for your help...  AGAIN!  =]
Sub DriveMapper(sDrive, sShare)
    For iLoop = 0 to objDrives.Count -1 Step 2
    if LCase(sDrive) = LCase(objDrives.Item(iLoop)) then
        if not LCase(sShare) = LCase(objDrives.Item(iLoop+1)) then
            objNetwork.RemoveNetworkDrive sDrive, true, true
        Else
            if bolWriteLog then objLogFile.WriteLine(Now() & ": Success: Connect  """ & sDrive & """ to share """ & _
                sShare & """ (previously connected)")
            Exit Sub
        End if
    End if
    Next
    on error resume next
    objNetwork.MapNetworkDrive sDrive, sShare
    If Err.Number = 0 Then
        if bolWriteLog then objLogFile.WriteLine(Now() & ": Success: Connect  """ & sDrive & """ to share """ & sShare & """")
    else
        if bolWriteLog then objLogFile.WriteLine(Now() & ": Failed:  Connect """ & sDrive & """ to share """ & sShare & """")
    end if
    on error goto 0
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
exx1976Commented:
Indeed, it looks like line 5 of the code you just posted removes mappings before line 14 puts them back..

It's hard to be sure without the rest of the code, but that looks like it does what you want.

Glad to be of service...   Again!  :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.