Logon Script with net use * /delete /yes











up vote
1
down vote

favorite
1












I'm trying to get rid of all manually mapped network drives on all workstations in my domain. I want our end-user's mapped drives to be mapped solely via GPO (GPO's are already in place).



I'm trying to write a script that will:




  1. Unmap all network drives when the user logs in

  2. Run gpupdate /f to re-map drives based on applied GPO


I'm planning to have this logon script policy applied only for a few weeks, until I can verify that all manually mapped drives are gone.



Here is the contents of my batch script:



REM Delete all mapped drives
net use * /del /y

REM force a group policy update to map all drives according to GPO's.
gpupdate /force

REM create a directory to verify the script is actually running.
mkdir %USERPROFILE%test


I've placed this script on my NETLOGON directory on my domain controller. The script runs as intended if manually run from this directory. However, when applied as a logon script, the net use /delete /yes command doesn't seem to work. I've verified that the script is actually running during logon with the mkdir %USERPROFILE%test.



I've even tried to redirect the output of the first command net use * /del /y > result.txt and the output came out as




"There are no entries in the list"




Is there any reason why my script is working when I run it manually, but not as a logon script?



Server: Windows 2012R2

Host: Windows 10










share|improve this question
























  • It may be running too early. Try putting a delay in the script of a few minutes. ping shows you how to add a delay using ping.
    – DavidPostill
    Apr 25 '16 at 19:11








  • 2




    This doesn't answer your question, but you may want to run the unmapping script as a logoff script. That way you don't compete with GPO mapping the drives, and the drives should be mapped at logoff (meaning they exist and you can unmap them).
    – Patrick Seymour
    Apr 25 '16 at 19:29












  • @DavidPostill I just tried adding a sleep 300 before the unmap command, and other sleep 100 before the gpupdate /f. The output still says "There are no entries in the list."
    – Francis Batalla
    Apr 25 '16 at 19:35










  • @PatrickS. I've switched the script to run at logoff instead. Also, I've shortened the script to contain ONLY the unmapping drives cmd and a script run verification (send output to text file). My drives are still remaining mapped. Any other suggestions?
    – Francis Batalla
    Apr 25 '16 at 19:46










  • My comment wasn't intended as an answer, just a suggestion on when to run the script. In fact, I tried what you're doing, and it worked for me on a Windows 10 machine.
    – Patrick Seymour
    Apr 25 '16 at 20:23















up vote
1
down vote

favorite
1












I'm trying to get rid of all manually mapped network drives on all workstations in my domain. I want our end-user's mapped drives to be mapped solely via GPO (GPO's are already in place).



I'm trying to write a script that will:




  1. Unmap all network drives when the user logs in

  2. Run gpupdate /f to re-map drives based on applied GPO


I'm planning to have this logon script policy applied only for a few weeks, until I can verify that all manually mapped drives are gone.



Here is the contents of my batch script:



REM Delete all mapped drives
net use * /del /y

REM force a group policy update to map all drives according to GPO's.
gpupdate /force

REM create a directory to verify the script is actually running.
mkdir %USERPROFILE%test


I've placed this script on my NETLOGON directory on my domain controller. The script runs as intended if manually run from this directory. However, when applied as a logon script, the net use /delete /yes command doesn't seem to work. I've verified that the script is actually running during logon with the mkdir %USERPROFILE%test.



I've even tried to redirect the output of the first command net use * /del /y > result.txt and the output came out as




"There are no entries in the list"




Is there any reason why my script is working when I run it manually, but not as a logon script?



Server: Windows 2012R2

Host: Windows 10










share|improve this question
























  • It may be running too early. Try putting a delay in the script of a few minutes. ping shows you how to add a delay using ping.
    – DavidPostill
    Apr 25 '16 at 19:11








  • 2




    This doesn't answer your question, but you may want to run the unmapping script as a logoff script. That way you don't compete with GPO mapping the drives, and the drives should be mapped at logoff (meaning they exist and you can unmap them).
    – Patrick Seymour
    Apr 25 '16 at 19:29












  • @DavidPostill I just tried adding a sleep 300 before the unmap command, and other sleep 100 before the gpupdate /f. The output still says "There are no entries in the list."
    – Francis Batalla
    Apr 25 '16 at 19:35










  • @PatrickS. I've switched the script to run at logoff instead. Also, I've shortened the script to contain ONLY the unmapping drives cmd and a script run verification (send output to text file). My drives are still remaining mapped. Any other suggestions?
    – Francis Batalla
    Apr 25 '16 at 19:46










  • My comment wasn't intended as an answer, just a suggestion on when to run the script. In fact, I tried what you're doing, and it worked for me on a Windows 10 machine.
    – Patrick Seymour
    Apr 25 '16 at 20:23













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I'm trying to get rid of all manually mapped network drives on all workstations in my domain. I want our end-user's mapped drives to be mapped solely via GPO (GPO's are already in place).



I'm trying to write a script that will:




  1. Unmap all network drives when the user logs in

  2. Run gpupdate /f to re-map drives based on applied GPO


I'm planning to have this logon script policy applied only for a few weeks, until I can verify that all manually mapped drives are gone.



Here is the contents of my batch script:



REM Delete all mapped drives
net use * /del /y

REM force a group policy update to map all drives according to GPO's.
gpupdate /force

REM create a directory to verify the script is actually running.
mkdir %USERPROFILE%test


I've placed this script on my NETLOGON directory on my domain controller. The script runs as intended if manually run from this directory. However, when applied as a logon script, the net use /delete /yes command doesn't seem to work. I've verified that the script is actually running during logon with the mkdir %USERPROFILE%test.



I've even tried to redirect the output of the first command net use * /del /y > result.txt and the output came out as




"There are no entries in the list"




Is there any reason why my script is working when I run it manually, but not as a logon script?



Server: Windows 2012R2

Host: Windows 10










share|improve this question















I'm trying to get rid of all manually mapped network drives on all workstations in my domain. I want our end-user's mapped drives to be mapped solely via GPO (GPO's are already in place).



I'm trying to write a script that will:




  1. Unmap all network drives when the user logs in

  2. Run gpupdate /f to re-map drives based on applied GPO


I'm planning to have this logon script policy applied only for a few weeks, until I can verify that all manually mapped drives are gone.



Here is the contents of my batch script:



REM Delete all mapped drives
net use * /del /y

REM force a group policy update to map all drives according to GPO's.
gpupdate /force

REM create a directory to verify the script is actually running.
mkdir %USERPROFILE%test


I've placed this script on my NETLOGON directory on my domain controller. The script runs as intended if manually run from this directory. However, when applied as a logon script, the net use /delete /yes command doesn't seem to work. I've verified that the script is actually running during logon with the mkdir %USERPROFILE%test.



I've even tried to redirect the output of the first command net use * /del /y > result.txt and the output came out as




"There are no entries in the list"




Is there any reason why my script is working when I run it manually, but not as a logon script?



Server: Windows 2012R2

Host: Windows 10







windows batch network-shares group-policy net-use






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 27 '16 at 13:34









techraf

3,975111729




3,975111729










asked Apr 25 '16 at 19:07









Francis Batalla

613




613












  • It may be running too early. Try putting a delay in the script of a few minutes. ping shows you how to add a delay using ping.
    – DavidPostill
    Apr 25 '16 at 19:11








  • 2




    This doesn't answer your question, but you may want to run the unmapping script as a logoff script. That way you don't compete with GPO mapping the drives, and the drives should be mapped at logoff (meaning they exist and you can unmap them).
    – Patrick Seymour
    Apr 25 '16 at 19:29












  • @DavidPostill I just tried adding a sleep 300 before the unmap command, and other sleep 100 before the gpupdate /f. The output still says "There are no entries in the list."
    – Francis Batalla
    Apr 25 '16 at 19:35










  • @PatrickS. I've switched the script to run at logoff instead. Also, I've shortened the script to contain ONLY the unmapping drives cmd and a script run verification (send output to text file). My drives are still remaining mapped. Any other suggestions?
    – Francis Batalla
    Apr 25 '16 at 19:46










  • My comment wasn't intended as an answer, just a suggestion on when to run the script. In fact, I tried what you're doing, and it worked for me on a Windows 10 machine.
    – Patrick Seymour
    Apr 25 '16 at 20:23


















  • It may be running too early. Try putting a delay in the script of a few minutes. ping shows you how to add a delay using ping.
    – DavidPostill
    Apr 25 '16 at 19:11








  • 2




    This doesn't answer your question, but you may want to run the unmapping script as a logoff script. That way you don't compete with GPO mapping the drives, and the drives should be mapped at logoff (meaning they exist and you can unmap them).
    – Patrick Seymour
    Apr 25 '16 at 19:29












  • @DavidPostill I just tried adding a sleep 300 before the unmap command, and other sleep 100 before the gpupdate /f. The output still says "There are no entries in the list."
    – Francis Batalla
    Apr 25 '16 at 19:35










  • @PatrickS. I've switched the script to run at logoff instead. Also, I've shortened the script to contain ONLY the unmapping drives cmd and a script run verification (send output to text file). My drives are still remaining mapped. Any other suggestions?
    – Francis Batalla
    Apr 25 '16 at 19:46










  • My comment wasn't intended as an answer, just a suggestion on when to run the script. In fact, I tried what you're doing, and it worked for me on a Windows 10 machine.
    – Patrick Seymour
    Apr 25 '16 at 20:23
















It may be running too early. Try putting a delay in the script of a few minutes. ping shows you how to add a delay using ping.
– DavidPostill
Apr 25 '16 at 19:11






It may be running too early. Try putting a delay in the script of a few minutes. ping shows you how to add a delay using ping.
– DavidPostill
Apr 25 '16 at 19:11






2




2




This doesn't answer your question, but you may want to run the unmapping script as a logoff script. That way you don't compete with GPO mapping the drives, and the drives should be mapped at logoff (meaning they exist and you can unmap them).
– Patrick Seymour
Apr 25 '16 at 19:29






This doesn't answer your question, but you may want to run the unmapping script as a logoff script. That way you don't compete with GPO mapping the drives, and the drives should be mapped at logoff (meaning they exist and you can unmap them).
– Patrick Seymour
Apr 25 '16 at 19:29














@DavidPostill I just tried adding a sleep 300 before the unmap command, and other sleep 100 before the gpupdate /f. The output still says "There are no entries in the list."
– Francis Batalla
Apr 25 '16 at 19:35




@DavidPostill I just tried adding a sleep 300 before the unmap command, and other sleep 100 before the gpupdate /f. The output still says "There are no entries in the list."
– Francis Batalla
Apr 25 '16 at 19:35












@PatrickS. I've switched the script to run at logoff instead. Also, I've shortened the script to contain ONLY the unmapping drives cmd and a script run verification (send output to text file). My drives are still remaining mapped. Any other suggestions?
– Francis Batalla
Apr 25 '16 at 19:46




@PatrickS. I've switched the script to run at logoff instead. Also, I've shortened the script to contain ONLY the unmapping drives cmd and a script run verification (send output to text file). My drives are still remaining mapped. Any other suggestions?
– Francis Batalla
Apr 25 '16 at 19:46












My comment wasn't intended as an answer, just a suggestion on when to run the script. In fact, I tried what you're doing, and it worked for me on a Windows 10 machine.
– Patrick Seymour
Apr 25 '16 at 20:23




My comment wasn't intended as an answer, just a suggestion on when to run the script. In fact, I tried what you're doing, and it worked for me on a Windows 10 machine.
– Patrick Seymour
Apr 25 '16 at 20:23










2 Answers
2






active

oldest

votes

















up vote
0
down vote













I just had issue using net use g: /delete /yes on WIndows 2012R2, it was causing mapping conflicts. My G drive mapping would map to other servers, and sometimes additional z mapped drive appeared that was a ghost. It's wasn't in the batch script



If you Must delete network drives before the actual mappings using shares on Server 2012R2, use net use g: /del (ONLY)...this will work on 2012R2 Server



MJ






share|improve this answer





















  • So you are saying to first run NET USE G: /DELETE and explicitly delete all possible mapped drive letters that way rather than using the asterisk to do all drive letters regardless of the mapped drive letter, correct?
    – Pimp Juice IT
    Aug 9 '17 at 1:37


















up vote
0
down vote













If the user in question is an administrator, (un)mapping drives using scripts won’t work.



With UAC, you have two tokens and login sessions: one with all permissions (“elevated”) and one with limited permissions only. Scripts started by GPOs run with full permissions.



Mapped drives are tracked per session. When you try to map or unmap drives from logon/logoff scripts, they will only be available to programs running elevated. Explorer never runs elevated by default.



Here’s more info directly from Microsoft.



To work around this, use the following .reg script. After that, changes to mapped shares will affect both the full and limited token.



Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem]
"EnableLinkedConnections"=dword:00000001


This also fixes errors when trying to run setups (or other stuff that runs elevated) from mapped drives.






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1069675%2flogon-script-with-net-use-delete-yes%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I just had issue using net use g: /delete /yes on WIndows 2012R2, it was causing mapping conflicts. My G drive mapping would map to other servers, and sometimes additional z mapped drive appeared that was a ghost. It's wasn't in the batch script



    If you Must delete network drives before the actual mappings using shares on Server 2012R2, use net use g: /del (ONLY)...this will work on 2012R2 Server



    MJ






    share|improve this answer





















    • So you are saying to first run NET USE G: /DELETE and explicitly delete all possible mapped drive letters that way rather than using the asterisk to do all drive letters regardless of the mapped drive letter, correct?
      – Pimp Juice IT
      Aug 9 '17 at 1:37















    up vote
    0
    down vote













    I just had issue using net use g: /delete /yes on WIndows 2012R2, it was causing mapping conflicts. My G drive mapping would map to other servers, and sometimes additional z mapped drive appeared that was a ghost. It's wasn't in the batch script



    If you Must delete network drives before the actual mappings using shares on Server 2012R2, use net use g: /del (ONLY)...this will work on 2012R2 Server



    MJ






    share|improve this answer





















    • So you are saying to first run NET USE G: /DELETE and explicitly delete all possible mapped drive letters that way rather than using the asterisk to do all drive letters regardless of the mapped drive letter, correct?
      – Pimp Juice IT
      Aug 9 '17 at 1:37













    up vote
    0
    down vote










    up vote
    0
    down vote









    I just had issue using net use g: /delete /yes on WIndows 2012R2, it was causing mapping conflicts. My G drive mapping would map to other servers, and sometimes additional z mapped drive appeared that was a ghost. It's wasn't in the batch script



    If you Must delete network drives before the actual mappings using shares on Server 2012R2, use net use g: /del (ONLY)...this will work on 2012R2 Server



    MJ






    share|improve this answer












    I just had issue using net use g: /delete /yes on WIndows 2012R2, it was causing mapping conflicts. My G drive mapping would map to other servers, and sometimes additional z mapped drive appeared that was a ghost. It's wasn't in the batch script



    If you Must delete network drives before the actual mappings using shares on Server 2012R2, use net use g: /del (ONLY)...this will work on 2012R2 Server



    MJ







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 8 '17 at 21:27









    user759438

    1




    1












    • So you are saying to first run NET USE G: /DELETE and explicitly delete all possible mapped drive letters that way rather than using the asterisk to do all drive letters regardless of the mapped drive letter, correct?
      – Pimp Juice IT
      Aug 9 '17 at 1:37


















    • So you are saying to first run NET USE G: /DELETE and explicitly delete all possible mapped drive letters that way rather than using the asterisk to do all drive letters regardless of the mapped drive letter, correct?
      – Pimp Juice IT
      Aug 9 '17 at 1:37
















    So you are saying to first run NET USE G: /DELETE and explicitly delete all possible mapped drive letters that way rather than using the asterisk to do all drive letters regardless of the mapped drive letter, correct?
    – Pimp Juice IT
    Aug 9 '17 at 1:37




    So you are saying to first run NET USE G: /DELETE and explicitly delete all possible mapped drive letters that way rather than using the asterisk to do all drive letters regardless of the mapped drive letter, correct?
    – Pimp Juice IT
    Aug 9 '17 at 1:37












    up vote
    0
    down vote













    If the user in question is an administrator, (un)mapping drives using scripts won’t work.



    With UAC, you have two tokens and login sessions: one with all permissions (“elevated”) and one with limited permissions only. Scripts started by GPOs run with full permissions.



    Mapped drives are tracked per session. When you try to map or unmap drives from logon/logoff scripts, they will only be available to programs running elevated. Explorer never runs elevated by default.



    Here’s more info directly from Microsoft.



    To work around this, use the following .reg script. After that, changes to mapped shares will affect both the full and limited token.



    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem]
    "EnableLinkedConnections"=dword:00000001


    This also fixes errors when trying to run setups (or other stuff that runs elevated) from mapped drives.






    share|improve this answer

























      up vote
      0
      down vote













      If the user in question is an administrator, (un)mapping drives using scripts won’t work.



      With UAC, you have two tokens and login sessions: one with all permissions (“elevated”) and one with limited permissions only. Scripts started by GPOs run with full permissions.



      Mapped drives are tracked per session. When you try to map or unmap drives from logon/logoff scripts, they will only be available to programs running elevated. Explorer never runs elevated by default.



      Here’s more info directly from Microsoft.



      To work around this, use the following .reg script. After that, changes to mapped shares will affect both the full and limited token.



      Windows Registry Editor Version 5.00

      [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem]
      "EnableLinkedConnections"=dword:00000001


      This also fixes errors when trying to run setups (or other stuff that runs elevated) from mapped drives.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        If the user in question is an administrator, (un)mapping drives using scripts won’t work.



        With UAC, you have two tokens and login sessions: one with all permissions (“elevated”) and one with limited permissions only. Scripts started by GPOs run with full permissions.



        Mapped drives are tracked per session. When you try to map or unmap drives from logon/logoff scripts, they will only be available to programs running elevated. Explorer never runs elevated by default.



        Here’s more info directly from Microsoft.



        To work around this, use the following .reg script. After that, changes to mapped shares will affect both the full and limited token.



        Windows Registry Editor Version 5.00

        [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem]
        "EnableLinkedConnections"=dword:00000001


        This also fixes errors when trying to run setups (or other stuff that runs elevated) from mapped drives.






        share|improve this answer












        If the user in question is an administrator, (un)mapping drives using scripts won’t work.



        With UAC, you have two tokens and login sessions: one with all permissions (“elevated”) and one with limited permissions only. Scripts started by GPOs run with full permissions.



        Mapped drives are tracked per session. When you try to map or unmap drives from logon/logoff scripts, they will only be available to programs running elevated. Explorer never runs elevated by default.



        Here’s more info directly from Microsoft.



        To work around this, use the following .reg script. After that, changes to mapped shares will affect both the full and limited token.



        Windows Registry Editor Version 5.00

        [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem]
        "EnableLinkedConnections"=dword:00000001


        This also fixes errors when trying to run setups (or other stuff that runs elevated) from mapped drives.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 1 at 15:36









        Daniel B

        33.2k76087




        33.2k76087






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1069675%2flogon-script-with-net-use-delete-yes%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

            Eduardo VII do Reino Unido