Reply
Old March 10th, 2006 Top | #1

OSNN Folding Team  
kcnychief's Avatar
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305

Default Login Script Syntax

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

XBOX Live Gamertag: kcnychief
kcnychief is offline   Reply With Quote
Old March 10th, 2006 Top | #2
 
madmatt's Avatar
Bow Down to the King
Joined: April 2002
Location: New York
Posts: 13,312
Reputation: 4090
Power: 297

Default Re: Login Script 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.

madmatt is offline   Reply With Quote
Old March 10th, 2006 Top | #3

OSNN Folding Team  
kcnychief's Avatar
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305

Default Re: Login Script Syntax

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

XBOX Live Gamertag: kcnychief
kcnychief is offline   Reply With Quote
Old March 10th, 2006 Top | #4
 
madmatt's Avatar
Bow Down to the King
Joined: April 2002
Location: New York
Posts: 13,312
Reputation: 4090
Power: 297

Default Re: Login Script Syntax

May I ask why you prefer to use Visual Basic Script over batch or even command scripting?

madmatt is offline   Reply With Quote
Old March 10th, 2006 Top | #5

OSNN Folding Team  
kcnychief's Avatar
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305

Default Re: Login Script Syntax

I'm kind of fascinated by it, it's just something I want to learn

XBOX Live Gamertag: kcnychief
kcnychief is offline   Reply With Quote
Old March 10th, 2006 Top | #6

OSNN Folding Team  
fitz's Avatar
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,028
Reputation: 2947
Power: 168

Default Re: Login Script Syntax

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..
fitz is offline   Reply With Quote
Old March 10th, 2006 Top | #7
 
ZeroHour's Avatar
ho3 ho3 ho3
Joined: March 2004
Location: Scotland
Posts: 1,112
Reputation: 1032
Power: 121

Default Re: Login Script Syntax

VB allows you to dump errors to the event log
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.

<Z>
EduGeek.net -The I.T. professionals' life line
ZeroHour is offline   Reply With Quote
Old March 10th, 2006 Top | #8

OSNN Folding Team  
kcnychief's Avatar
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305

Default Re: Login Script Syntax

Great info fitz, will get to testing and get back to ya

XBOX Live Gamertag: kcnychief
kcnychief is offline   Reply With Quote
Old March 11th, 2006 Top | #9

OSNN Folding Team  
fitz's Avatar
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,028
Reputation: 2947
Power: 168

Default Re: Login Script Syntax

no problem at all

I'm no where near a scripting god like the scripting Guys, but I do know some of the basics
fitz is offline   Reply With Quote
Old March 11th, 2006 Top | #10

OSNN Folding Team  
kcnychief's Avatar
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305

Default Re: Login Script Syntax

Yeah, I subscribe to that newsletter

XBOX Live Gamertag: kcnychief
kcnychief is offline   Reply With Quote
Old March 12th, 2006 Top | #11

OSNN Folding Team  
kcnychief's Avatar
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305

Default Re: Login Script Syntax

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 = "\\server\share" 
strRemotePath2 = "\\server\share" 
 
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, "\\server\share\%username%\", "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, "\\server\share\%username%\", "REG_EXPAND_SZ" 
 
'Change location of Favorites folder
RegLocate2 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Favorites"
objShell.RegWrite RegLocate, "\\server\share\%username%\", "REG_EXPAND_SZ"
 
Wscript.Quit
This will allow me to do everything without calling an external file

XBOX Live Gamertag: kcnychief
kcnychief is offline   Reply With Quote

Reply

Bookmarks

Thread Tools

Posting Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
Domain group policy login script not applying Mainframeguy Windows Desktop Systems 1 October 8th, 2007 6:45pm
Login Script Help kcnychief Windows Server Systems 2 January 18th, 2007 3:45am
Syntax mobo's? dreamliner77 General Hardware 5 May 12th, 2004 5:13am
OE6 syntax error! Kylie Windows Desktop Systems 4 March 23rd, 2002 1:36am
HELP ...cant go pass login screen cause of custom login program... steveklebs Windows Desktop Systems 3 January 26th, 2002 11:38am