Results 1 to 3 of 3

Thread: Login Script to handle Persistent Drive Mapping

  1. #1
    Mike Bailey Guest

    Login Script to handle Persistent Drive Mapping

    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=impersonate}!\\.\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=impersonate}!\\.\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

  2. #2
    Mike Bailey Guest

    Re: Login Script to handle Persistent Drive Mapping

    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=impersonate}!\\.\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=impersonate}!\\.\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


  3. #3
    Al Dunbar Guest

    Re: Login Script to handle Persistent Drive Mapping

    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" <mbailey@beaumontproducts.com> wrote in message
    news:O9I5Um3EJHA.4336@TK2MSFTNGP05.phx.gbl...
    > 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=impersonate}!\\.\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=impersonate}!\\.\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




Similar Threads

  1. Mapping a Network drive.
    By medic1202 in forum Windows Server Help
    Replies: 2
    Last Post: 03-02-2012, 08:27 PM
  2. Home Drive mapping
    By DREW in forum Active Directory
    Replies: 2
    Last Post: 05-02-2010, 09:58 PM
  3. Map Drive Login Script Issue
    By Jason in forum Windows Server Help
    Replies: 9
    Last Post: 26-06-2008, 08:40 PM
  4. to add username & password into my login.cmd - login script
    By sphilip in forum Windows Server Help
    Replies: 4
    Last Post: 05-03-2008, 11:04 PM
  5. Startup Script or Login Script ??
    By WANNABE in forum Active Directory
    Replies: 5
    Last Post: 22-12-2006, 07:44 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,713,255,982.64284 seconds with 17 queries