Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB Script problems when replacing a logon script

Posted on 2004-10-28
3
Medium Priority
?
275 Views
Last Modified: 2010-04-12
I am using a VB script to map a network drive and to also add network printers to every computer on the network.  I had been using a logon script (batch file) to map the drive, but chose to use the vb script when I added the printers.  The problem that I am having is that the vb script fails if there is a previous mapped drive with the same drive letter, or if there is already a printer with the same name.  I want to know if there is something that I can add to the script that will tell it to overwrite the mapped drives and printers that have the same drive letters or names.  Here is an example of the script that I am using.



Set objWSHNetwork = CreateObject("WScript.Network")  'create network object
strConnectString = "\\Dellserver\8400DX"
strResult = objWSHNetwork.AddWindowsPrinterConnection(strConnectString)

Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "P:", "\\192.168.0.10\Public"
WshNetwork.MapNetworkDrive "Q:", "\\192.168.0.10\DCC"
WshNetwork.MapNetworkDrive "o:", "\\192.168.0.53\FTP"


0
Comment
Question by:wdabbs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 31

Expert Comment

by:merowinger
ID: 12433680
WshNetwork.MapNetworkDrive "o:", "\\192.168.0.53\FTP" /p:yes


mero
0
 
LVL 1

Expert Comment

by:MrBass
ID: 12434592
Create a loop at the beginning of your script to remove any drive mappings you want to remap:

Dim WshNetwork
Dim strRequiredDrives

Set WshNetwork = WScript.CreateObject("WScript.Network")

strRequiredDrives = "P:,Q:,O:"

Set curDrives = WshNetwork.EnumNetworkDrives
For i = 0 to curDrives.Count -1
   If Len(curDrives.Item(i)) > 0 And InStr(strRequiredDrives,Left(curDrives.Item(i),2)) Then
      WshNetwork.RemoveNetworkDrive curDrives.Item(i),True
   End If
Next

WshNetwork.MapNetworkDrive "P:", "\\192.168.0.10\Public"
WshNetwork.MapNetworkDrive "Q:", "\\192.168.0.10\DCC"
WshNetwork.MapNetworkDrive "O:", "\\192.168.0.53\FTP"

You can do the same sort of thing for printers using WshNetwork.EnumPrinterConnections
0
 
LVL 1

Accepted Solution

by:
MrBass earned 2000 total points
ID: 12434819
Actually for printers it's even simpler:

Set objWSHNetwork = CreateObject("WScript.Network")  'create network object
strConnectString = "\\Dellserver\8400DX"

On Error Resume Next
objWshNetwork.RemovePrinterConnection strConnectString

strResult = objWSHNetwork.AddWindowsPrinterConnection(strConnectString)

- OR -

strConnectString = "\\Dellserver\8400DX"

Set curPrinters = objWshNetwork.EnumPrinterConnections
For i = 0 to curPrinters.Count -1
    If curPrinters.Item(i) = strConnectString Then objWshNetwork.RemovePrinterConnection strConnectString
Next
strResult = objWSHNetwork.AddWindowsPrinterConnection(strConnectString)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Working from home is a dream for many people who aren’t happy about getting up early, going to the office, and spending long hours at work. There are lots of benefits of remote work for employees.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question