Solved

Logoff script to delete drive mappings

Posted on 2010-09-01
4
804 Views
Last Modified: 2012-06-27
I am trying to make a logoff script to remove all drive mappings other than the user drive (U:). This is so that I can ensure that any user created mappings are deleted.

My script fails when a drive mapping does not exist and does not move on to the next one.

Can anyone help?

Thanks
Dim wshNetwork, wshShell



on error resume next





Disconnect()





Sub Disconnect()



Set wshNetwork = WScript.CreateObject("WScript.Network")

    wshNetwork.RemoveNetworkDrive "e:"

    wshNetwork.RemoveNetworkDrive "g:"

    wshNetwork.RemoveNetworkDrive "i:"

    wshNetwork.RemoveNetworkDrive "j:"

    wshNetwork.RemoveNetworkDrive "k:"

    wshNetwork.RemoveNetworkDrive "l:"

    wshNetwork.RemoveNetworkDrive "m:"

    wshNetwork.RemoveNetworkDrive "n:"

    wshNetwork.RemoveNetworkDrive "o:"

    wshNetwork.RemoveNetworkDrive "p:"

    wshNetwork.RemoveNetworkDrive "q:"

    wshNetwork.RemoveNetworkDrive "r:"

    wshNetwork.RemoveNetworkDrive "s:"

    wshNetwork.RemoveNetworkDrive "t:"

    wshNetwork.RemoveNetworkDrive "v:"

    wshNetwork.RemoveNetworkDrive "w:"

    wshNetwork.RemoveNetworkDrive "x:"

    wshNetwork.RemoveNetworkDrive "y:"

    wshNetwork.RemoveNetworkDrive "z:"



End sub

Open in new window

0
Comment
Question by:aideb
  • 2
4 Comments
 
LVL 34

Assisted Solution

by:Shreedhar Ette
Shreedhar Ette earned 50 total points
Comment Utility
Hi,

Refer this:
http://www.computerperformance.co.uk/Logon/Logon_Remove.htm

Hope this helps,
Shree
0
 
LVL 25

Assisted Solution

by:Tony1044
Tony1044 earned 250 total points
Comment Utility
Try adding this in front of each remove line:

if objfso.DriveExists("R:") wshNetwork.RemoveNetworkDrive "r:"


0
 
LVL 25

Assisted Solution

by:Tony1044
Tony1044 earned 250 total points
Comment Utility
Sorry - forgot to define objFSO for you:

Set objFSO = CreateObject("Scripting.FileSystemObject")
0
 
LVL 3

Accepted Solution

by:
bobalob earned 200 total points
Comment Utility
Also you can check drive type on the fly with objFSO.GetDrive("X:").DriveType, 3 being a network map.

Example code attached.
On Error Resume Next

Dim objDrive

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim wshNetwork: Set wshNetwork = WScript.CreateObject("WScript.Network")



For i = Asc("F") to Asc("Z")

	if i <> Asc("U") then ' Ignore U: drive

		if objFSO.DriveExists(chr(i)) then 

			Set objDrive = objFSO.GetDrive(chr(i))

			if objDrive.DriveType = 3 then ' Network drive

				wshNetwork.RemoveNetworkDrive chr(i) & ":", true

			end if

		end if

	end if

Next

Set objDrive = Nothing

Set objFSO = Nothing

Set wshNetwork = Nothing

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Use email signature images to promote corporate certifications and industry awards.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now