• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

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"
0
jjeffords
Asked:
jjeffords
  • 4
  • 4
1 Solution
 
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
 
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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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
 
star_trekCommented:
  If CheckDrive.Item(intDrive) =strDriveLetter Then
              AlreadyConnected =True
     else
              WshNetwork.MapNetworkDrive "H:", "\\win2003\Users"
   end if
Next
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now