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
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??
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
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
================================================================================
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!
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.
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.
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?