Logon Script will not remove "Remembered Connection" in XP

Discussion in 'Scripting' started by Mike Bailey, Aug 3, 2007.

  1. Mike Bailey

    Mike Bailey Guest

    I've been trying to write a simple logon script for a Server 2003/XP
    workstation environment.

    At this point, I'm past trying anything fancy such as mapping by group
    membership, I just want to have everyone map to the same few drives, but
    I've run into a problem.

    Say someone already has a drive, J:, mapped through XP set to Reconnect.
    In my logon script, I have:

    wshNetwork.RemoveNetworkDrive "j:"
    wshNetwork.MapNetworkDrive "j:","\\myserver\users\shared"

    J: is already mapped to something else in XP. The script would not
    Remove the drive first. I captured this error "The local device name has
    a remembered connection to another network resource." So, since XP is
    set to remember the connection, this will not remove it.

    I found this information somewhere:
    "In addition to the mandatory parameter that specifies the mapped drive
    to be removed, the MapNetworkDrive method accepts two additional,
    optional, parameters: A Boolean value that, if set to True, specifies
    that the method should unmap the drive regardless of whether it is
    currently in use. If the value is set to True, the user will no longer
    be able to save data to that drive, even if he or she has already opened
    a document from there. Instead, the user will have to save the document
    to an alternate location.A Boolean value that, if set to True, specifies
    that the method should remove the drive mapping from the profile of the
    user."

    So, I tried this:

    wshNetwork.RemoveNetworkDrive "j:",True,True

    But it doesnt' work either - it doesn't produce an error, but it doesn't
    unmap the drive either.

    If I issue a Net Use from the command line, it shows it mapped correctly
    there, but My Computer still shows the old mapping - so I guess it's cached.

    Can anyone tell me how to over come this? All I want to do is:

    1)Check if a drive letter is already mapped to something, if so, unmap it.
    2)Map the drive to something new.
    3)Have the new mapping correctly displayed in My Computer.

    Thanks,
    Mike
     
    Mike Bailey, Aug 3, 2007
    #1
    1. Advertisements

  2. To remove any persistent mappings, more may be necessary.

    If (objFSO.DriveExists("j:" = True) Then
    objNetwork.RemoveNetworkDrive "j:",True,True
    End If

    If objFSO.DriveExists("j:") Then
    Set objReg =
    GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    objReg.DeleteKey HKCU, "Network\" & Left("j:", 1)
    Set objReg = Nothing
    End If
     
    Shenan Stanley, Aug 4, 2007
    #2
    1. Advertisements

  3. Mike Bailey

    Mike Bailey Guest

    Thanks. I have a copuple of questions though:

    Is nothing else required for this? Do I not have to delare some of this
    in Dim's or something? When I tried to include it in my scrip, it
    generates an error right at the first line of your code, Char 1. I did
    add an additional right parenthesis.

    I also got an error on the 6rh line, "set objReg=" I brought up the next
    line with it and it seems to fix it.

    I don't know vbs, so I can't tell what is missing. Here is the whole
    script as I have it now:

    ===============================================================================
    Dim WshNet

    '*****************
    'MAP COMMON DRIVES
    '*****************
    '
    'Note: U: (User Home directory) is mapped in the user profile in Active
    Directory

    'I: Drive - myserver\Shares
    '************************
    If (objFSO.DriveExists("I:" = True)) Then
    objNetwork.RemoveNetworkDrive "I:",True,True
    End If

    If objFSO.DriveExists("I:") Then
    Set objReg =
    GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
    Set objReg = Nothing
    End If

    Set WshNet = WScript.CreateObject("WScript.Network")
    WshNet.MapNetworkDrive "I:", "\\myserver\shares"
    Set WSHNet = Nothing
    ================================================================================
     
    Mike Bailey, Aug 6, 2007
    #3
  4. Mike Bailey

    Mike Bailey Guest

    Does the line that starts with \root\ belong on the same line as the
    line above - the GerObject
     
    Mike Bailey, Aug 30, 2007
    #4
  5. Hi - you're replying to a nonexistent (stale) thread, and you haven't quoted
    the original in your reply, so it's unlikely that anyone will know what
    you're referring to.

    Don't use the icky techarena forums as a means to access the MS public
    newsgroups. This is a regular problem with posts from that forum. Nor should
    you use Google Groups or any other 'mirror' of the newsgroups. Access them
    directly using a newsreader client and msnews.microsoft.com as your NNTP
    server. Much, much better.
     
    Lanwench [MVP - Exchange], Jul 16, 2009
    #5
    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.