Jump to content

Recommended Posts

Posted

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!?

Posted

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

Posted

#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

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 ;)

Posted

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.

Posted

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?

Posted

;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.
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

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
×
×
  • Create New...