Sign in to follow this  
Followers 0

create computer restart loop for X times

16 posts in this topic

Posted

Hi

i wont to create a computer restart loop

witch in it a`ll have the ability to select how many restart will be preformed

is it passable :P

shay

Share this post


Link to post
Share on other sites



Posted

yes it's possible. What are you creating this for?

I suggest taking a look at file writing and reading functions to do the counting.

Share this post


Link to post
Share on other sites

Posted

yes it's possible. What are you creating this for?

I suggest taking a look at file writing and reading functions to do the counting.

i need this for testing purpose

i know that i need to do a loop how read counter from some log files

and after each restart it will write -1 in the log file

so when log file will get to 0 it will stop running the restart loop

how do i implant this?

Share this post


Link to post
Share on other sites

Posted

First find yourself a piece of coding that will make this program run on startup... Or would you want to have to manually open your program every time you want to restart it?

Share this post


Link to post
Share on other sites

Posted

First find yourself a piece of coding that will make this program run on startup... Or would you want to have to manually open your program every time you want to restart it?

no problem

i use this to add Run Once in the registry

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce", "ewf", "REG_SZ", "c:\runonce.exe")

Share this post


Link to post
Share on other sites

Posted

FileRead(blahblah)

FileWrite(blahblah)

some code for restart.

Voila you're finished.

throw in some if... then... else... endif in there and you're set.

Share this post


Link to post
Share on other sites

Posted

all of that info is very helpful

but i have some problem on the "conter"

with the read and write to the counter.....

Share this post


Link to post
Share on other sites

Posted

Do you need this when the unit first starts, of after it is logged in? If after it is logged in, you could just place this compiled script in startup. Else you can put it in the path to it in the registry:

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce", "ewf", "REG_SZ", "c:\runonce.exe")

Just edit the ini to handle the number of reboots you need.

$path = "C:\restart.ini"
$ini = IniRead($path, "1", "1", "0")
if $ini => 1 then 
	$ini = $ini - 1
	IniWrite($path, "1", "1", $ini)
	Shutdown(6)  ;Force a reboot
endif

Share this post


Link to post
Share on other sites

Posted

all of that info is very helpful

but i have some problem on the "conter"

with the read and write to the counter.....

That is part of the examples... just be creative. :P

Share this post


Link to post
Share on other sites

Posted

Do you need this when the unit first starts, of after it is logged in? If after it is logged in, you could just place this compiled script in startup. Else you can put it in the path to it in the registry:

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce", "ewf", "REG_SZ", "c:\runonce.exe")

Just edit the ini to handle the number of reboots you need.

$path = "C:\restart.ini"
$ini = IniRead($path, "1", "1", "0")
if $ini => 1 then 
	$ini = $ini - 1
	IniWrite($path, "1", "1", $ini)
	Shutdown(6)  ;Force a reboot
endif
Isnt the registry should be

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run", "ewf", "REG_SZ", "c:\runonce.exe")

Since runonce path registry means only run once then delete the registry path?

Share this post


Link to post
Share on other sites

Posted

Do you need this when the unit first starts, of after it is logged in? If after it is logged in, you could just place this compiled script in startup. Else you can put it in the path to it in the registry:

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce", "ewf", "REG_SZ", "c:\runonce.exe")

Just edit the ini to handle the number of reboots you need.

$path = "C:\restart.ini"
$ini = IniRead($path, "1", "1", "0")
if $ini => 1 then 
	$ini = $ini - 1
	IniWrite($path, "1", "1", $ini)
	Shutdown(6)  ;Force a reboot
endif
thanks,

that work great and short my code to more "clean" one

i use the "REG run once" to run the code after restart.

Share this post


Link to post
Share on other sites

Posted

thanks,

that work great and short my code to more "clean" one

i use the "REG run once" to run the code after restart.

after i develop the code some more a had some another problems,

after PC restart the firs thing that run is the code,

the problem is that the code wait to a specific window (WinWaitActive), the code pause all the programs in the start-up,

i need all the startup programs to load and then tell the code to wait to specific window,

no meter if i use sleep or WinWaitActive pause al programs during startup

$path = "d:\restart.ini"
$ini = IniRead($path, "restart_count", "restart_number", "0")
if $ini >= 1 then
	$ini = $ini - 1
	IniWrite($path, "restart_count", "restart_number", $ini)
	
;log file
	$file = FileOpen("d:\restart.log", 1)
	FileWriteLine($file, "Restart " &  @Hour & ":" & @Min & ":" & @Sec) 
	FileClose($file)
	
; REG insert
	RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce", "ewf", "REG_SZ", "d:\restart.exe")
	Sleep(200)
	Run(@COMSPEC & " /c ewfmgr c: -commitanddisable")
	sleep(200)
	MsgBox(0,'','Insert regestry OK ' ,2)
	Sleep(60000)
;Restart
	WinWaitActive(  "" , "connect")
	Beep(500, 500)
	Sleep(200)
	Beep(500, 500)
	Run(@COMSPEC & " /c shutdown -r -t 3")
	

Else 
Beep(500, 1000)
Sleep(200)
Beep(500, 1000)

$file = FileOpen("d:\restart.log", 1)
	FileWriteLine($file, "End of automation  restart " &  @Hour & ":" & @Min & ":" & @Sec) 
	FileClose($file)
	Sleep(200)
MsgBox(0,'','end of automation restart ' )

Share this post


Link to post
Share on other sites

Posted

Why exactly are you wanting the computer to restart? There must be an easier solution I think...

Share this post


Link to post
Share on other sites

Posted

Why exactly are you wanting the computer to restart? There must be an easier solution I think...

Runonce will always be the first thing windows run after it start up.

Its mean only run one time only and will always be the first priority program to load, once executed whether successful or not, the runonce registry path will be deleted.

Thats why I suggested Run in the registry path instead of runonce.

This way, you could pause or sleep your program to wait until all apps in computer to load up. :P

Share this post


Link to post
Share on other sites

Posted

OK i found the problem

if i use run-once from the REG this is the firs application to load on windows,

if i run it from the start-up its last to load (in my case i use it)

Share this post


Link to post
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
Sign in to follow this  
Followers 0