microera Posted October 8, 2009 Share Posted October 8, 2009 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!? Link to comment Share on other sites More sharing options...
Mat Posted October 8, 2009 Share Posted October 8, 2009 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 AutoIt Project Listing Link to comment Share on other sites More sharing options...
dantay9 Posted October 8, 2009 Share Posted October 8, 2009 You could just read the ini data again back into the same variable that it was previously in. Link to comment Share on other sites More sharing options...
Yashied Posted October 9, 2009 Share Posted October 9, 2009 #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 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Mison Posted October 9, 2009 Share Posted October 9, 2009 (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 October 9, 2009 by Mison Hi ;) Link to comment Share on other sites More sharing options...
TurionAltec Posted October 9, 2009 Share Posted October 9, 2009 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. Link to comment Share on other sites More sharing options...
microera Posted October 10, 2009 Author Share Posted October 10, 2009 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? Link to comment Share on other sites More sharing options...
martin Posted October 11, 2009 Share Posted October 11, 2009 ;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. Link to comment Share on other sites More sharing options...
microera Posted October 18, 2009 Author Share Posted October 18, 2009 (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 October 18, 2009 by microera Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now