Jump to content

Force Reboot and re-logging in?


Recommended Posts

I'm currently using shutdown(6) to force a reboot of the system.

That's all fine and dandy, however I was wondering if there were any way to get the system to auto-login to the user the program was run from, after the reboot?

Edited by Edifice
Link to comment
Share on other sites

I did actually. I didn't find a solution. That's properly why I'm asking.

The posted link does not answer my question at all.

Maybe I should clarify my question:

I wanna use the program for testing purposes - I often repair computers that have a problem 5% of the times they are booted. To get myself out of the slow and often boring process of booting them all 20 times before seeing the problem i thought i'd make a little re-boot program. I did, however I still have to manually log them in, which really renders the program useless.

A more precise version of my question:

I'm currently using shutdown(6) to force a reboot of the system.

That's all fine and dandy, however I was wondering if there were any way to get the system to auto-login to the user the program was run from, after the reboot?

No third-party software, and no windows-specific solutions - It has to run on all windows-based computers out of the box so to say.

Edited by Edifice
Link to comment
Share on other sites

  • Developers

I have posted this already a few times. This is a script I have used when installing sofware pakage(s) that required reboot(s)

Jos

; 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
        RunAsSet($Userid, @ComputerName, $Psw)
;
; *** put your stuff here for step1 ***
        RunWait("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
Edited by 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

Thanks! This looks like just the thing I was looking for! Sorry I didn't find it on my own.

Anyway, I suppose it was written a while ago, as the RunAsSet doesn't exist any longer.

I replaced it like this:

RunAs($Userid, @ComputerName, $Psw, 1, @ScriptFullPath)

is that correct?

Link to comment
Share on other sites

  • Developers

Thanks! This looks like just the thing I was looking for! Sorry I didn't find it on my own.

Anyway, I suppose it was written a while ago, as the RunAsSet doesn't exist any longer.

I replaced it like this:

RunAs($Userid, @ComputerName, $Psw, 1, @ScriptFullPath)

is that correct?

Correct, it was written a couple of years ago and the RunAsSet() & RunWait() need to be replaced with RunAsWait() Edited by 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

  • 3 months later...

have a question, the "step 1", etc. areas aren't making much sense to me. Sorry i'm a bit of a n00b still. I get all the rest, just not sure what to put in where it says:

; *** put your stuff here for step1 ***
        RunWait("notepad.exe step1.txt")

My script is basically to log the user off, login as an admin, install the software:

$INSTALL_STRING = "msiexec.exe /i c:\temp\sqltools\sqlrun_tools.msi /qb"

Then logoff when it's complete. Would I change the 'step 1' line to:

RunWait($INSTALL_STRING)

And then just disregard the other steps since I only need one?

The way I read the lines is that you're opening Notepad and calling it "step1.txt".

Sorry if this is elementary, I'm still learning.

Link to comment
Share on other sites

  • 1 month later...

have a question, the "step 1", etc. areas aren't making much sense to me. Sorry i'm a bit of a n00b still. I get all the rest, just not sure what to put in where it says:

; *** put your stuff here for step1 ***
        RunWait("notepad.exe step1.txt")

My script is basically to log the user off, login as an admin, install the software:

$INSTALL_STRING = "msiexec.exe /i c:\temp\sqltools\sqlrun_tools.msi /qb"

Then logoff when it's complete. Would I change the 'step 1' line to:

RunWait($INSTALL_STRING)

And then just disregard the other steps since I only need one?

The way I read the lines is that you're opening Notepad and calling it "step1.txt".

Sorry if this is elementary, I'm still learning.

I was able to get it to work, somewhat. Sometimes it adds the registry info but doesn't reboot, other times it reboots but doesn't login. One issue I'm having is it seems to be tailored for an AD domain for the LOGONSERVER part, it adds a couple of backslashes at the beginning so I had to leave that part out, that or I'll have to change it to @ComputerName.

Edit: I'm working in a Novell Zenworks environment btw.

Any help?

Edited by slundy
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...