Announcement

Collapse
No announcement yet.

Logoff Script for Dissconnecting Mapp Drives .

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

  • Logoff Script for Dissconnecting Mapp Drives .

    we are using windows server 2003 .I use a login script in GPO

    User Configuration.....>Windows Settings......>Script.....>Login

    In bat file i write the script with the following sysntex

    NET USE Z: \\SERVER_NAME\Sahre Folder Name

    On the client side when the user login through domain controller he/she can see Mapp drive automatically in My computer.

    I want that when ever the user Logg off it automatically disconnect the mapp drive.Please guide me that how can i do that

    thanks in advance for help.
    mypass

  • #2
    Re: Logoff Script for Dissconnecting Mapp Drives .

    Hi,

    Code:
    net use f: \\SERVER_NAME\Sahre /delete
    Caesar's cipher - 3

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

    SFX JNRS FC U6 MNGR

    Comment


    • #3
      Re: Logoff Script for Dissconnecting Mapp Drives .

      Thanks "L4ndy" please just clear me that should I write the script

      in a new bat file and use it script under "Logoff" ? or write it in same login script ?

      net use f: \\SERVER_NAME\Sahre /delete
      Last edited by mypass604; 15th October 2009, 09:50.

      Comment


      • #4
        Re: Logoff Script for Dissconnecting Mapp Drives .

        Originally posted by mypass604 View Post
        we are using windows server 2003 .I use a login script in GPO

        User Configuration.....>Windows Settings......>Script.....>Login

        In bat file i write the script with the following sysntex

        NET USE Z: \\SERVER_NAME\Sahre Folder Name

        I want that when ever the user Logg off it automatically disconnect the mapp drive.Please guide me that how can i do that

        thanks in advance for help.
        mypass
        The default setting for mappings to shared folders is set to not-persistent. The connection being made or subsequent connections are not saved when the user logoff.

        To control this you can add the /persistent switch to your current batch, like
        NET USE Z: "\\SERVER_NAME\Sahre Folder Name" /PERSISTENT:NO

        /persistent: { yes | no } : Controls the use of persistent network connections. The default is the setting used last. Deviceless connections are not persistent. Yes saves all connections as they are made, and restores them at next logon. No does not save the connection being made or subsequent connections. Existing connections are restored at the next logon. Use /delete to remove persistent connections.


        \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


        • #5
          Re: Logoff Script for Dissconnecting Mapp Drives .

          thanks for t reply. is there any space between

          PERSISTENT:NO

          or

          PERSISTENT :NO


          I have made three map drives

          NET USE x: \\SERVER_NAME\Sahre Folder Name /PERSISTENT:NO
          NET USE y: \\SERVER_NAME\Sahre Folder Name /PERSISTENT:NO
          NET USE z: \\SERVER_NAME\Sahre Folder Name /PERSISTENT:NO

          I remove following two lines from my bat file

          NET USE y: \\SERVER_NAME\Sahre Folder Name /PERSISTENT:NO
          NET USE z: \\SERVER_NAME\Sahre Folder Name /PERSISTENT:NO


          In my client computer I can still see both three map drives X, Y and Z . I even use gpupdate command as well restart my server, client computer also
          please guide me where iam doing mistake?



          some use people use %username% i.e

          NET USE Z: "\\SERVER_NAME\Sahre Folder Name\"%username% " /PERSISTENT:NO


          please guide me what is %username% ? after the share folder name and what is its purpose?

          thanks
          Last edited by mypass604; 15th October 2009, 11:34.

          Comment


          • #6
            Re: Logoff Script for Dissconnecting Mapp Drives .

            There should be no spaces in the switch /PERSISTENT:NO


            What might be causing the disconnecting issue:
            When a previous connection is being restored after every user logon it means that it has been made persistent somewere in the past.

            In that case, that drive letter is not available for the Net Use command to make a (re-)connection.
            So your logon script will fail changing the existing Persistent mapping to 'Persistent:No'.
            Even if you try to map it to the same share on the network, an error message showing the drive letter is already in use and the net use command fails.

            The persistently mapped drive letters you like to re-use in the script need to be disconnected first in the script:
            Code:
            @echo off & setlocal ENABLEEXTENSIONS
            goto:eoMapDrive
                :MapDrive
                setlocal
                Set "DrvLetter=%~1" & Set "NetworkPath=%~2"
                If exist %DrvLetter% (
                   2>nul Net.exe Use %DrvLetter% /Delete /Yes &&(
                   1>nul ping.exe -n 1 -w 1000 0.0.0.1))
                NET.exe USE %DrvLetter% "%NetworkPath%" /PERSISTENT:NO
                endlocal
                exit /b 0
            :eoMapDrive
            
            call:MapDrive x: "\\SERVER_NAME\Sahre Folder\folder test 1"
            call:MapDrive y: "\\SERVER_NAME\Sahre Folder Name\%username%"
            call:MapDrive z: "\\SERVER_NAME\Sahre Folder Name"
            
            endlocal
            This batch sample make use of a subroutine. The 3 lines starting with call:MapDrive are calling this subroutine with the 2 parameters. I used a subroutine in this batch just because this way I don't have to re-type these lines for every mapping.

            Note, the ":MapDrive" label (name of the subroutine) is case sensitive.

            Subsequently, the routine checks if the provided drive letter is available. If the drive letter is in-use it tries to disconnect it. If successfull disconnected it pauses the batch for about one second (that Pause is performed by the ping statement). The pause is needed for Explorer to refresh first before the same drive letter can be connected correctly to another UNC path.
            Next, the Net Use command will try to map the drive letter to the provided UNC.


            Originally posted by mypass604 View Post

            some use people use %username% i.e

            NET USE Z: "\\SERVER_NAME\Sahre Folder Name\"%username% " /PERSISTENT:NO

            please guide me what is %username% ? after the share folder name and what is its purpose?
            Mind unwanted quote-signs and extra spaces, the UNC in your sample should be like,
            "\\SERVER_NAME\Sahre Folder Name\%username%"

            The variable %username% will automatically expand the name of the logged-on user - and most likely maching a name of an existing folder on the network.


            \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


            • #7
              Re: Logoff Script for Dissconnecting Mapp Drives .

              thanks a lot "Rems" for your detail reply. Well you have used VB script.Is there any option to use bat file to do all these steps .

              I am not a good programmer so I prefer to use bat file.I does't know that is there any way of disconnect the map drives using bat file?

              2- I want to know that where should i keep the vb script file for mapping drive?
              Last edited by mypass604; 16th October 2009, 09:11.

              Comment


              • #8
                Re: Logoff Script for Dissconnecting Mapp Drives .

                Hi mypass,

                The sample in my previous post actualy is a batch file, it should be saved with the extension *.bat.


                For disconnecting the mapped drives the batch also use a NET USE statement.
                Like,

                NET USE x: /DELETE
                NET USE y: /DELETE /Y
                NET USE z: /DELETE


                Or, to disconnect *all* currently mapped drives at the same time, do:
                NET USE * /DELETE

                The switch /DELETE is the same as /DEL or /D
                After the switch /DELETE you can also add an additional parameter /YES or /Y. The undocumented /YES switch makes NET USE to continue trying to disconnect if the drive would currently be active (note however, disconnecting will fail anyway when there are currently open files on that drive).

                When the script makes non-persistent mapping, these mappings will be lost after the user logs-off. So normally you only have to delete a persistent drive just once with the script and it won't show up a next time - unless the user would disconnect the drive letter and manualy connect the drive again, in most cases drive mapping manualy created by the user are made persistent.
                Therefore it could possibly be a good practise to start all batches that mappes drives with NET USE * /D /Y first to make drive letters available.

                If a drive letter was unmapped by the batch, and that same letter will be mapped to a new share within the same batch there should be added a pause of a few seconds between both actions. You can use PING commands to create the delay in the batch.

                The sample below tries to disconnect all currently mapped drives. Then it pause for 3 seconds after the deletion but only if there were any mapped drives found.
                Code:
                @echo off
                For /f "delims=" %%* in ('net.exe use * /d /y ^|find "\\"') do set "_Del=TRUE"
                If /i [%_Del%]==[TRUE] 1>nul ping -n 3 127.0.0.1
                Add the two lines above to the beginning of your existing batch file.

                Optionally, after the drive is being mapped it is even possible to configure a custom name (drive label) for it with the batch: see http://forums.petri.com/showthread.p...751#post181751.
                I like giving a custom name to mapped drives for hiding the UNC path for the users.


                \Rems
                Last edited by Rems; 16th October 2009, 11:22.

                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


                • #9
                  Re: Logoff Script for Dissconnecting Mapp Drives .

                  thanks "Rems" a lot for the detail reply.I appreciate it. Well there is some more confusion about net use command.

                  1-In windows server 2003 i made two partions.On C drive windows is installed and on D drive is free for mapping drive to keep the users their files in it.

                  NET USE x: \\SERVER_NAME\Sahre Folder Name /PERSISTENT:NO
                  NET USE y: \\SERVER_NAME\Sahre Folder Name /PERSISTENT:NO
                  NET USE z: \\SERVER_NAME\Sahre Folder Name /PERSISTENT:NO


                  In this case if the "Sahre Folder Name" is on C drive then it is fine on the client side but what if the "Sahre Folder Name" is on D drive? i.e the D drive (2nd partion is for users files.) where can i write the server drive path in my NET USE command ? If I write my path as " D:\ "I can't see my map drives in my client machine

                  NET USE x: \\SERVER_NAME\Sahre Folder Name\Server Volume /PERSISTENT:NO
                  NET USE y: \\SERVER_NAME\Sahre Folder Name\Server Volume /PERSISTENT:NO
                  NET USE z: \\SERVER_NAME\Sahre Folder Name\Server Volume /PERSISTENT:NO





                  2- For writing a VBS please let me know any free software tool in which i can edit/debug it.

                  thanks









                  Last edited by mypass604; 17th October 2009, 09:48.

                  Comment


                  • #10
                    Re: Logoff Script for Dissconnecting Mapp Drives .

                    Well there was a mistake in my script which i was writing.i.e space issue. Now I can access drive in client side.Same thing which I did in mapping drive using C partition.

                    I need to know any site for learning VB script for windows server 2003. also can you suggest me any free tool to writeing vb script.

                    thanks many many times for your wonderfull help.
                    mypass

                    Comment

                    Working...
                    X