Announcement

Collapse
No announcement yet.

Script to map drive if it fails to map on logon to windows

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

  • Script to map drive if it fails to map on logon to windows

    Hi All,
    hope you are are doing fine and good

    I am using NAS and create everyone's personal folders on that, and i want to map them automatically, and they all are laptop users (some are also on wireless) so sometime it happen they will not get the connectivity at log on to the windows, so map drive fails to connect. These all users are High Level (Managers and Directors) i don't ask them to manually click on bat files.

    So is there any way to solve this problem? or can say handle this situation??

    The idea is on mine mind is that there should me a bat script who run at {startup} looking for ping for some internal IP address if he not able to find the desired ip it remain running on a loop and if he able found the desired ip then he will map the drive and quit.

    and i will hope this will be also helpful to others also..

    Thanks in advance.

    Aman Dhally

  • #2
    Re: Script to map drive if it fails to map on logon to windows

    You can try this first:
    Configure the logon script at the user object (this way it will not use Fast Logon Optimization).

    OR,
    turn off Fast Logon Optimization, by:
    Enable the 'Always wait for the network at computer startup and logon' Group Policy setting.
    => Computer Configuration\Administrative Templates\System\Logon\
    and, Disable the 'Run logon scripts synchronously' policy setting.
    => Computer Configuration\Administrative Templates\System\Scripts\



    Yes, your batch idea will work too, but it should be initiated by a logon script though not from a startup script and depending how you would launch this program you might have to Disable the 'Run logon scripts synchronously' policy setting at user level or computer level.

    An alternative could also be to schedule a script to run every ...minutes - that script will then check if the mapping is there if not it will do the mapping.


    Here is a sample of "a batch script who run at {logon} that will ping for some internal IP address until that server starts replying then it will map the drive".

    Code:
    :: Check every ~3 seconds if the gateway- or other
    :: server has become available.
    :: Stop checking after 60 loops.
    
    @echo off & setlocal
    
    Set "Server=192.168.10.253"
    
    :: progressbar
    title Waiting for Network
    Set "write=<nul Set/p" 
    %write%=Wait
    
    :BeginLoop
       >nul (
       set /a "i=%i%+1"
       ping -n 1 -w 3000 %Server%|findstr /ir "\<TTL=[0-9].*\>"
       )&&(Goto:MyBatch)
       %write% n=.%n%
       If %i% EQU 60 (echo. %i% STOPPED & Goto:EndLoop
       ) Else (goto:BeginLoop)
    :EndLoop
    goto:end
    
    :MyBatch
    echo your code comes here,
    
    :end
    rem pause
    \Rems
    Last edited by Rems; 7th July 2009, 19:29.

    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


    • #3
      Re: Script to map drive if it fails to map on logon to windows

      Hi Rems,
      Thanks for the reply,

      I have added the few lines in
      :MyBatch
      echo your code comes here,

      :: i add this line

      net use z: \\192.168.1.10\sharefolder

      I save it this file as bat and add this file in startup folder but it not working on startup and i also tried to schedule this file y using schedule task > run when user log on but output is same..

      But when i double click that file, then it is working fine..

      Is there is nay step which i am missing ?????

      Thanks
      Aman Dhally

      Comment


      • #4
        Re: Script to map drive if it fails to map on logon to windows

        no reply

        Comment


        • #5
          Re: Script to map drive if it fails to map on logon to windows

          What name did you gave the batch file?

          How long does it take approx. before the WiFi is connected and the server connectable?

          After each unsuccesfull test try raising the max loopcount number "t",
          (This is the time-out value for the batch, every loop is about 3 seconds):

          Code:
          @echo off & setlocal
          
          :: Check every ~3 seconds if the gateway- or other
          :: server has become available.
          :: Stop checking after "t" loops.
          Set "t=180"
          
          >NUL 2>&1 (Net.exe use Z: /d /y )
          Set "Server=192.168.1.10"
          
          :: progressbar
          echo\&title Waiting for Network
          Set "write=<nul Set/p" 
          %write%=Wait
          
          :BeginLoop
             >nul (
             set /a "i=%i%+1"
             ping.exe -n 1 -w 3000 %Server%|findstr.exe /ir "\<TTL=[0-9].*\>"
             )&&(Goto:MyBatch)
             %write% d=.%d%
             If %i% EQU %t% (echo. %i% STOPPED & Goto:EndLoop
             ) Else (goto:BeginLoop)
          :EndLoop
          goto:end
          
          :MyBatch
          echo\&echo\
          Net.exe use Z: "\\%Server%\sharefolder" /persistent:no
          
          :end
          pause
          note that the mapping should be Non-persistent.
          Delete Z: (if exist) before checking for network.

          \Rems
          Last edited by Rems; 9th July 2009, 16:42.

          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: Script to map drive if it fails to map on logon to windows

            Hi Rems,

            Thanks a lot, yes this script works for me i increased the time to {180} to {500} it works

            The only one thing more , after running sucessfully it ask for press any key to continue

            can you make them auto quit ? { because then it not requir any user intrection }
            rest of all is work great

            Thanks a lot again Rems

            Regards :

            Aman DHallY

            Comment


            • #7
              Re: Script to map drive if it fails to map on logon to windows

              remove the pause

              Comment


              • #8
                Re: Script to map drive if it fails to map on logon to windows

                hi, wullieb1

                Thanks a lot .......

                I am thanksful to you

                Regards
                AMan dhally

                Comment

                Working...
                X