Announcement

Collapse
No announcement yet.

VBS logon script map drive with different credentials

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBS logon script map drive with different credentials

    I am in the process of creating a new logon script using VBS, that i am new too.

    The old one was in a bacth file format and worked fine. One of the problem I am findind hard to over come is mapping a drive with different user credentials. My normal drive mappings work fine. But the one I need to get working is to a FTP server that certain users logon to with a generic username/password. In the batch file I use the NET USE command, but i have no idea what I would use in VBS.

    Any ideas?

    many thanks

  • #2
    Re: VBS logon script map drive with different credentials

    Don't know scripting either, but I can Google. Check out the result for net use in vbs. That should help.
    1 1 was a racehorse.
    2 2 was 1 2.
    1 1 1 1 race 1 day,
    2 2 1 1 2

    Comment


    • #3
      Re: VBS logon script map drive with different credentials

      Thanks biggles77

      I was using a different search on google, but your one got me what i needed.

      I added this to my logon script and it works perfect... so far, a little more testing to be done

      -----
      Dim objNetwork
      Set objNetwork = WScript.CreateObject("WScript.Network")
      strLocalDrive = "L:"
      strRemoteShare = "\\server\share_name"
      strPer = "FALSE"
      strUsr = "username"
      strPas = "password"
      objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
      -----

      Comment


      • #4
        Re: VBS logon script map drive with different credentials

        Excellent. Can you post back with the full script once you have finished testing it. I'm sure it will be useful to others. Thanks.
        1 1 was a racehorse.
        2 2 was 1 2.
        1 1 1 1 race 1 day,
        2 2 1 1 2

        Comment


        • #5
          Re: VBS logon script map drive with different credentials

          As not to go off topic with this post I have removed most of everything else in this script apart from anything relating to drive mappings.

          Please note I am no expert in scripting and the information below should be properly tested if you intend to use it.

          The script below maps drives for uses in two ways. First off, it will give all users the default shares and there home drive (P, S, X).

          Then it checks what groups a user is a member of and attaches the appropriate drives. (W, U, Z, M, L)

          Drives M, L attach to another server and also use different logon credentials. If you required another drive with different credentials, you could try…

          On the line

          Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path, objNetwork, objNetwork1

          Add another value “objNetwork2”

          Then find in the script below and copy and paste it to a new section. Then replace all the 1’s with 2’s.

          Amend the username, password and the share to reflect the desired connection. And fingers crossed it should work.

          Set objNetwork1 = WScript.CreateObject("WScript.Network")
          strLocalDrive1 = "L:"
          strRemoteShare1 = "\\server\share"
          strPer1 = "FALSE"
          strUsr1 = "username"
          strPas1 = "password"
          objNetwork1.MapNetworkDrive strLocalDrive1, strRemoteShare1, strPer1, strUsr1, strPas1

          ‘ ------ Script START ------

          ON ERROR RESUME NEXT

          Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path, objNetwork, objNetwork1

          Set WSHShell = CreateObject("WScript.Shell")
          Set WSHNetwork = CreateObject("WScript.Network")
          'Automatically find the domain name
          Set objDomain = getObject("LDAP://rootDse")
          DomainString = objDomain.Get("dnsHostName")
          WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

          'Grab the user name
          UserString = WSHNetwork.UserName
          'Bind to the user object to get user name and check for group memberships later
          Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

          'Grab the computer name for use in add-on code later
          strComputer = WSHNetwork.ComputerName

          'Disconnect ALL mapped drives
          Set clDrives = WshNetwork.EnumNetworkDrives
          For i = 0 to clDrives.Count -1 Step 2
          WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
          Next

          'Give the PC time to do the disconnect, wait 300 milliseconds
          wscript.sleep 300

          'Map drives
          'Note the first command uses the user name as a variable to map to a user share.
          WSHNetwork.MapNetworkDrive "p:", "\\server\users\" & UserString,True
          WSHNetwork.MapNetworkDrive "s:", "\\server\standards",True
          WSHNetwork.MapNetworkDrive "X:", "\\server\company",True

          'Now check for group memberships and map appropriate drives
          For Each GroupObj In UserObj.Groups
          Select Case GroupObj.Name
          'Check for group memberships and take needed action
          Case "grp-Admin_tools"
          WSHNetwork.MapNetworkDrive "w:", "\\server\share",True
          WSHNetwork.MapNetworkDrive "u:", "\\server\share",True
          Case "grp-temp-user"
          WSHNetwork.MapNetworkDrive "w:", "\\Server\Share",True
          Case "grp-FTP-root-rw"
          Set objNetwork = WScript.CreateObject("WScript.Network")
          strLocalDrive = "M:"
          strRemoteShare = "\\server\share"
          strPer = "FALSE"
          strUsr = "username"
          strPas = "password"
          objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
          Case "grp-ftp-root-r"
          Set objNetwork1 = WScript.CreateObject("WScript.Network")
          strLocalDrive1 = "L:"
          strRemoteShare1 = "\\server\share"
          strPer1 = "FALSE"
          strUsr1 = "username"
          strPas1 = "password"
          objNetwork1.MapNetworkDrive strLocalDrive1, strRemoteShare1, strPer1, strUsr1, strPas1
          End Select
          Next

          '=====================================
          'Add On Code goes above this line

          'Clean Up Memory We Used
          set UserObj = Nothing
          set GroupObj = Nothing
          set WSHNetwork = Nothing
          set DomainString = Nothing
          set WSHSHell = Nothing
          Set WSHPrinters = Nothing
          Set objNetwork = Nothing
          Set objNetwork1 = Nothing

          'Quit the Script
          wscript.quit

          ‘ ------ Script END ------

          Comment


          • #6
            Re: VBS logon script map drive with different credentials

            Thank You Brian. We apprieciate your Community spirit.
            1 1 was a racehorse.
            2 2 was 1 2.
            1 1 1 1 race 1 day,
            2 2 1 1 2

            Comment


            • #7
              Re: VBS logon script map drive with different credentials

              no problem I have found a load of usefull information here.

              Five minutes posting is nothing to the time this site has saved me already ! Being a newbie to a windows server enviroment !

              Comment


              • #8
                Re: VBS logon script map drive with different credentials

                All I have to say is Brian873 you rule. I've been trying to put a script like this together forewver, but thougt using kix was the only way to do it. I took your script modifed it and it worked great. So I added printer maps and added zone groups for my users, and added them to the zones, and was able to create default printer maps, based on zone groups. I've pasted the modified script below. Thanks so much. This has saved me a LOT of time and headaches rooting through all the different functions I'd have to learn from scratch, only to figure out, it isn't the one I want. You know the process. Thanks again. Also it should be noted for those with less experience programming, etc. there are a few spaces, carrier returns, and the such that need to be removed if you cut and paste the script to an editor (Word Wrap or strange custom formatting). Once you run the VBS script it will give you the exact location of the offending character. Just start with Brian's script, and make sure it looks EXACTLY like that, and you should be in good shape. Thanks:


                'COMPANY Draft Login Script
                'October 2006
                'SFCG
                'Code almost explicitly taken from http://forums.petri.com/showthread.php?t=9607
                'Thanks Brian873 for doing all the work for me

                ON ERROR RESUME NEXT

                Dim WSHShell, WSHNetwork, objDomain, DomainString,UserString, UserObj, Path, objNetwork, objNetwork1

                Set WSHShell = CreateObject("WScript.Shell")

                '---------------------------------- Printer Maps ----------------------------------------
                '
                '***** SAM *****

                Set WshNetwork = CreateObject("WScript.Network")
                WshNetwork.AddWindowsPrinterConnection "\\server\SAM"


                '***** SYD *****

                Set WshNetwork = CreateObject("WScript.Network")
                WshNetwork.AddWindowsPrinterConnection "\\server\syd"

                '**** COLOR ****

                Set WshNetwork = CreateObject("WScript.Network")
                WshNetwork.AddWindowsPrinterConnection "\\server\printer"


                '**** BETH ****

                Set WshNetwork = CreateObject("WScript.Network")
                WshNetwork.AddWindowsPrinterConnection "\\server\beth"

                '--------------------- Drive Maps & Default Printer Settings ---------------------------
                '
                'DRIVE MAPPINGS UNC PATH Group with permissions to Drive
                '
                'DEPARTMENTAL MAPPINGS
                'I: \\server\Administration$ Administration
                'J: \\server\IT$ Tech
                'K: \\server\NewAccounts$ NewAccounts
                'L: \\server\SalesAndMarketing$ SalesAndMarketing
                'M: \\server\CarrierManagment$ CarrierManagement
                'N: \\server\CustomerService$ CustomerService
                '
                'COMMON MAPPINGS
                'E: \\server\share
                'S: \\server\share2
                '
                'USER MAPPINGS
                'H: \\server\%USERNAME%$ Individual Users (Active Directory)
                '
                'SPECIAL MAPPINGS
                'Z: \\server\appdata SPECIAL


                Set WSHNetwork = CreateObject("WScript.Network")

                'Automatically find the domain name
                Set objDomain = getObject("LDAP://rootDse")
                DomainString = objDomain.Get("dnsHostName")
                WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

                'Grab the user name
                UserString = WSHNetwork.UserName

                'Bind to the user object to get user name and check for group

                memberships later
                Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

                'Grab the computer name for use in add-on code later
                strComputer = WSHNetwork.ComputerName

                'Disconnect ALL mapped drives
                Set clDrives = WshNetwork.EnumNetworkDrives
                For i = 0 to clDrives.Count -1 Step 2
                WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
                Next

                'Give the PC time to do the disconnect, wait 300 milliseconds
                wscript.sleep 300

                'Map drives
                'Note the first command uses the user name as a variable to map to a user share.
                'WSHNetwork.MapNetworkDrive "p:", "\\server\users\" & UserString,True (COMMENTED FOR REFERENCE)
                WSHNetwork.MapNetworkDrive "e:", "\\server\share",True
                WSHNetwork.MapNetworkDrive "s:", "\\server\share2",True

                'Now check for group memberships and map appropriate drives
                For Each GroupObj In UserObj.Groups
                Select Case GroupObj.Name


                'Check for group memberships and take needed action

                Case "Administration"
                WSHNetwork.MapNetworkDrive "I:", "\\server\administration$",True

                Case "IT"
                WSHNetwork.MapNetworkDrive "J:", "\\server\it$",True

                Case "NewAccounts"
                WSHNetwork.MapNetworkDrive "K:", "\\server\newaccounts$",True

                Case "SalesAndMarketing"
                WSHNetwork.MapNetworkDrive "L:", "\\server\salesandmarketing$",True

                Case "CarrierManagement"
                WSHNetwork.MapNetworkDrive "M:", "\\server\carriermanagement$",True

                Case "CustomerService"
                WSHNetwork.MapNetworkDrive "N:", "\\server\customerservices$",True


                'Check for Zone Group and map appropriate default printer

                Case "SFZONE1"
                WshNetwork.SetDefaultPrinter "\\server\SAM"

                Case "SFZONE2"
                WshNetwork.SetDefaultPrinter "\\server\SYD"

                Case "SFZONE3"
                WshNetwork.SetDefaultPrinter "\\server\BETH"

                'COMMENTED FOR REFERENCE

                'WSHNetwork.MapNetworkDrive "w:", "\\Server\Share",True
                'Case "grp-FTP-root-rw"
                'Set objNetwork = WScript.CreateObject("WScript.Network")
                'strLocalDrive = "M:"
                'strRemoteShare = "\\server\share"
                'strPer = "FALSE"
                'strUsr = "username"
                'strPas = "password"
                'objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare,

                'strPer, strUsr, strPas
                'Case "grp-ftp-root-r"
                'Set objNetwork1 = WScript.CreateObject("WScript.Network")
                'strLocalDrive1 = "L:"
                'strRemoteShare1 = "\\server\share"
                'strPer1 = "FALSE"
                'strUsr1 = "username"
                'strPas1 = "password"
                'objNetwork1.MapNetworkDrive strLocalDrive1, strRemoteShare1,

                'strPer1, strUsr1, strPas1
                End Select
                Next

                '=====================================
                'Add On Code goes above this line

                'Clean Up Memory We Used
                Set UserObj = Nothing
                Set GroupObj = Nothing
                Set WSHNetwork = Nothing
                Set DomainString = Nothing
                Set WSHSHell = Nothing
                Set WSHPrinters = Nothing
                Set objNetwork = Nothing
                Set objNetwork1 = Nothing

                'Quit the Script
                wscript.quit
                Last edited by sfcg; 4th October 2006, 21:42.

                Comment


                • #9
                  Re: VBS logon script map drive with different credentials

                  No worries SFCG. Glad it helped you.

                  This site has gave me a lot of good advice, so I hope I can give some back.

                  Although a little REP wwould not go a miss

                  Comment


                  • #10
                    Re: VBS logon script map drive with different credentials

                    Well I implemented this script enterprise wide yesterday, and all things considered, it went pretty well. One problem I did run into was there was a Linux machine I needed users to be able map to via Samba, so I used your map via username and password section. I quickly found out that users needed to be able to use their individual logins to this machine, as certain applications would not work with multiple of the same user logging in. I decided to modify your script by using the InputBox object. This not only allows for individuals to add their logins individually, but does not store a username and password in the script in a public folder that anyone can access :P

                    Anyhow, here was the example of the slight modification:

                    Case "Domain Users"
                    Set objNetwork = WScript.CreateObject("WScript.Network")
                    strLocalDrive = "S:"
                    strRemoteShare = "\\Server\Share"
                    strPer = "FALSE"
                    strUsr = InputBox("Username for S: drive:")
                    strPas = InputBox("Password for S: drive:")
                    objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas


                    The one problem I have with this is that you cannot mask the InputBox object for the password. Pretty bunk, but oh well. It works.

                    Once again, thanks Brian, and Petri people. You've saved the day once again.

                    Chris

                    Comment


                    • #11
                      Re: VBS logon script map drive with different credentials

                      BTW Biggles, I stole your sig for my email :P

                      Comment


                      • #12
                        Re: VBS logon script map drive with different credentials

                        SFCG - Nice touch I might use that myself (input box) !

                        And I just found this link that may help you hide the content of the input box

                        http://www.danielklann.com/excel/hid...a_inputbox.htm


                        hail hail
                        Last edited by brian873; 11th October 2006, 09:54.

                        Comment


                        • #13
                          Re: VBS logon script map drive with different credentials

                          Just to let you know I started another thread to figure out the password masking. I resolved it and it works great, but requires running the script from cscript on the command line, and also won't work before XP. Anyhow, here's the thread. Thanks again!

                          http://forums.petri.com/showthread.p...ed=1#post42763

                          Chris

                          Comment


                          • #14
                            Re: VBS logon script map drive with different credentials

                            I have the script mapping the drives etc. working just fine. Is there a way to map the drive and then hide it from Windows Explorer. I have certain apps that require a mapped drive. I just want to try and remove some temptation to go exploring.

                            This is part of my mapping method;

                            'If IsMember(objUser, "Administrative") then
                            ' objNetwork.MapNetworkDrive "j:", "\\servername\quickbooks"
                            'end if

                            Thanks

                            sghmsh

                            Comment


                            • #15
                              Re: VBS logon script map drive with different credentials

                              AFAIK you can only hide the letters of local drives.

                              The best you can do is deleting the name that is next to the mapped drive, then there will only be just a letter.
                              Next thing is to hide files and folders on that share. And Prevent users from viewing hidden files and Folders with a GPO.

                              'sghmsh' it is better to start a new thread if you have a new question, instead of 'hijacking' an old thread. Look at the title of this thread, it has not much with 'hiding drive letters'.


                              \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