Win 2k3 login script on Win 7

illmaticone

OSNN Junior Addict
Joined
Jan 30, 2006
Messages
45
ok so heres there deal, i have a windows 2003 server pushing out the script below... The login script executes on windows 7, it maps all my drives EXCEPT the the maps with username/password specified. this works 100% on Windows XP.

Code:
' Create the Shell or environment for the commands:
Set WshShell = WScript.CreateObject("WScript.Shell")

' Define objects:
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives()

' ====================================
' DEFINE WHO TO CONTACT for pop-up messages:
' ====================================
strContactMessage = "If you require assistance, please contact IT Support ."

Dim strUserName

' Here is where we extract the UserName
strUserName = WshNetwork.UserName 

' ==================
' DEFINE DRIVES TO MAP:
' ==================
' Users home folder
Mapit "H", "\\server\Profile\"+ strUserName +"\My Documents", "", ""

' DATA
Mapit "N", "\\server\stanton\data", "", ""

' Server2 Public
Mapit "O", "\\server2\public", "", ""

' Server1 Public
Mapit "P", "\\server1\public", "", ""

' AQ-Import
Mapit "Q", "\\server3\folder", "user", "pass"

' S2K Docs
Mapit "S", "\\server3\S2KDOCS\", "user", "pass"

' set PC time
wshShell.Run "Net Time /Domain:xxx /set /yes",0,False

' ========
' CLEAN UP:
' ========
Set WshShell = Nothing
Set WshNetwork = Nothing
Set oDrives = Nothing


' ##################################
' DO NOT MODIFY ANYTHING BELOW THIS POINT...
'   unless you are familiar with the proper settings.
' ##################################
Sub Mapit(strLetter, strPath, strUser, strPass)

    ' Define the DriveLetter:
    DriveLetter = strLetter & ":"

    ' Define the remote path:
    RemotePath = strPath

    ' Pop-up Notices (set to False to disable notices, otherwise set to True):
    bPopReminder = false

    ' Define known errors to trap:
    Dim arrErrCode(1)
    Dim arrErrDesc(1)
    arrErrCode(0) = -2147023694
    arrErrCode(1) = -2147024811
    arrErrDesc(0) = "Unable to map drive " & DriveLetter & " to " & RemotePath _
        & " due to a previously defined remembered map with the same letter." _
        & vbCrLf & vbCrLf & "Please MANUALLY disconnect map drive " & DriveLetter _
        & ", then Log Out and Log back in."
    arrErrDesc(1) = "Unable to map drive " & DriveLetter & " to " & RemotePath _
        & " since " & DriveLetter & ": was previously reserved by your computer." _
        & vbCrLf & vbCrLf & "(Refer to Management, Shared Folders, Shares)"

    ' Define whether the map information should be removed from the current user's profile:
    bForceRemoveFromProfile = True
    bRemoveFromProfile = True

    ' Define whether the map information should be stored in the current user's profile:
    bStoreInProfile = False

    ' Check if already connected:
    AlreadyConnected = False
    For i = 0 To oDrives.Count - 1 Step 2
        If LCase(oDrives.Item(i)) = LCase(DriveLetter) Then AlreadyConnected = True
    Next

    ' Attempt to map the drive.  If already mapped, first attempt disconnect:
    If AlreadyConnected = True then
        WshNetwork.RemoveNetworkDrive DriveLetter, bForceRemoveFromProfile, bRemoveFromProfile
        If Not strUser = "" Then
            WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile, strUser, strPass
        Else
            WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
        End If
        If bPopReminder Then WshShell.PopUp "Drive " & DriveLetter & " disconnected, then connected successfully to " & RemotePath
    Else
        On Error Resume Next
        If Not strUser = "" Then
            WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile, strUser, strPass
        Else
            WshNetwork.MapNetworkDrive DriveLetter, RemotePath, bStoreInProfile
        End If
        If Err.Number <> 0 Then
            bKnownError = False
            For I = LBound(arrErrCode) To UBound(arrErrCode)
                If Err.Number = arrErrCode(I) Then
                    bKnownError = True
                    strPopMessage = arrErrDesc(I)
                    ' Display the Disconnect Network Drives window:
                    If Err.Number = arrErrCode(0) Then
                        Set objWSH = Wscript.CreateObject("WScript.Shell")
                        objWSH.Run "rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL Disconnect", 1, true
                    End If
                    Exit For
                End If
            Next
            If Not bKnownError Then
                strPopMessage = "Unable to map drive " & DriveLetter & " to " & RemotePath _
                    & " due to reason stated below."
            End If
            ' Display warning message:
            strPopMessage = "WARNING!!   WARNING!!   WARNING!!   WARNING!!" _
                & vbCrLf & vbCrLf & strPopMessage _
                & vbCrLf & vbCrLf & Err.Description & " (error " & Err.Number & ")" _
                & vbCrLf & vbCrLf & strContactMessage
            WshShell.PopUp strPopMessage
        Else
            If bPopReminder Then WshShell.PopUp "Drive " & DriveLetter & " connected successfully to " & RemotePath
        End If
    End If

    ' Release resources:
    Set objWSH = Nothing

    ' Slight pause to ensure each pass has time to commit:
    wscript.sleep 200
End Sub
i'm pulling my hair here, any help would be greatly appreciated. Thanks!!
 

Members online

No members online now.

Latest profile posts

Electronic Punk wrote on Sazar's profile.
Where are you buddy? :(
Perris Calderon wrote on Electronic Punk's profile.
Hey ep!

All good with me, applying for microsoft mvp right now, should have done this a while ago.

Notifications don't work, I only found your response by comming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier, mine is perriscalderon at gmail
Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?

Forum statistics

Threads
61,978
Messages
673,285
Members
89,062
Latest member
nirmalweb02