Script for Mapping drives in vb script

Hey guys i have a vbscript that i am currently using as logon script for a client. Right now this is the script that i am using(below) but instead of auto deleting and remapping the drives i want the script to check to see if the mapping is correct and if it is leave it alone but if it isnt correct then the script will delete and remap.
Any help would be graciously appreciated !!!

Option Explicit
On Error Resume Next
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemoveNetworkDrive "H:"
WshNetwork.RemoveNetworkDrive "I:"
WshNetwork.RemoveNetworkDrive "K:"
WshNetwork.MapNetworkDrive "H:", "\\win2003\USERS"
WshNetwork.MapNetworkDrive "I:", "\\win2003\COMMON"
WshNetwork.MapNetworkDrive "K:", "\\win2003\ACCOUNTING"
jjeffordsAsked:
Who is Participating?
 
star_trekConnect With a Mentor Commented:
  If CheckDrive.Item(intDrive) =strDriveLetter Then
              AlreadyConnected =True
     else
              WshNetwork.MapNetworkDrive "H:", "\\win2003\Users"
   end if
Next
0
 
star_trekCommented:
Following script checks if the drive is mapped or not.


Option Explicit
Dim strDriveLetter, strRemotePath
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
' The section sets the variables.
strDriveLetter = "H:"
strRemotePath = "\\server\drive"

' This sections creates two objects:
' objShell and objNetwork and counts the drives
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()

' See how it compares the enumerated drive letters with strDriveLetter
On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1
     If CheckDrive.Item(intDrive) =strDriveLetter Then
    AlreadyConnected =True
Next
0
 
jjeffordsAuthor Commented:
Does this also remap if they arent mapped?
I dont see where it does if i am correct in what i am seeing tell me if i am going down the right path. This is what i am thinking for the mapping of the drive letter H

Option Explicit
Dim strDriveLetter, strRemotePath
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
strDriveLetter = "H:"
strRemotePath = \\win2003\users
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()
On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1
     If CheckDrive.Item(intDrive) =strDriveLetter Then
    AlreadyConnected =True

Next

Option Explicit
On Error Resume Next
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "H:", "\\win2003\USERS"
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
star_trekCommented:
Option Explicit
Dim strDriveLetter, strRemotePath
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
strDriveLetter = "H:"
strRemotePath = \\win2003\users
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()
Set WshNetwork = WScript.CreateObject("WScript.Network")
On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1
     If CheckDrive.Item(intDrive) =strDriveLetter Then
              AlreadyConnected =True
     else
              WshNetwork.MapNetworkDrive "H:", "\\win2003\USERS"
Next
0
 
jjeffordsAuthor Commented:
When i run this script even locally on a machine this i get an error
The script is directly below and the error is under that.

SCRIPT
Option Explicit
Dim strDriveLetter, strRemotePath
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
strDriveLetter = "H:"
strRemotePath = \\win2003\users
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()
Set WshNetwork = WScript.CreateObject("WScript.Network")
On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1
     If CheckDrive.Item(intDrive) =strDriveLetter Then
              AlreadyConnected =True
     else
              WshNetwork.MapNetworkDrive "H:", "\\win2003\Users"
Next

ERROR
Line 6
Char 17
Error Syntax Error      
Code 800A03EA
Microsoft VBScript Compilation error
0
 
star_trekCommented:
it should be strRemotePath = "\\win2003\users"


Is this your homework question BTW?
0
 
jjeffordsAuthor Commented:
Homework question?  No
I know nothing about programming though at all.
I can write old batch files but i like using VBS in 2003 Server Group Policy. It is supposed to run more smoothly from what i have heard from my peers and on other forums.
0
 
jjeffordsAuthor Commented:
ERROR
Line 18
Char 1
Error Unexpected 'Next'
Code 800A041F
Microsoft VBScript Compilation error
0
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.

All Courses

From novice to tech pro — start learning today.