Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Login Script to handle Persistent Drive Mapping

Reply
Thread Tools Display Modes

Login Script to handle Persistent Drive Mapping

 
 
Mike Bailey
Guest
Posts: n/a

 
      09-10-2008
I've been trying to put together a login script that will account for XP
persistent drive mapping. I've foudn that with normal vbs scripting to
just remove and then remap a drive letter, that it may still appear to
be mapped incorrectly in My Computer.

All of the script that I have has come from other people.

Here is what I hve right now, and it is producing an error: Line 19
Char: 5 Error: Variable is undefined: 'HKCU'

----Start My Scrip-----------------------------------------------

Option Explicit
Dim objFSO, objNetwork, objReg

'*****************
'MAP Q: TO sever
'*****************
'
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Set objReg =
GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\default:StdRegProv")

'Q: Drive
'*********
If (objFSO.DriveExists("Q:" = True)) Then
objNetwork.RemoveNetworkDrive "Q:", True, True
End If

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

objNetwork.MapNetworkDrive "Q:", "\\server\share"

---End My Script-----------------------------------------------


At one time, I had received this email/post with the script suggestions
below from a couple of people tryign to help. I'm not sure if all of
this is needed, or just part of it.

================================================== =====================
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=impersonat e}!\\.\root\default:StdRegProv")
objReg.DeleteKey HKCU, "Network\" & Left("j:", 1)
Set objReg = Nothing
End If

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

---------------------------------------------------------

================================================== ========================

Thanks for any help,
Mike
 
Reply With Quote
 
 
 
 
Mike Bailey
Guest
Posts: n/a

 
      09-10-2008
By the way, if I take the code out causing the error, I then get this
error which reflects the persistent dive maping issue:

Error: THe local device name has a remembered connection to antoher
network resource.

Thanks,
Mike

Mike Bailey wrote:
> I've been trying to put together a login script that will account for XP
> persistent drive mapping. I've foudn that with normal vbs scripting to
> just remove and then remap a drive letter, that it may still appear to
> be mapped incorrectly in My Computer.
>
> All of the script that I have has come from other people.
>
> Here is what I hve right now, and it is producing an error: Line 19
> Char: 5 Error: Variable is undefined: 'HKCU'
>
> ----Start My Scrip-----------------------------------------------
>
> Option Explicit
> Dim objFSO, objNetwork, objReg
>
> '*****************
> 'MAP Q: TO sever
> '*****************
> '
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objNetwork = CreateObject("Wscript.Network")
> Set objReg =
> GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\default:StdRegProv")
>
>
> 'Q: Drive
> '*********
> If (objFSO.DriveExists("Q:" = True)) Then
> objNetwork.RemoveNetworkDrive "Q:", True, True
> End If
>
> If objFSO.DriveExists("Q:") Then
> objReg.DeleteKey HKCU, "Network\" & Left("Q:", 1)
> End If
>
> objNetwork.MapNetworkDrive "Q:", "\\server\share"
>
> ---End My Script-----------------------------------------------
>
>
> At one time, I had received this email/post with the script suggestions
> below from a couple of people tryign to help. I'm not sure if all of
> this is needed, or just part of it.
>
> ================================================== =====================
> 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=impersonat e}!\\.\root\default:StdRegProv")
>
> objReg.DeleteKey HKCU, "Network\" & Left("j:", 1)
> Set objReg = Nothing
> End If
>
> --------------------------------------------------
> 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??
>
> ---------------------------------------------------------
>
> ================================================== ========================
>
> Thanks for any help,
> Mike

 
Reply With Quote
 
Al Dunbar
Guest
Posts: n/a

 
      09-11-2008
This statement:

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


calls the DeleteKey method, and passes two parameters. The second parameter
is the string "Network\Q", while the first parameter is being interpreted
according to vbscript syntax rules as a reference to a non-existent variable
(or constant) called HKCU.

The first parameter to this method needs to be one of a series of special
numeric values. To delete a key in the Current User hive with the above
code, you'd be best off defining HKCU as a constant:

const HKCU = &H80000001


/Al

"Mike Bailey" <> wrote in message
news:...
> I've been trying to put together a login script that will account for XP
> persistent drive mapping. I've foudn that with normal vbs scripting to
> just remove and then remap a drive letter, that it may still appear to be
> mapped incorrectly in My Computer.
>
> All of the script that I have has come from other people.
>
> Here is what I hve right now, and it is producing an error: Line 19 Char:
> 5 Error: Variable is undefined: 'HKCU'
>
> ----Start My Scrip-----------------------------------------------
>
> Option Explicit
> Dim objFSO, objNetwork, objReg
>
> '*****************
> 'MAP Q: TO sever
> '*****************
> '
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objNetwork = CreateObject("Wscript.Network")
> Set objReg =
> GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\default:StdRegProv")
>
> 'Q: Drive
> '*********
> If (objFSO.DriveExists("Q:" = True)) Then
> objNetwork.RemoveNetworkDrive "Q:", True, True
> End If
>
> If objFSO.DriveExists("Q:") Then
> objReg.DeleteKey HKCU, "Network\" & Left("Q:", 1)
> End If
>
> objNetwork.MapNetworkDrive "Q:", "\\server\share"
>
> ---End My Script-----------------------------------------------
>
>
> At one time, I had received this email/post with the script suggestions
> below from a couple of people tryign to help. I'm not sure if all of this
> is needed, or just part of it.
>
> ================================================== =====================
> 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=impersonat e}!\\.\root\default:StdRegProv")
> objReg.DeleteKey HKCU, "Network\" & Left("j:", 1)
> Set objReg = Nothing
> End If
>
> --------------------------------------------------
> 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??
>
> ---------------------------------------------------------
>
> ================================================== ========================
>
> Thanks for any help,
> Mike



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drive Mapping in Login Script bpledger Windows Small Business Server 2 02-08-2007 08:59 PM
Login script drive mapping problem: multiple offices, one domain, different mapping David Lewis Scripting 2 12-03-2003 02:52 AM
Login-script and drive mapping Peter Jensen Scripting 2 08-04-2003 05:16 AM
login script for drive mapping Marc De Schepper Scripting 0 07-21-2003 12:48 PM
Re: login script for drive mapping David H. Lipman Scripting 0 07-21-2003 02:04 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59