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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP! If Exists- remove drive code!

Status
Not open for further replies.

bran2235

IS-IT--Management
Feb 13, 2002
703
US
Hello everyone,

Newby to VBS sorta...
All I want to do is check to see if a drive exists (already mapped), and if so, remove it... if it doesn't exist, then continue on...

I don't want to remove ALL DRIVES because their HOME DIR is needed...

Here's my code:

============================================
On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

If objnetwork.DriveExists("Z:") Then
objnetwork.RemoveNetworkDrive "Z:", True, True
Sleep 300

'then depending on group membership either map drives or printers

Select Case strGroupName
Case "UserGroup1"
objNetwork.AddWindowsPrinterConnection "\\Server\Printer"
objNetwork.RemoveNetworkDrive "Y:", True, True
objNetwork.MapNetworkDrive "Y:", "\\Server\NewShare"

Case "PrinterGroup"
objNetwork.AddWindowsPrinterConnection "\\server\printer"

End Select
set objuser = Nothing
set objnetwork = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
'Quit the Script
wscript.quit

==========================================

Can anyone help me here?
I've checked the FAQs too!!

Brandon
 
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
if objFSO.folderexists("Y:") then
   'do something
Else
   ' do something else
End If

Does that hit the target?

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, and so on)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top