Announcement

Collapse
No announcement yet.

VB Logon Script not working as should

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VB Logon Script not working as should

    Hello all!

    First off - great forums, I have been watching these forums with joy and active participation...though never posted - you always helped me without me needing to post. But that is different now...

    I have an organization on which I am working right now (IT of course, not literately). I have setup almost everything but the logon script is making my completion difficult. The logon script is -for now - doing just basic stuff, until we migrate all of the workstations to Windows 7. Though probably everything is working OK, and if not - not an issue BUT the drive mapping is just playing stupid. I need to get three shares to users: the home user share, which is done by system alone under profile settings, the common share, which is working just fine..in most cases and the share that specific users are only allowed to have. Now the script is NOT doing it...in cases, there is only personal share, in some cases there are first two shares, but the third one is just bye-bye. I have tried to program just about everything, short of programming my own functions (I did not have to as free are available on internet ). If someone could PLEASE tell me on how to go about this problem I would be eternally grateful. So - I will attach my logon script for you to see and suggest. Let me remind you all, that we are currently in heterogeneous IT workspace. Servers are Windows 2003, up to date, workstations are mainly Windows XP, some Windows 7 but in process of upgrading all workstations to Windows 7 - so really we need solution for Windows 7.

    I thank you all in advance and look forward to have some discussions about the issue. I only hope that you can help me as you did countless others.
    Regards, Damjan
    Attached Files
    Last edited by DarkMaster; 15th February 2011, 14:43. Reason: Forgot to attach actual script

  • #2
    Re: VB Logon Script not working as should

    Attaching the logon script will help us a bit
    Use the QUOTE tags as you will not be able to post attachments yet
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: VB Logon Script not working as should

      BUMP anyone?

      Comment


      • #4
        Re: VB Logon Script not working as should

        Originally posted by DarkMaster View Post
        <cut>
        the drive mapping is just playing stupid <..> I have setup almost everything but the logon script is making my completion difficult .

        The home user share, which is done under profile settings is working just fine..in most cases.

        Two other shares are mapped by the login script,
        Now in some cases there is just one drive mapped by the script, the other one is just bye-bye.

        Servers are Windows 2003, up to date, workstations are mainly Windows XP, some Windows 7

        snippet:
        Code:
        Dim objGroupList, objUser
        Set objNetwork = CreateObject("Wscript.Network")
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        
        Set objSysInfo = CreateObject("ADSystemInfo")
        strUserDN = objSysInfo.userName
        Set objUser = GetObject("LDAP://" & strUserDN)
        
        
        ' ***********************************************************
        ' ***		    Mapiranje mrežnih pogonov   	  ***
        ' ***********************************************************
        
        If Not MapDrive("P:", "\\PCMGLJ01\PCMG") Then
        	objNetwork.MapNetworkDrive "P:", "\\PCMGLJ01\PCMG"
        End If
        
        'If IsMember("JAPTI-INT") or IsMember("JAPTI INT") or IsMember("JAPTI TNI") or IsMember("JAPTI-TNI") Then
         If Not MapDrive("S:", "\\japtilj05\skupno$") Then
         	objNetwork.MapNetworkDrive "S:", "\\japtilj05\skupno$"
         End If  
        	
        'End If
        
        
        ' IsMember is a boolean function to determine group membership.
        Function IsMember(strGroup)
        ' Function to test for group membership,
        ' returns True if the user or computer is a member of the group.
        
          If IsEmpty(objGroupList) Then
            Call LoadGroups
          End If
          IsMember = objGroupList.Exists(strGroup)
        End Function
        
        Sub LoadGroups
        ' Subroutine to populate dictionary object with group memberships.
        ' objUser is the user or computer object, with global scope.
        ' objGroupList is a dictionary object, with global scope.
        
          Dim arrbytGroups, j, arrstrGroupSids(), objGroup
        
          Set objGroupList = CreateObject("Scripting.Dictionary")
          objGroupList.CompareMode = vbTextCompare
        
          objUser.GetInfoEx Array("tokenGroups"), 0
          arrbytGroups = objUser.Get("tokenGroups")
          If TypeName(arrbytGroups) = "Byte()" Then
            ReDim arrstrGroupSids(0)
            arrstrGroupSids(0) = OctetToHexStr(arrbytGroups)
            Set objGroup = GetObject("LDAP://<SID=" & arrstrGroupSids(0) _
              & ">")
            objGroupList(objGroup.sAMAccountName) = True
            Set objGroup = Nothing
            Exit Sub
          End If
          If UBound(arrbytGroups) = -1 Then
            Exit Sub
          End If
        
          ReDim arrstrGroupSids(UBound(arrbytGroups))
          For j = 0 To UBound(arrbytGroups)
            arrstrGroupSids(j) = OctetToHexStr(arrbytGroups(j))
            Set objGroup = GetObject("LDAP://<SID=" & arrstrGroupSids(j) _
              & ">")
            objGroupList(objGroup.sAMAccountName) = True
          Next
          Set objGroup = Nothing
        End Sub
        
        Function MapDrive(strDrive, strShare)
        ' Function to map network share to a drive letter.
        ' If the drive letter specified is already in use, the function
        ' attempts to remove the network connection.
        ' objFSO is the File System Object, with global scope.
        ' objNetwork is the Network object, with global scope.
        ' Returns True if drive mapped, False otherwise.
        
          Dim objDrive
        
          On Error Resume Next
          Err.Clear
          If objFSO.DriveExists(strDrive) Then
            Set objDrive = objFSO.GetDrive(strDrive)
            If Err.Number <> 0 Then
              Err.Clear
              MapDrive = False
              Exit Function
            End If
            If CBool(objDrive.DriveType = 3) Then
              objNetwork.RemoveNetworkDrive strDrive, True, True
            Else
              MapDrive = False
              Exit Function
            End If
            Set objDrive = Nothing
          End If
          objNetwork.MapNetworkDrive strDrive, strShare
          If Err.Number = 0 Then
            MapDrive = True
          Else
            Err.Clear
            MapDrive = False
          End If
          On Error GoTo 0
        End Function
        
        Function OctetToHexStr(arrbytOctet)
        ' Function to convert OctetString (byte array) to Hex string.
        
          Dim k
          OctetToHexStr = ""
          For k = 1 To Lenb(arrbytOctet)
            OctetToHexStr = OctetToHexStr _
              & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
          Next
        End Function
        We are currently in heterogeneous IT workspace. Servers are Windows 2003, up to date, workstations are mainly Windows XP, some Windows 7 but in process of upgrading all workstations to Windows 7 - so really we need solution for Windows 7.
        You say that sometimes the mapping is succesful other times not,, have you in the time being discovered a pattern for this?
        - Does it fail on both WinXP and Win7 machines
        - Does it just fail for users who are admins on their computer
        - Does it fail just (/always) for the same set of computers (OS undepended)
        - Does it fail just (/always) for the same set of users

        Note, The "IsMember" function you use in the script (in this sample it was commented out though) only finds names of security groups, no distribution groups, be aware of that.

        Is the logon script directly launched from GPO or is the script you showed launched from within an other script?

        Can you seperate the drive mappings apart from the main script to a second script. Launch both script directly from GPO.

        TEST just the drive mappings:
        Code:
        Dim objGroupList, objUser
        Set objNetwork = CreateObject("Wscript.Network")
        
        Set objSysInfo = CreateObject("ADSystemInfo")
        strUserDN = objSysInfo.userName
        Set objUser = GetObject("LDAP://" & strUserDN)
        
        
        ' ***********************************************************
        ' ***		    Mapiranje mrežnih pogonov   	  ***
        ' ***********************************************************
        
        call MapDrive("P:", "\\PCMGLJ01\PCMG")
        
        Select Case True
           Case IsMember("JAPTI-INT"), IsMember("JAPTI INT"), _
                IsMember("JAPTI TNI"), IsMember("JAPTI-TNI")
             call MapDrive("S:", "\\japtilj05\skupno$")
        
           Case Else
             rem "No action"
        
        End Select
        
        
        ' IsMember is a boolean function to determine securitygroup membership.
        Function IsMember(strGroup)
        ' Function to test for group membership,
        ' returns True if the user or computer is a member of the group.
        
          If IsEmpty(objGroupList) Then
            Call LoadGroups
          End If
          IsMember = objGroupList.Exists(strGroup)
        End Function
        
        Sub LoadGroups
        ' Subroutine to populate dictionary object with group memberships.
        ' objUser is the user or computer object, with global scope.
        ' objGroupList is a dictionary object, with global scope.
        
          Dim arrbytGroups, j, arrstrGroupSids(), objGroup
          Set objGroupList = CreateObject("Scripting.Dictionary")
          objGroupList.CompareMode = vbTextCompare
        
          objUser.GetInfoEx Array("tokenGroups"), 0
          arrbytGroups = objUser.Get("tokenGroups")
          If TypeName(arrbytGroups) = "Byte()" Then
            ReDim arrstrGroupSids(0)
            arrstrGroupSids(0) = OctetToHexStr(arrbytGroups)
            Set objGroup = GetObject("LDAP://<SID=" & arrstrGroupSids(0) _
              & ">")
            objGroupList(objGroup.sAMAccountName) = True
            Set objGroup = Nothing
            Exit Sub
          End If
          If UBound(arrbytGroups) = -1 Then
            Exit Sub
          End If
        
          ReDim arrstrGroupSids(UBound(arrbytGroups))
          For j = 0 To UBound(arrbytGroups)
            arrstrGroupSids(j) = OctetToHexStr(arrbytGroups(j))
            Set objGroup = GetObject("LDAP://<SID=" & arrstrGroupSids(j) _
              & ">")
            objGroupList(objGroup.sAMAccountName) = True
          Next
          Set objGroup = Nothing
        End Sub
          Function OctetToHexStr(arrbytOctet)
          ' Function to convert OctetString (byte array) to Hex string.
             Dim k
             OctetToHexStr = ""
             For k = 1 To Lenb(arrbytOctet)
               OctetToHexStr = OctetToHexStr _
                & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
             Next
          End Function
        
        Sub MapDrive(strDrive, strShare)
        ' Function to map network share to a drive letter.
        ' If the drive letter specified is already in use, the function
        ' attempts to remove the network connection.
        ' objNetwork is the Network object, with global scope.
          On Error Resume Next
          objNetwork.RemoveNetworkDrive strDrive, True, True
          If err.Number = 0 Then wsh.sleep 750: err.Clear
          objNetwork.MapNetworkDrive strDrive, strShare, False
        End Sub
        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment

        Working...
        X