|
|
![]() |
|
|
Top | #1 |
|
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305 |
Code:
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "S:" , "\\server01\public_files"
regedit /s folders.reg
EDIT: I should probably mention this is a .VBS, incase you couldn't tell from the syntax
|
|
|
|
|
|
Top | #2 |
|
Bow Down to the King
Joined: April 2002
Location: New York
Posts: 13,312
Reputation: 4090
Power: 297 |
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 |
|
|
|
|
|
Top | #3 |
|
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305 |
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
|
|
|
|
|
|
Top | #4 |
|
Bow Down to the King
Joined: April 2002
Location: New York
Posts: 13,312
Reputation: 4090
Power: 297 |
May I ask why you prefer to use Visual Basic Script over batch or even command scripting?
|
|
|
|
|
|
Top | #5 |
|
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305 |
I'm kind of fascinated by it, it's just something I want to learn
|
|
|
|
|
|
Top | #6 |
|
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,028
Reputation: 2947
Power: 168 |
Code:
objNetwork.MapNetworkDrive "S:" , "\\server01\public_files" 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
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")
Code:
'Grab the windows directory path from the environment variable "WINDIR"
strWinPath = objShell.ExpandEnvironmentStrings("%WinDir%")
|
|
|
|
|
|
Top | #7 |
|
ho3 ho3 ho3
Joined: March 2004
Location: Scotland
Posts: 1,112
Reputation: 1032
Power: 121 |
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. |
|
|
|
|
|
Top | #8 |
|
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305 |
Great info fitz, will get to testing and get back to ya
|
|
|
|
|
|
Top | #9 |
|
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,028
Reputation: 2947
Power: 168 |
no problem at all
I'm no where near a scripting god like the scripting Guys, but I do know some of the basics
|
|
|
|
|
|
Top | #10 |
|
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305 |
Yeah, I subscribe to that newsletter
|
|
|
|
|
|
Top | #11 |
|
█▄█ ▀█▄ █
Joined: April 2005
Location: Massachusetts
Posts: 16,949
Reputation: 4941
Power: 305 |
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
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|
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 |