Solved Make a Mapped Drive persistent so that it restores every time you reboot

kengooch

Member
Local time
Today, 06:57
Joined
Feb 29, 2012
Messages
137
I have an Excel Macro that Maps several drives automatically. However, every time the computer reboots, they disappear. I noted that a manual mapping of the drives there is a box to select to "Reconnect at Signin" Is there a VBA command that allows us to select that option?
 
You could probably use the Shell command to execute a Net Use command with the /persistent: yes switch.

 
The other alternative is to recognize that drive letter mapping is normally a Windows function and therefore would need to use Win32 API calls or a more modern equivalent. VBA could do the mapping but it is FAR better to let Windows make it persistent with that "Reconnect at Sign-in" option.
 
The other alternative is to recognize that drive letter mapping is normally a Windows function and therefore would need to use Win32 API calls or a more modern equivalent. VBA could do the mapping but it is FAR better to let Windows make it persistent with that "Reconnect at Sign-in" option.
Exactly... but how do I use VBA to tell the "Reconnect at Sign-in" box to be checked?
 
I'd be using theDBguy's method
 


The first link shows SHELL commands you could issue to do the reconnect.
The second link does a reconnect in VBA. The properties you want for "reconnect at sign-in" might be exposed from the WScript library. The article shows the reconnect but not how to set the properties.

But I have a logic question. Why do you want to bother with VBA for this? It would seem to me that you don't NEED to use VBA because the drive would reconnect at subsequent sign-in anyway? In which case this code wouldn't run, or would actually lead to a conflict, and its original use would represent a one-off usage. Is a one-off that important?
 
MapNetworkDrive command with the appropriate argument value
 


The first link shows SHELL commands you could issue to do the reconnect.
The second link does a reconnect in VBA. The properties you want for "reconnect at sign-in" might be exposed from the WScript library. The article shows the reconnect but not how to set the properties.

But I have a logic question. Why do you want to bother with VBA for this? It would seem to me that you don't NEED to use VBA because the drive would reconnect at subsequent sign-in anyway? In which case this code wouldn't run, or would actually lead to a conflict, and its original use would represent a one-off usage. Is a one-off that important?
When our organization runs MS updates, they have a script that disconnects all mapped drives except P: and U:. Not sure why they do this, but they do, so I wrote a VBA script in an Excel Workbook that users can run. It hides excel, pops up a menu and offers them a chance to map any of 5 drives.
 
Thanks for everyone's help! The key was telling the drives to reconnect at login. That works great. There doesn't seem to be a way to overcome the organizations reset of drives.
 
Ah, yes, the cumbersome nature of a "helpful" IT staff. Glad you got it working.
 
There doesn't seem to be a way to overcome the organizations reset of drives.

You could run your script daily, with a check of whether drive letter "G" is already in use. If not, it probably got wiped out by your very faithful IT department.

Like this:
Code:
Function ReportDriveStatus(drv)
   Dim fso, msg
   Set fso = CreateObject("Scripting.FileSystemObject")
   If fso.DriveExists(drv) Then
      msg = "true"
   Else
      msg = "false"
   End If
   ReportDriveStatus = msg
End Function
(one of the lesser used but incredibly useful functions of Scripting.FileSystemObject)

more code:
Code:
If ReportDriveStatus("a")="false" then...........
 
You could run your script daily, with a check of whether drive letter "G" is already in use. If not, it probably got wiped out by your very faithful IT department.

Like this:
Code:
Function ReportDriveStatus(drv)
   Dim fso, msg
   Set fso = CreateObject("Scripting.FileSystemObject")
   If fso.DriveExists(drv) Then
      msg = "true"
   Else
      msg = "false"
   End If
   ReportDriveStatus = msg
End Function
(one of the lesser used but incredibly useful functions of Scripting.FileSystemObject)

more code:
Code:
If ReportDriveStatus("a")="false" then...........
That is a good thought! What I do now, is I have added code to verify the L:\ drive is connected, if not, as you noted, I map it. I am adding that to each of my Databases and Automated Spreadsheets so if a person uses any of the daily tools, they will always be remapped automatically. Great suggestion and help! Thanks so much!!
 

Users who are viewing this thread

Back
Top Bottom