Jump to content

Question/Help AutoIt logging into Windows 7


Recommended Posts

We have a scenario that we wanted to set a task that runs AutoIt so that it will log into Windows 7 and then we are able to use AutoIt to run reports with a series of commands.

I was wondering if there is a way to find information on the windows that controls the login so that we can create a script for AutoIt to login to a machine from within the machine.

I realize this may be contradictory, but alternatives would be greatly appreciated as well.

 

We don't have the option of remotely connecting to the machine to login because that would require us to leave a machine logged in all the time which is what we are trying to prevent with the login script.

Link to comment
Share on other sites

  • Developers

You have the RunAs() Function to shell a script under any userid's credentials, so see no reason why you would like to bypass the loginprompt with a script.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

We have a program called QS1 and it has to be launched then a combination of button clicks and keyboard keys have to be sent to the machine which can't be done if the machine hasn't been logged in to from what I've seen.
So in order to run the reports we need to launch a program with an interactive window then send clicks and keys to the interactive window for it to run the reports we need creating a report file that we then search for and rename based on the date, location, and report.
We figured out how to launch and run the reports but we need a way to login to windows so we can have an interactive window.

Link to comment
Share on other sites

  • Developers

Is there no option to send ControlXXXX() commands to this program?

Either way, bypassing the windows login gina is not simple without hacking something and that isn't up for discussion in our forums. :)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

The way the program is setup it doesn't react to sending Control commands. And since it would require hacking I guess I'll look for another solution.
We would be using our logins my main focus was being able to select the fields for Username and Password so we can send key commands to login automatically at a specific time of day with a combination of task scheduler and an AutoIt Script.

Thanks for the help though.

Link to comment
Share on other sites

It does not require hacking GINA, as the registry keys required to have a Windows machine automatically login under a particular account are documented by Microsoft.  You will need one process to set the registry keys and reboot the machine (e.g. in the Task Scheduler), and another to perform the work and logoff (e.g. a Startup task).

That said, the security you have gained by not having an account logged in all the time will be utterly defeated by having the password saved in the script that sets the registry keys.  You can try to secure it, but in the end that password will be recoverable by any motivated hacker so you need to weigh the risks based on the importance of the data.

 

Edited by DougShields
clarity
Link to comment
Share on other sites

  • Developers

True about the registry setting way and I've actually used that in the past when having to go through a couple of reboot cycles for an installation process.
I have posted that sample script before but haven't used it ever on Win7/8:

; pgm name Install_With_Reboots.AU3
$Userid = "Administrator"
$Psw = "adminpsw"
; Remove autologin params from registry to clean up
SetAutoLogon("Off", "")
;
; retrieve param
$param1 = ""
If $CmdLine[0] > 0 Then
    $param1 = $CmdLine[1]
EndIf
; Act on it
Select
    Case $param1 = ""
        ; run your programs with admin account if needed in the first step
        ; *** put your stuff here for step1 ***
        RunAs($Userid, @ComputerName, $Psw, Default,"notepad.exe step1.txt")
        SetAutoLogon("On", "step1")
        Shutdown(6)
    Case $param1 = "step1"
        ; is already logged on with admin account
        ;
        ; *** put your stuff here for step2 ***
        RunWait("notepad.exe step2.txt")
        ;
        SetAutoLogon("On", "step2")
        Shutdown(6)
    Case $param1 = "step2"
        ; logoff the admin account
        ; *** put your stuff here for step3 ***
        RunWait("notepad.exe step3.txt")
        ; just logoff
        Shutdown(0)
        Exit
