VBS Logon script

Discussion in 'MCSA' started by Matt G, May 14, 2008.

  1. Matt G

    Matt G Guest

    Hi all I am testing this script to map network drives upon logon

    Dim wshNetwork
    Set wshNetwork = CreateObject("Wscript.Network")
    wshNetwork.RemoveNetworkDrive "H:"
    wshNetwork.MapNetworkDrive "H:", "\\server\share"
    WSCript.Quit

    Is there any way I can stick an "IF" statement in there so it will remove
    the drive if it exists but carry on if it doesn't.

    Cheers
     
    Matt G, May 14, 2008
    #1
    1. Advertisements

  2. Matt G

    PAJ Guest

    On Wed, 14 May 2008 04:41:01 -0700, Matt G <Matt

    I use:
    -----------------------
    Dim objFSO, strDrive, strShare
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objNetwork = CreateObject("Wscript.Network")
    strDrive = "H:"
    strShare = "\\server\share"
    If objFSO.DriveExists(strDrive) = True Then
    objNetwork.RemoveNetworkDrive strDrive
    End If
    WScript.sleep 600
    objNetwork.MapNetworkDrive strDrive, strShare
    -----------------------
     
    PAJ, May 14, 2008
    #2
    1. Advertisements

  3. Matt G

    Matt G Guest

    Hi Do I need to change anything.

    E.g. if the strDrive is v:

    would I change it to look like this

    If objFSO.DriveExists(V) = True Then
    objNetwork.RemoveNetworkDrive strDrive
     
    Matt G, May 16, 2008
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.