none
batch file to Automatically logoff and Auto Login to windows

    Question

  • hi all

    in win 2008 R2 , is there any method to create a batch file that when we run it , we be loged off from windows and immediately be Automatically Logged in to windows with the user account and password which we have written in that batch file ?

    ( for example that's useful when we need to logoff one time for refreshing group policy and we don't want to type in username and password manually )    :-)   nice ?

    thanks in advance

    Sunday, February 05, 2012 10:12 AM

All replies

  • Hi,

    To Auto Logoff, you can simply user logoff command in a batch file and to Auto Login you can edit registry Keys :

    You can use Registry Editor to add your log on information. To do this, follow these steps:

    1. Click Start, click Run, type regedit, and then click OK.
    2. Locate the following registry key:
      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
    3. Using your account name and password, double-click the DefaultUserName entry, type your user name, and then click OK.
    4. Double-click the DefaultPassword entry, type your password under the value data box, and then click OK.

      If there is no DefaultPassword value, create the value. To do this, follow these steps:
      1. In Registry Editor, click Edit, click New, and then click String Value.
      2. Type DefaultPassword as the value name, and then press ENTER.
      3. Double-click the newly created key, and then type your password in the Value Data box.
      Note: If the DefaultPassword registry entry does not exist, Windows XP automatically changes the value of the AutoAdminLogonregistry key from 1 (true) to 0 (false) to turn off the AutoAdminLogon feature after the computer is restarted.
    5. Double-click the AutoAdminLogon entry, type 1 in the Value Data box, and then click OK.

      If there is no AutoAdminLogon entry, create the entry. To do this, follow these steps:
      1. In Registry Editor, click Edit, click New, and then click String Value.
      2. Type AutoAdminLogon as the value name, and then press ENTER.
      3. Double-click the newly created key, and then type 1 in the Value Data box.
    6. Exit Registry Editor.
    7. Click Start, click Restart, and then click OK.

    MCSE Certified
    • Proposed as answer by IamBharat Sunday, February 05, 2012 4:17 PM
    Sunday, February 05, 2012 4:17 PM
  • Hi,

    To Auto Logoff, you can simply user logoff command in a batch file and to Auto Login you can edit registry Keys :

    You can use Registry Editor to add your log on information. To do this, follow these steps:

    1. Click Start, click Run, type regedit, and then click OK.
    2. Locate the following registry key:
      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
    3. Using your account name and password, double-click the DefaultUserName entry, type your user name, and then click OK.
    4. Double-click the DefaultPassword entry, type your password under the value data box, and then click OK.

      If there is no DefaultPassword value, create the value. To do this, follow these steps:
      1. In Registry Editor, click Edit, click New, and then click String Value.
      2. Type DefaultPassword as the value name, and then press ENTER.
      3. Double-click the newly created key, and then type your password in the Value Data box.
      Note: If the DefaultPassword registry entry does not exist, Windows XP automatically changes the value of the AutoAdminLogonregistry key from 1 (true) to 0 (false) to turn off the AutoAdminLogon feature after the computer is restarted.
    5. Double-click the AutoAdminLogon entry, type 1 in the Value Data box, and then click OK.

      If there is no AutoAdminLogon entry, create the entry. To do this, follow these steps:
      1. In Registry Editor, click Edit, click New, and then click String Value.
      2. Type AutoAdminLogon as the value name, and then press ENTER.
      3. Double-click the newly created key, and then type 1 in the Value Data box.
    6. Exit Registry Editor.
    7. Click Start, click Restart, and then click OK.

    MCSE Certified

    hi Tech_Ad .  thank you for your answer. i'll test that

    regards

    Sunday, February 05, 2012 5:55 PM
  • If you supply an account name and password in a batch file, then there's that possibility of someone else reading it, since it's stored in plain text. It's not accepted practice, and as a security standpoint, I wouldn't really suggest it.

    It's just to refresh a policy? What's wrong with manually typing it in?

    To refresh the GPOs, as long as something is not mitigating a logoff/logon or restart, such as when you first setup and configured Folder Redirection, you can either wait the 90 min +/- 30 min for the policies to refresh, or use gpupdate /F (/F forces both user and computer) at the command line. You can also use PSEXEC utility to remotely run a command in CMD on a remote computer, as long as you have administrative rights and the remote registry service is Started. PSExec is part of the PSTool set from Microsoft. I use it all the time.

    PsTools, Microsoft, written by By Mark Russinovich
    http://technet.microsoft.com/en-us/sysinternals/bb896649 

    Ace


    Ace Fekay
    MVP, MCT, MCITP Enterprise Administrator, MCTS Windows 2008 & Exchange 2007 & Exchange 2010, Exchange 2010 Enterprise Administrator, MCSE & MCSA 2003/2000, MCSA Messaging 2003
    Microsoft Certified Trainer
    Microsoft MVP - Directory Services
    Complete List of Technical Blogs: http://www.delawarecountycomputerconsulting.com/technicalblogs.php

    This posting is provided AS-IS with no warranties or guarantees and confers no rights.

    FaceBook Twitter LinkedIn
    Monday, February 06, 2012 6:41 AM
  • Hi John,

    The method provided by Tech_AD only apply when the server reboot. If we manually logoff, it won’t logon automatically. And there is no way to logon automatically when you logoff. This is by design. Thanks for your understanding.

    As Ace mentioned, using automatic logon can pose a security risk because anyone that has access to your computer will have access to your programs and files. It’s better to turn off.

    Best Regards,

    Aiden


    Aiden Cao

    TechNet Community Support

    Tuesday, February 07, 2012 3:38 AM
    Moderator
  • Hi John,

    The method provided by Tech_AD only apply when the server reboot. If we manually logoff, it won’t logon automatically. And there is no way to logon automatically when you logoff. This is by design. Thanks for your understanding.

    As Ace mentioned, using automatic logon can pose a security risk because anyone that has access to your computer will have access to your programs and files. It’s better to turn off.

    Best Regards,

    Aiden


    Aiden Cao

    TechNet Community Support

    hi Aiden. thank you very much.  there is no security risk because i am asking it for test environment only and was looking for a solution.

    after reboot isn't useful for me , i was searching for solution abot logoff and then Auto Logon

    Tuesday, February 07, 2012 7:48 AM
  • echo off
    set rpathLog=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
    reg add "%rpathLog%" /v "AutoAdminLogon" /t REG_SZ /d "1" /f >nul
    reg add "%rpathLog%" /v "AutoLogonCount" /t REG_DWORD /d "0x1" /f >nul
    reg add "%rpathLog%" /v "AutoRestartShell" /t REG_DWORD /d "0x1" /f >nul
    @start shutdown -f -l -t 0 & exit

    • Proposed as answer by syamsyai Monday, December 17, 2012 6:31 AM
    Monday, December 17, 2012 6:30 AM