Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 753
  • Last Modified:

Getting past net use: i: /delete

I am trying to setup a login script to map an I: drive.

I have used this in the past with no problem:
@echo off
net use I: /delete
net use I: \\server1\share1

I will get "the network connection could not be found" if there is no mapping already. If there is a mapping that does exist for the I drive, it will not disconnect it and reconnect the new one to \\server1\share1.

Is there a way first delete a network drive and get past any errors if it's not already mapped so that the mapping can continue?





0
Ponthecomputer
Asked:
Ponthecomputer
3 Solutions
 
JustWorkingCommented:
I have seen that happen when a drive is in "disconnected" state otherwise it should work and continue on.
At the begining of your script delete all mapped drives first just incase?

net use * /delete
net use /persistent:no
net use I: \\server1\share1
0
 
MiahmichnoCommented:
Or in VBS if you prefer.
This will remove all drives then add then back

On Error Resume Next
      Set objNetwork = CreateObject("Wscript.Network")
      Set colDrives = objNetwork.EnumNetworkDrives
      For i = 0 to colDrives.Count-1 Step 2
            objNetwork.RemoveNetworkDrive colDrives.Item(i)
      Next
      objNetwork.MapNetworkDrive "i:" , "\\server1\share1"
      objNetwork.MapNetworkDrive "j:" , "\\server2\share2"
0
 
Lukasz ChmielewskiCommented:
or

if EXIST l: "net use I: /delete"
net use I: \\server1\share1
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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