"circulent" <circulent@discussions.microsoft.com> wrote in message
news:A4169737-056E-47C0-BA45-4C8AB4EC47F1@microsoft.com...
> Does anyone have a simple VB script template for mapping multiple network
> drives and network printers via group policies I can use?
A very simple VBScript logon script would be:
=============
' VBScript logon script program.
Option Explicit
Dim objNetwork
Set objNetwork = CreateObject("Wscript.Network")
' Map shared folders.
objNetwork.MapNetworkDrive "K:", "\\MyServer\MyShare2"
objNetwork.MapNetworkDrive "M:", "\\MyServer\MyShare1"
' Map shared printer.
objNetwork.AddWindowsPrinterConnection "\\MyServer\Printer1"
' Make this printer the default.
objNetwork.SetDefaultPrinter "\\MyServer\Printer1"
==============
If the drive letter could be in use due to persistent connections, you can
trap the possible error, attempt to remove the drive mapping, then try to
map again. The code would be similar to:
============
' Trap error if K: already in use.
On Error Resume Next
objNetwork.MapNetworkDrive "K:", "\\MyServer\MyShare1"
If (Err.Number <> 0) Then
' Restore normal error handling.
On Error GoTo 0
' Attempt to remove drive mapping.
objNetwork.RemoveNetworkDrive "K:", True, True
' Try again to map the drive.
objNetwork.MapNetworkDrive "K:", "\\MyServer\MyShare1"
End If
' Restore normal error handling.
On Error GoTo 0
===========
The above assumes you do not map according to group membership. Everyone
subject to the GPO gets the same mappings.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab -
http://www.rlmueller.net
--