I require an automatic process to mount a network drive for a specific user on a Windows 10 computer after the system has started up. The user has running services that need access to the network drive.
I need to accomplish this without the need for manual input of credentials, and the drive must be mounted during bootup, not just login.
I have attempted to mount the drive using a method that is similar but not exactly what I need:
net use h: https://server.example.com/storage /savecred /persistent:yes
The network drive is mounted successfully by requesting the user’s login credentials and providing an option to save them for future use. However, upon restarting the system and logging in again, the drive appears as a listed resource but is not mounted.
Additionally, I am prompted to provide the password, which suggests that the /savecred option is not functioning as intended.
2 Answers
Introduction
In a Windows 10 environment, it is often necessary to have network drives mounted and available automatically after the machine has booted up. This is especially important if you have services running that require access to the network drive. Mounting a network drive on bootup ensures that the drive is available to services without requiring manual intervention from a user. In this blog post, we will discuss how to mount a network drive automatically when Windows 10 boots up.
Step 1: Create a Batch File
The first step to mounting a network drive automatically on Windows 10 is to create a batch file. A batch file is a script that can be used to automate tasks on a Windows machine. In this case, we will use a batch file to mount the network drive.
To create a batch file, open Notepad and type the following command:
net use h: https://server.example.com/storage /user:username password /persistent:yes
Replace “h:” with the letter you want to assign to your network drive. Replace “https://server.example.com/storage” with the path to your network drive. Replace “username” with your username and “password” with your password.
Save the file with a .bat extension. For example, you could name the file “mount_drive.bat”.
Step 2: Create a Scheduled Task
The next step is to create a scheduled task that will run the batch file on bootup. To create a scheduled task, follow these steps:
1. Open the Task Scheduler by searching for it in the Start menu.
2. Click on “Create Task” in the “Actions” pane on the right-hand side of the window.
3. Give the task a name and description.
4. Click on the “Triggers” tab and click “New”.
5. Choose “At startup” from the “Begin the task” drop-down menu.
6. Click on the “Actions” tab and click “New”.
7. Choose “Start a program” from the “Action” drop-down menu.
8. Click “Browse” and select the batch file you created in Step 1.
9. Click “OK” to save the task.
Step 3: Test the Scheduled Task
After creating the scheduled task, you can test it to make sure that the network drive is mounted automatically on bootup. To test the task, follow these steps:
1. Restart your computer.
2. After your computer has booted up, open File Explorer and check if the network drive is mounted.
3. If the network drive is mounted, you have successfully mounted the network drive automatically on bootup.
Step 4: Troubleshooting
If the network drive is not mounted automatically on bootup, there are a few things you can check to troubleshoot the issue.
First, make sure that the batch file is working correctly. You can test the batch file by double-clicking on it and checking if the network drive is mounted.
If the batch file is working correctly, check the scheduled task to make sure that it is configured correctly. Double-check the path to the batch file and make sure that the task is set to run at startup.
If the scheduled task is configured correctly, check the credentials that you are using to mount the network drive. Make sure that the username and password are correct and that the user has permission to access the network drive.
Step 5: Security Considerations
When mounting a network drive automatically on bootup, it is important to consider security. Storing passwords in a batch file can be a security risk, especially if the batch file is accessible to other users.
One way to mitigate this risk is to store the password in the Windows Credential Manager. The Credential Manager is a secure storage area in Windows where you can store usernames and passwords. To store the password in the Credential Manager, follow these steps:
1. Open the Control Panel and click on “Credential Manager”.
2. Click on “Add a Windows credential”.
3. Enter the network address, username, and password for the network drive.
4. Click “OK” to save the credential.
After saving the credential, you can modify the batch file to use the credential from the Credential Manager. To do this, replace the “/user:username password” portion of the batch file with “/user:username /savecred”. This will tell Windows to use the credential from the Credential Manager instead of storing the password in the batch file.
Step 6: Conclusion
Mounting a network drive automatically on bootup is a useful feature in a Windows 10 environment. By creating a batch file and a scheduled task, you can mount a network drive without requiring manual intervention from a user. Remember to consider security when storing passwords and credentials, and always test your setup to ensure that it is working correctly.
I’m not sure why the CLI is not saving the credential, but there is an alternative method to add it manually using the GUI:
1. After the user logs in, open “This PC.”
2. Right-click on the background and choose “Add a network location.”
3. Click “Next” twice and select “Choose a custom network location.”
4. Enter the share name (e.g., \\Server\share\name) and click “Next.”
5. Enter the credentials when prompted. Once accepted, they will be saved in Credential Manager located in Control Panel\User Accounts\Credential Manager.
6. Name the share, click “Next,” and then click “Finish.”
For Pro/Enterprise editions, you may need to enable the following Group Policy:
Computer Configuration\Administrative Templates\System\Logon: Always wait for the network at computer startup and logon
Alternatively, you can use Group Policy [gpedit.msc] on Pro and Enterprise versions of Windows 10 to accomplish this.