Results 1 to 9 of 9

Thread: Logon Script will not remove "Remembered Connection" in XP

  1. #1
    Mike Bailey Guest

    Logon Script will not remove "Remembered Connection" in XP

    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

  2. #2
    CreateWindow Guest

    Re: Logon Script will not remove "Remembered Connection" in XP

    This should just work.

    Dim WshNet

    Set WshNet = WScript.CreateObject("WScript.Network")
    WshNet.RemoveNetworkDrive "J:", True, True
    Wscript.Sleep(1000)
    WshNet.MapNetworkDrive "J:", "\\myserver\users\shared"
    Set WSHNet = Nothing

    I put a 1 second delay in to allow the network to "settle" before the
    reconnect. Might help??

  3. #3
    Shenan Stanley Guest

    Re: Logon Script will not remove "Remembered Connection" in XP

    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

  4. #4
    Mike Bailey Guest

    Re: Logon Script will not remove "Remembered Connection" in XP

    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
    ================================================================================

  5. #5
    jessetechie@gmail.com Guest

    Re: Logon Script will not remove "Remembered Connection" in XP

    In case you're still struggling, you need to replace

    Dim WshNet

    with

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

    (yes, that should be all on one line)

    Looks like you're just combining two examples from two different
    people.

    What that line does is just create an instance of the WScript.Network
    object, so you can then call the RemoveNetworkDrive method.

    Good Luck!


  6. #6
    jessetechie@gmail.com Guest
    Ugh, I just looked closer and it's ALL confused. Here's what you
    want:

    Set objNet = CreateObject("WScript.Network")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.
    \root\default:StdRegProv")

    If objFSO.DriveExists("I:") Then
    objNet.RemoveNetworkDrive "I:",True,True
    End If

    If objFSO.DriveExists("I:") Then
    objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
    End If

    objNet.MapNetworkDrive "I:", "\\myserver\shares"

    Set objNet = Nothing
    Set objFSO = Nothing
    Set objReg = Nothing


    I haven't tested this though.

    Does the line that starts with \root\ belong on the same line as the
    line above - the GerObject

  7. #7
    Join Date
    Jul 2009
    Posts
    1

    Re: Logon Script will not remove "Remembered Connection" in XP

    The key to this issue is the fact that the registry is holding the drive letter. Hence using "If objFSO.DriveExists("I:") Then objReg.DeleteKey HKCU, "Network\" & Left("I:", 1) End If ". Adding this extra code did the trick.

    If you do get that error, you can also verify if the drive letter is there. Launch Regedit (normal disclaimer; if you aren't careful you can really muck things up goes here) but launch Regedit and navigate to "HKCU\Network\" Look for the drive letter in question. If it is there, you'll see where it points and if not - well it's not.

    Hope that helps explain why its there and where to find it. Thanks to the original poster that added that line.
    Last edited by JRendon; 10-07-2009 at 11:41 PM. Reason: Added addition info

  8. #8
    Lanwench [MVP - Exchange] Guest

    Re: Logon Script will not remove "Remembered Connection" in XP

    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.

  9. #9
    Join Date
    Oct 2009
    Posts
    1

    Re: Logon Script will not remove "Remembered Connection" in XP

    Ouch, pretty harsh. The fact that this thread is stale, is really irrelevant nowadays. These threads come up as search results, people (such as myself) are searching for a solution, rather than re-posting the same question over and over, creating new non-stale threads. Secondly, who cares if you quote the previous post, maybe those dinosaurs that are using nntp, seriously, like we want a whole thick client app running just to get to the newsgroups, embrace the new technology/methodology. Now, down to my question, in case anybody cares to answer.

    Why in this script is everyone using:

    objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)

    instead of just objReg.DeletKey HKCU, "Network\I". That just seems crazy, why concatenate and use 'left' on that string?

Similar Threads

  1. Replies: 4
    Last Post: 14-01-2011, 01:33 AM
  2. Replies: 1
    Last Post: 13-05-2010, 03:46 AM
  3. Replies: 2
    Last Post: 31-10-2008, 04:58 AM
  4. Replies: 1
    Last Post: 06-11-2007, 02:18 PM
  5. No "Logon using dial-up connection" on Vista login screen
    By aileen in forum Windows Vista Network
    Replies: 3
    Last Post: 18-04-2007, 09:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,716,543,289.80861 seconds with 17 queries