Solved Make a Mapped Drive persistent so that it restores every time you reboot (1 Viewer)

kengooch

Member
Local time
Yesterday, 21:34
Joined
Feb 29, 2012
Messages
101
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?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:34
Joined
Oct 29, 2018
Messages
18,962
You could probably use the Shell command to execute a Net Use command with the /persistent: yes switch.

 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:34
Joined
Feb 28, 2001
Messages
22,780
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.
 

kengooch

Member
Local time
Yesterday, 21:34
Joined
Feb 29, 2012
Messages
101
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?
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:34
Joined
Sep 21, 2011
Messages
10,531
I'd be using theDBguy's method
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:34
Joined
Feb 28, 2001
Messages
22,780


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?
 

Isaac

Lifelong Learner
Local time
Yesterday, 21:34
Joined
Mar 14, 2017
Messages
6,454
MapNetworkDrive command with the appropriate argument value
 

kengooch

Member
Local time
Yesterday, 21:34
Joined
Feb 29, 2012
Messages
101


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.
 

kengooch

Member
Local time
Yesterday, 21:34
Joined
Feb 29, 2012
Messages
101
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.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:34
Joined
Feb 28, 2001
Messages
22,780
Ah, yes, the cumbersome nature of a "helpful" IT staff. Glad you got it working.
 

Isaac

Lifelong Learner
Local time
Yesterday, 21:34
Joined
Mar 14, 2017
Messages
6,454
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...........
 

kengooch

Member
Local time
Yesterday, 21:34
Joined
Feb 29, 2012
Messages
101
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

Top Bottom