Sign in to follow this  
Followers 0
microera

restart script.... possible?

9 posts in this topic

Is possible to restart compiled script (.exe) within script?

I have different INI files, have GUI, and script working in circle....and GUIOnEventMode...

... and because I read many parameters from .INI file at begining I want to restart script from begining, because of reading another INI file with new paramaters!

I hope I'm clear?

Is this possible on clear way!?

Share this post


Link to post
Share on other sites



Yes...

If @Compiled Then
   Run ("""" & @ScriptFullPath & """")
Else
   Run ("""" & @AutoitEXE & """ """ & @ScriptFullPath & """")
EndIf
Exit

basicly, run the script again and then exit. it starts a completely new process though.

Mat

Share this post


Link to post
Share on other sites

You could just read the ini data again back into the same variable that it was previously in.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

#Include <File.au3>

If MsgBox(36, 'Restarting...', 'Press OK to restart this script.') = 6 Then
    _ScriptRestart()
EndIf

Func _ScriptRestart()
    $sVbs = _TempFile(@TempDir, '~', '.vbs')
    $hFile = FileOpen($sVbs, 2)
    FileWriteLine($hFile, 'Set objService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2")')
    FileWriteLine($hFile, 'Set objRefresher = CreateObject("WbemScripting.SWbemRefresher")')
    FileWriteLine($hFile, 'Set colItems = objRefresher.AddEnum(objService, "Win32_Process").objectSet')
    FileWriteLine($hFile, 'Do Until False')
    FileWriteLine($hFile, '    WScript.Sleep 500')
    FileWriteLine($hFile, '    objRefresher.Refresh')
    FileWriteLine($hFile, '    Flag = True')
    FileWriteLine($hFile, '    For Each objItem in colItems')
    FileWriteLine($hFile, '        If InStr(objItem.ExecutablePath, "' & StringRegExpReplace(@ScriptFullPath, '^.*\\', '') & '") Then')
    FileWriteLine($hFile, '            Flag = False')
    FileWriteLine($hFile, '        End If')
    FileWriteLine($hFile, '    Next')
    FileWriteLine($hFile, '    If Flag = True Then')
    FileWriteLine($hFile, '        Exit Do')
    FileWriteLine($hFile, '    End If')
    FileWriteLine($hFile, 'Loop')
    FileWriteLine($hFile, 'Set objShell = CreateObject("WScript.Shell")')
    FileWriteLine($hFile, 'objShell.Run("' & FileGetShortName(@ScriptFullPath) & '")')
    FileWriteLine($hFile, 'Set objFSO = CreateObject("Scripting.FileSystemObject")')
    FileWriteLine($hFile, 'Set File = objFSO.GetFile("' & FileGetShortName($sVbs) & '")')
    FileWriteLine($hFile, 'File.Delete')
    FileClose($hFile)
    ShellExecute($sVbs)
    Exit
EndFunc   ;==>_ScriptRestart

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi,

If I understand your question correctly, all you need is a function

#include <whatever.au3>

InitMyScript("default.ini") ; 1st call to InitMyScript
;
; your codes here... GUI bla bla
;
While 1
    $msg = MsgBox(1,"Prompt", "want to change default settings?")
    If $msg = 1 Then InitMyScript("custom.ini") ; 2nd call to 1st call to InitMyScript
WEnd


Func InitMyScript($ini) ; read ini Function
    IniRead($ini,"Your Section", "Key", "-")
    ; (re-)apply your settings here
    ; bla bla
EndFunc

With read ini function, you can read ini as many times as you want...

Edited by Mison

Hi ;)

Share this post


Link to post
Share on other sites

I've used Mison's approach before. Create a function "Loadsettings" in which all your inireads are located. Have it run at start, and then call it again if a "reload settings" button is pressed.

Share this post


Link to post
Share on other sites

it's problem baceuse I have GUIOnEventMode

example like this:

__________________________

loadINIfile

...

commands...

....

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=C:\NaprednoSkeniranje\naprednoskeniranje02k.kxf

.... GUI statements....

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

while 1

loop ......

wend

__________________________

how exit from loop and start to beginning?

Share this post


Link to post
Share on other sites

;all includes here

while 1
$restart = False
loadINIfile
...
commands...
....
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=C:\NaprednoSkeniranje\naprednoskeniranje02k.kxf
.... GUI statements....
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

while 1
   loop ......
if $restart then exitloop;need some event or logic to set $restart to True
wend
;delete any guis here ior change your script so that they are not created twice.
Wend


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

;all includes here

while 1
$restart = False
loadINIfile
...
commands...
....
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=C:\NaprednoSkeniranje\naprednoskeniranje02k.kxf
.... GUI statements....
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

while 1
   loop ......
if $restart then exitloop;need some event or logic to set $restart to True
wend
;delete any guis here ior change your script so that they are not created twice.
Wend

Thanks MArtin working OK but ... old process was still active!

How to close old proces and live active only new GUI process?

....

found solution!

:)

GUIDelete()

Edited by microera

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