Solved

VB Script problems when replacing a logon script

Posted on 2004-10-28
273 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
Question by:wdabbs
    3 Comments
     
    LVL 31

    Expert Comment

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


    mero
    0
     
    LVL 1

    Expert Comment

    by:MrBass
    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:
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Server Hard Drive Expansion 2 124
    Making a spare domain pc 12 313
    Active Directory Replication 10 1,111
    VBScript not processed at Windows 8.1 logon 2 7,834
    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…
    SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…
    This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.

    884 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now