Announcement

Collapse
No announcement yet.

Startup script not working right

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

  • Startup script not working right

    I have the default logon script I want to use on Small Business Server 2003 to map two network drives on the workstations. There are five servers on the network and I do not want drives mapped on these. There must be something wrong with my syntax because the servers always get their drives mapped. Any suggestions?

    @echo off
    \\SERVER1\Clients\Setup\setup.exe /s SERVER1
    rem
    rem check if server - skip drive mappings if server
    rem
    if %computername% == Server1 goto end
    if %computername% == AVPS3 goto end
    if %computername% == Avpserver1 goto end
    if %computername% == NAS goto end
    if %computername% == ERP goto end
    rem
    rem All client computers but server run these commands
    rem
    net time \\Server1 /set /y
    net use z: /d
    net use z: \\NAS\users\%username%
    net use y: /d
    net use y: \\nas\shared
    :end
    Network Engineers do IT under the desk

  • #2
    Re: Startup script not working right

    Have you tried "echo %computername%" to see what gets reported back?
    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: Startup script not working right

      Yes I have, SERVER1 gets reported. I tried changing Server1 to SERVER1 in the startup file but that did not make any difference.

      Thanks,
      Network Engineers do IT under the desk

      Comment


      • #4
        Re: Startup script not working right

        Why don't you make it a logon script for users instead of a startup script for computers?

        Comment


        • #5
          Re: Startup script not working right

          I'm not sure why this command should run every time a user log-on to the computer..
          "\\SERVER1\Clients\Setup\setup.exe" /s SERVER1

          In the thread title you say "Startup script", while in the post you write "logon script".
          It must be a logon script, to be able to map the networdk drives for the user.

          For all the If statements in your batch, use the /i switch like,
          if /i "%computername%"=="Server1" goto :end
          to make case insensitive comparison of the two strings.

          Between
          net use z: /delete (also with, net use y: /delete /yes)
          and
          net use z: "\\NAS\users\%username%" /persistent:no
          there should be a delay between both command for about 3 seconds before you can use the same drive letter!
          like,
          If exist "y:" (net use y: /delete /yes & ping 127.0.0.1 -n 2)>nul
          net use y: "\\nas\shared" /persistent:no



          \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


          • #6
            Re: Startup script not working right

            I am more interested in finding a solution why this does not work - it used to.
            Network Engineers do IT under the desk

            Comment


            • #7
              Re: Startup script not working right

              Hi,

              Try this:
              Code:
              @echo off
              \\SERVER1\Clients\Setup\setup.exe /s SERVER1
              rem 
              rem check if server - skip drive mappings if server 
              rem 
              if /I %computername% == Server1 goto end
              if /I %computername% == AVPS3 goto end 
              if /I %computername% == Avpserver1 goto end 
              if /I %computername% == NAS goto end 
              if /I %computername% == ERP goto end 
              rem 
              rem All client computers but server run these commands 
              rem 
              net time \\Server1 /set /y 
              net use z: /d
              net use z: \\NAS\users\%username%
              net use y: /d
              net use y: \\nas\shared
              :end
              Caesar's cipher - 3

              ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

              SFX JNRS FC U6 MNGR

              Comment


              • #8
                Re: Startup script not working right

                This works. How important is the ":" before 'end' in the command lines?

                Thanks,


                @echo off
                \\SERVER1\Clients\Setup\setup.exe /s SERVER1
                rem delete old drive maps
                net use z: /d
                net use y: /d
                rem
                rem check if server - skip drive mappings if server
                rem
                if /i "%COMPUTERNAME%"=="server1" goto :end
                if /i "%computername%"=="AVPS3" goto :end
                if /i "%computername%"=="Avpserver1" goto :end
                if /i "%computername%"=="NAS" goto :end
                if /i "%computername%"=="ERP" goto :end
                rem
                rem All client computers but server run these commands
                rem
                net time \\Server1 /set /y
                net use z: \\NAS\users\%username%
                net use y: \\nas\shared
                :end
                Network Engineers do IT under the desk

                Comment


                • #9
                  Re: Startup script not working right

                  A practitioners prospective,

                  I am not sure how important it is but when I tried the script without ":" it worked.
                  I know the colon is used in conjunction with Goto to denote a label so Not quite sure why is working without.

                  Also I far as I know the /i switch is used to render comparisons insensitive to case.
                  So when the case is correct why need the /i switch?
                  Caesar's cipher - 3

                  ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

                  SFX JNRS FC U6 MNGR

                  Comment


                  • #10
                    Re: Startup script not working right

                    Originally posted by RobW View Post
                    This works. How important is the ":" before 'end' in the command lines?
                    The ":" indicates a batch label (name is case sensitive). To answer your question, it is not neccesary to enter ":" before the name of the label with the Goto statements.

                    What most likely has solved the problem is the /I switch. And probably also the change of the order of the commands - so there might now be a small delay between diconnecting and reconnecting the same drive letter, although it still is not a relaiable solution. A delay of 2 second is recommended as discussed in the scripting forum a few times.

                    \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


                    • #11
                      Re: Startup script not working right

                      Originally posted by Rems View Post
                      I'm not sure why this command should run every time a user log-on to the computer..
                      "\\SERVER1\Clients\Setup\setup.exe" /s SERVER1
                      Agreed, that's the default for SBS 2003 though. Throws up a lovely error message when a non-admin logs on, naturally.

                      I guess it's run every time so that any changes made are reflected on the machine... would be nice if it didn't show an error message for standard users though.
                      Gareth Howells

                      BSc (Hons), MBCS, MCP, MCDST, ICCE

                      Any advice is given in good faith and without warranty.

                      Please give reputation points if somebody has helped you.

                      "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

                      "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

                      Comment


                      • #12
                        Re: Startup script not working right

                        Thanks for the update gi

                        FWIW, a possible workaround for the lovely error message when a non-admin logs on could be,
                        Code:
                        @echo off
                        
                        :: If is local Admin
                        Set "IsAdmin=True"  ELSE
                        FOR /F "tokens=*" %%* IN (
                         'WMIC.exe quit 2^>^&1 1^>NUL'
                         ) DO Set "IsAdmin="
                        
                        If defined IsAdmin (
                          "\\SERVER1\Clients\Setup\setup.exe" /s SERVER1
                        )
                        The code will not work on SBS 2000


                        \Rems
                        Last edited by Rems; 16th December 2008, 21:00.

                        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


                        • #13
                          Re: Startup script not working right

                          Good point. The alternative would be to remove that script from NETLOGON entirely and use Group Policy. If you apply that policy to the user netsetup then even better - that is the user that is logged in after the reboot when you join a machine to the domain using the wizard. Failing that, just apply the policies to admins. The executable runs silently so shouldn't inconvenience anyone when it does run.
                          Gareth Howells

                          BSc (Hons), MBCS, MCP, MCDST, ICCE

                          Any advice is given in good faith and without warranty.

                          Please give reputation points if somebody has helped you.

                          "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

                          "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

                          Comment

                          Working...
                          X