Login Script Syntax


█▄█ ▀█▄ █
Political User
I have a very simple login script that does two things, mapping of drive(s) and applying registry values. The way I have the registry entries applied is that I made the changes on a machine, and then exported that area of the registry. So I have a .reg file I'm trying to apply. I'm getting a syntax error, so I think I don't have the command right. The drive mapping is fine, the problem is with running the .reg file.

Set objNetwork = WScript.CreateObject("WScript.Network") 
objNetwork.MapNetworkDrive "S:" , "\\server01\public_files"
regedit /s folders.reg
From what I understand, that will work as long as the "folders.reg" file is in the same directory as the script, which it is. Else I think you have to put the full path of the file itself. Am I wrong?

EDIT: I should probably mention this is a .VBS, incase you couldn't tell from the syntax :)


Bow Down to the King
Political User
Looks too complex.

@echo off
title Mapping Network Drives...
@echo off

Rem net use H: /home
net use R: /d /y
net use S: /d /y
net use T: /d /y
net use V: /d /y
net use R: "\\greno-02\Software Distribution"
net use S: "\\greno-02\Shared Documents"
net use T: "\\greno-02\Drawings"
net use V: \\greno-01\epicor
That's how I map drives. As for the registry file, I would put the full UNC.


█▄█ ▀█▄ █
Political User
Thanks madmatt, but I want to do it with a .VBS

However I just realized that the reason my registry call wasn't working was because I tried to combine .bat files with .vbs scripts.

I'm going to pull my book out and get this licked, will post when I have it completed

It is more complex than it has to be, but I want to learn it :)


Woah.. I'm still here?
Staff member
Political User
objNetwork.MapNetworkDrive "S:" , "\\server01\public_files"
I'm assuming you know this, but since you appear to be fairly new to VBScript, I'll point this out..

If the S: drive is already connected the script will throw an error and fail at this point and not process the rest of the script. You can either throw an "On Error Resume Next" up at the top of your script to continue processing on errors and/or more correctly, check if the drive is already connected before trying to connect the drive.

That being said, if you want to run regedit to use an external .reg file:

'create the Shell Object
set objShell = wscript.CreateObject("Wscript.Shell")

'Grab the windows directory path from the environment variable "WINDIR"
Set objEnv = objShell.Environment("process")
strWinPath = objEnv("WINDIR")

'Execute regedit
'1st argument is the command to execute
'2nd argument is the window style - 0 = run in a hidden window
'3rd arguement is to wait for command to complete 
'before moving on through the script
objShell.Run strWinPath & "\regedit folders.reg",0,false

'Clear the objects
set objEnv = Nothing
set objShell = Nothing
Edit: Merging multiple posts:
As an alternative, you can write registry keys from VBScript through the Shell object instead of calling the external program.. look up the RegWrite method the web.. or directly on MSDN

edit 2:
Hmm.. browsing the MSDN site and noticed there is an ExpandEnvironmentStrings method for the shell object so you could replace these lines:
'Grab the windows directory path from the environment variable "WINDIR"
Set objEnv = objShell.Environment("process")
strWinPath = objEnv("WINDIR")
With this:

'Grab the windows directory path from the environment variable "WINDIR"
strWinPath = objShell.ExpandEnvironmentStrings("%WinDir%")
Saves you from having to create another object..
Last edited:
VB allows you to dump errors to the event log :D
And you can inspect user properies like groups etc as well as narrowing down maps for different machines. Also VB shows no window which can be closed. Maps as well are user profile settings which means they dont need to be mapped unless they are there so you can check to see if the drive exists and not map if it does thus speeding loading.
But if you dont need that batch is fine.


█▄█ ▀█▄ █
Political User
I think I got it, I just have to test which I can't right now. Some of the code may get cleaned, as I feel some of this is excessive and can probably be eliminated...

' VBScript to Map Drive(s) and Change Registry Values 
' Drives will be mapped to S: X:
' Registry changes are to re-direct Desktop, My Documents and Favorites folders
Option Explicit
Dim objNetwork, objShell, strRemotePath1, strRemotePath2
Dim strDriveLetter1, strDriveLetter2, strDriveExplore
Dim ojbShell, RegLocate, RegLocate1, RegLocate2 
strDriveLetter1 = "M:" 
strDriveLetter2 = "P:" 
strRemotePath1 = "[URL="file://\\server\share"]\\server\share[/URL]" 
strRemotePath2 = "[URL="file://\\server\share"]\\server\share[/URL]" 
On Error Resume Next
Set objNetwork = CreateObject("WScript.Network") 
' Section which maps two drives, S: and X:
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
Set objshell = WScript.Createobject("WScript.Shell")
'On Error Resume Next
'Line above is commented as may not be needed
'Change location of Desktop folder
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Desktop"
objShell.RegWrite RegLocate, "[URL="file://\\server\share\%username%\"]\\server\share\%username%\[/URL]", "REG_EXPAND_SZ"
'Change location of My Documents folder
RegLocate1 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal"
objShell.RegWrite RegLocate, "[URL="file://\\server\share\%username%\"]\\server\share\%username%\[/URL]", "REG_EXPAND_SZ" 
'Change location of Favorites folder
RegLocate2 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Favorites"
objShell.RegWrite RegLocate, "[URL="file://\\server\share\%username%\"]\\server\share\%username%\[/URL]", "REG_EXPAND_SZ"
This will allow me to do everything without calling an external file :)

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
What a long strange trip it's been. =)

Forum statistics

Latest member