creating a batch file to map a users home drive on the network.

Posted on 2009-05-14
Last Modified: 2012-05-07
I want to create a file that can be sent out to all users in the company, that once they click on it will map a drive to their home folder on the network and also place a shortcut on the desktop, anyone know if this can be done and how to.
Question by:Techno-Man-uk
  • 5
  • 4
  • 3
LVL 67

Accepted Solution

sirbounty earned 500 total points
ID: 24384772
Are you in a domain?  You can use a logon script for this
net use h: \\servername\%username%

Author Comment

ID: 24384885
yes in a domain, I have used the above in Active Directory, but before I joined the company this wasn't enforced so I don't want to have to go through all the accounts looking at who has and hasn't got their drive mapped.
I just want a simple file they can click and it does all the work

Expert Comment

ID: 24384969
Would all of the users be mapping to the same file name? Example: \anyserver\myfolder , or do they each have a specific folder name \anyserver\johnsmith?
Do they need to log in to the server?
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  


Author Comment

ID: 24385032
all users folders are kept in a central location on 1 server under a shared folder called users


Expert Comment

ID: 24385120
so would you want them to enter specific data from command prompt?

SET /P variable=[promptString]

set /p user=Please enter your user name:
echo Hello, %NAME%

Author Comment

ID: 24385205
Well no I want something like a batch file that they can click and it will run some script to map their home drive and make a desktop shortcut.

Expert Comment

ID: 24385212
Do the users log in to the shared drive on the server? If they log in, could you have the files stored on the server itself and the batch file could run then? net use k: \\myserver\users\username /yes

Expert Comment

ID: 24385245
Could it be a batch file to add a shortcut that is pre-configured with the target and start-in values?

Expert Comment

ID: 24385278
name it shortcut.bat

@echo off

copy k:\shortcut.lnk %username%\Desktop

add to script:

call shortcut.bat

Author Comment

ID: 24385400
that doesn't seem to work
LVL 67

Assisted Solution

sirbounty earned 500 total points
ID: 24385457
Adapted from &
' CreateShortCut.vbs - Create a Desktop Shortcut.
' VBScript to create .lnk file
' Author Guy Thomas
' Version 2.4 - July 2006
' ----------------------------------------------------------' 
Option Explicit
Dim objShell, objDesktop, objLink
Dim strAppPath, strWorkDir, strIconPath
Set objShell = CreateObject("WScript.Shell")
' --------------------------------------------------
' Here are the variables that to change if you are making a 'real' script
'strWorkDir ="C:\windows"
strServer = "\\YourServer\"
strAppPath = strServer & objShell.ExpandEnvironmentStrings("%username%") '"%SystemRoot%\notepad.exe"
'strIconPath = "%SystemRoot%\system32\SHELL32.dll,5"
strDrive = "H:"
Set objNetwork = CreateObject("WScript.Network") 
objNetwork.MapNetworkDrive strDrive, strAppPath
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\HomeShare.lnk")
' ---------------------------------------------------
' Section which adds the shortcut's key properties
objLink.Description = "HomeShare"
'objLink.HotKey = "CTRL+SHIFT+X"
'objLink.IconLocation = strIconPath 
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3
'objLink.WorkingDirectory = strWorkDir
' End of creating a desktop shortcut

Open in new window

LVL 67

Expert Comment

ID: 24407400
Glad I could help - thanx for the grade! :^)

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question