EndSelect
Exit
;
;
Func SetAutoLogon($sw, $step)
    Local $s1, $s2, $s3, $s4
    If $sw = "On" Then
        ; set the registry to start this program again after reboot
        ; Read  current settings
        $s1 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "AutoAdminLogon")
        $s2 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultDomainName")
        $s3 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultUserName")
        $s4 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultPassword")
        ;Save current settings
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_AutoAdminLogon", "REG_SZ", $s1)
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultDomainName", "REG_SZ", $s2)
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultUserName", "REG_SZ", $s3)
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultPassword", "REG_SZ", $s4)
        ;Set New Settings
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN", "AutoItInstaller", "REG_SZ", @ScriptFullPath & " " & $step)
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "AutoAdminLogon", "REG_SZ", "1")
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultDomainName", "REG_SZ", EnvGet("LOGONSERVER"))
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultUserName", "REG_SZ", $Userid)
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultPassword", "REG_SZ", $Psw)
    EndIf
    ;
    If $sw = "Off" Then
        ; Read  previous settings and reset
        $s1 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_AutoAdminLogon")
        If Not @error Then
            RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_AutoAdminLogon")
            RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "AutoAdminLogon", "REG_SZ", $s1)
        EndIf
        $s2 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultDomainName")
        If Not @error Then
            RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultDomainName")
            RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultDomainName", "REG_SZ",$s2)
        EndIf
        $s3 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultUserName")
        If Not @error Then
            RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultUserName")
            RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultUserName", "REG_SZ", $s3)
        EndIf
        $s4 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultPassword")
        If Not @error Then
            RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultPassword")
            RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultPassword", "REG_SZ", $s4)
        EndIf
        ; Remove/Reset the registrykey to start this program again after reboot
        RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN", "AutoItInstaller")
    EndIf
EndFunc   ;==>SetAutoLogon

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Here is a function that I wrote to use with our setup script after imaging a PC.  This works with Windows 7 32-bit or 64-bit.    

Func _AutoLogon($iOnOff, $sUserName, $sPassword, $sDomain = ".", $iForceAutoLogon = 0) ;Auto Logon function.  $iOnOff should only be 1 (ON) or 0 (OFF).
    ;Auto Logon Registry Edits.
    Local $s64Bit = ""
    If @OSArch = "X64" Then $s64Bit = "64"
    Local Const $sRegKeyWinLogon = "HKEY_LOCAL_MACHINE" & $s64Bit & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"

    If $iOnOff = 0 Then ;Auto Logon OFF.
        RegWrite($sRegKeyWinLogon, "AutoAdminLogon", "REG_SZ", "0")
        If @error <> 0 Then Return SetError(1, @error, False)
    Else ;Auto Logon ON. If $iOnOff is anything but 0, it is set to 1 (ON).
        RegWrite($sRegKeyWinLogon, "AutoAdminLogon", "REG_SZ", "1")
        If @error <> 0 Then Return SetError(1, @error, False)
    EndIf

    If $iForceAutoLogon = 1 Then ;Force Auto Logon ON.
        RegWrite($sRegKeyWinLogon, "ForceAutoLogon", "REG_SZ", "1")
        If @error <> 0 Then Return SetError(2, @error, False)
    Else ;Force Auto Logon OFF. If $iForceAutoLogon is anything but 1, it is set to 0 (OFF).
        RegWrite($sRegKeyWinLogon, "ForceAutoLogon", "REG_SZ", "0")
        If @error <> 0 Then Return SetError(2, @error, False)
    EndIf

    RegWrite($sRegKeyWinLogon, "DefaultUserName", "REG_SZ", $sUserName)
    If @error <> 0 Then Return SetError(3, @error, False)
    RegWrite($sRegKeyWinLogon, "AltDefaultUserName", "REG_SZ", $sUserName)
    If @error <> 0 Then Return SetError(4, @error, False)
    RegWrite($sRegKeyWinLogon, "DefaultPassword", "REG_SZ", $sPassword)
    If @error <> 0 Then Return SetError(5, @error, False)
    RegWrite($sRegKeyWinLogon, "DefaultDomainName", "REG_SZ", $sDomain)
    If @error <> 0 Then Return SetError(6, @error, False)
    RegWrite($sRegKeyWinLogon, "AltDefaultDomainName", "REG_SZ", $sDomain)
    If @error <> 0 Then Return SetError(7, @error, False)
    
    ;Delete "AutoLogonCount" key created by sysprep autologon setting.  
    If RegRead($sRegKeyWinLogon, "AutoLogonCount") Then RegDelete($sRegKeyWinLogon, "AutoLogonCount")
    
    Local Const $sRegKeyLogonUI = "HKEY_LOCAL_MACHINE" & $s64Bit & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI"

    RegWrite($sRegKeyLogonUI, "LastLoggedOnSAMUser", "REG_SZ", $sDomain & "\" & $sUserName)
    If @error <> 0 Then Return SetError(8, @error, False)
    RegWrite($sRegKeyLogonUI, "LastLoggedOnUser", "REG_SZ", $sDomain & "\" & $sUserName)
    If @error <> 0 Then Return SetError(9, @error, False)

    Return True
EndFunc   ;==>_AutoLogon

 

Adam

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...