-2

We need to disconnect and re-map a network drive on Windows 7, using a set of scripts (or an app) that runs off the same network path.

That is, I need something that loads itself into RAM before it runs, so it continues to run after the drive is disconnected.

Any ideas?

sentinel23
  • 51
  • 3
  • 6
  • more info.... mapping/unmapping is simple in a batch file, for example: NET USE L: \\SERVER\DRIVESHARENAME /PERSISTENT – T McKeown Jan 03 '14 at 17:23
  • Can you run the script using the UNC path `\\server\share\path\batchfile.bat`? Can you run it via a shortcut on the user's computer? If the answer is **no** both times, then you're going to run into issues with running anything from the network path and having that same process disconnect the network drive. Anything run from the network maintains a handle to the file on the network and Windows doesn't like to delete a mapped drive when handles are still open. if the answer is **yes** to either question, I have a few ideas... – James L. Jan 04 '14 at 09:17
  • @TMcKeown I know. Read the question again please. – sentinel23 Jan 06 '14 at 14:56
  • @JamesL. We could probably do it with a shortcut or a UNC path. We had a 16-bit Novell utility which actually worked to allow the users to run S:\batchfile.bat which disconnected and re-mapped S:\, but that doesn't work anymore. We're probably just going to have to move it to another server. – sentinel23 Jan 06 '14 at 14:59
  • If you are using Windows as indicated by the TAGS then why can't you use Windows commands to remap the drive? – foxidrive Jan 16 '14 at 04:41

2 Answers2

1

Please note that 16-bit apps are NOT supported in 64 bit systems (this explains why the Novell utility failed).

You would need a vbs file running throughout a logon session to remap drives if it's disconnected by user. Need to make this script to run when domain user logs on - e.g. Logon Script in AD or GPO. There are many ways to do it.

You could even disable "Remove Network drives" feature from Explorer GUI via GPO or Reg key (net use command still works).

Or you can tweak solution by Julius for this SO question to fit your need. But consider performance impact of the vbs - only check every n minute(s) in an infinite loop.

Community
  • 1
  • 1
PatricK
  • 6,375
  • 1
  • 21
  • 25
1

We do something similar. We have a batch file on the network that maps the drives a user needs. We update the batch file from time to time, and users run it from a shortcut that we've placed on their desktop:

C:\WINDOWS\system32\cmd.exe /c (@echo off&if not exist \\172.x.x.x\Login (echo Unable to access server&pause) else (md c:\TMP > NUL 2>&1 &copy \\172.x.x.x\Login\MapDrives.bat C:\TMP /y > NUL 2>&1 &call C:\TMP\MapDrives.bat&del C:\TMP\MapDrives.bat&rd c:\TMP))

You can see that it checks to see if they can access the server, and if they can, it creates a folder C:\TMP, copies the MapDrives.bat file locally, then runs it. Since it is running locally, it can remap network drives without terminating it own execution. And we can update the batch file on the server without pushing it to each user's computer.

If you don't want to create a shortcut with the long command line above, it might work to create a second batch file on the server (e.g., RunMe.bat) that users run from the server. You could place all of the code from the shortcut in the RunMe.bat and accomplish the same thing. Of course, you'd want to add one more line of code to change to the local drive (so Windows doesn't hold open a handle to the network drive). Something like this:

@echo off
C:
if not exist \\172.x.x.x\Login\MapDrives.bat (
  echo Unable to access server
  pause
) else (
  md c:\TMP > NUL 2>&1
  copy \\172.x.x.x1\Login\MapDrives.bat C:\TMP /y > NUL 2>&1
  C:\TMP\MapDrives.bat
)

I kept the if not exist ... because you might place the RunMe.bat in a different location than the MapDrives.bat, so it still makes sense to verify the user can access the file. Because I didn't use call C:\TMP\MapDrives.bat, it transfers control to the local batch file and any handles to the server should be closed so the drive can be remapped. This means however, that you cannot place more commands after the C:\TMP\MapDrives.bat command.

James L.
  • 9,384
  • 5
  • 38
  • 77