Login Script Syntax

kcnychief

??? ??? ?
Political Access
Joined
8 Apr 2005
Messages
16,950
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.

Code:
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 :)
 
Looks too complex.

Code:
@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.
 
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 :)
 
May I ask why you prefer to use Visual Basic Script over batch or even command scripting?
 
I'm kind of fascinated by it, it's just something I want to learn :)
 
Code:
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:

Code:
'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:
Code:
'Grab the windows directory path from the environment variable "WINDIR"
Set objEnv = objShell.Environment("process")
strWinPath = objEnv("WINDIR")
With this:

Code:
'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.
 
Great info fitz, will get to testing and get back to ya :)
 
no problem at all :)

I'm no where near a scripting god like the scripting Guys, but I do know some of the basics :)
 
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...

Code:
' 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"
 
Wscript.Quit

This will allow me to do everything without calling an external file :)
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back