ReMapping Network Drive using VBS Script

Hello All,

I am a new system admin and this is my first job. I have been tasked to delete and remap the network drive in our network. So, please advise how to Removes network drives P (10.10.10.4)and then map new network drives P (10.10.10.11) I am using the below VBS Script to achieve the task.

Please find the below script for your reference:

Option Explicit 
Dim objNetwork, objShell 
Dim strDriveLetter, strNetworkPath, strExplorer 
strDriveLetter = "P:" 
strNetworkPath = "\\10.10.10.4\data" 
Set objNetwork = CreateObject("WScript.Network") 
‘ Section which removes strDriveLetter 
objNetwork.MapNetworkDrive strDriveLetter, strNetworkPath 
Set objShell = CreateObject("WScript.Shell") 
strExplorer = "Explorer" & " " & strDriveLetter 
objShell.run (strExplorer) 
Wscript.Quit 
‘ End of Script
Dim objNetwork, strDriveLetter 
strDriveLetter = "P:" 
strNetworkPath = "\\10.10.10.11\data" 
Set objNetwork = CreateObject("WScript.Network") 
‘ Section which removes strDriveLetter 
objNetwork.RemoveNetworkDrive strDriveLetter 
Wscript.Quit

Thanks for your help and much greatly appreciated.

1 Like

Hi @afzal,

Why are you trying to map the network drive using VBS Script. It will be very easier if you use CMD command like below to delete the existing drive and connect the new one.

This command will delete the existing drive
Net use q: /del

This command will map the new drive
Net use q: \\10.10.10.11\data

If you are in a domain environment I would recommend using Group Policy Preference to map the drive. Using scripts to manage drive mappings has been deprecated since Group Policy Preferences were released and also the use of VBscript is being deprecated now.

So, Group Policy is the recommended method for this use case.

I hope this helps let me know if you have any clarifications

1 Like

Hello @afzal
As @tjnihal Sujested you can use net use cammand
example net use X: \IP address\share folder

1 Like

hmm… Why do you want non team members to have access? That seems like what you would use the main Google Drive for?

As for all team members have full control - I’m guessing that goes to a general thinking that this is used by the team for the team, nothing should be here that’s not full access for all team members - right or wrong - it’s just one way of doing things.

here is the detailed answer :