MrCreatoR Posted November 5, 2007 Share Posted November 5, 2007 (edited) Hi all,I would like to make my own _ProcessWaitClose function, i need it because i need to call some function while the process is exists..Here is example:$Pid = Run("taskmgr.exe") _ProcessWaitClose($Pid, 0, "My_Func", $Pid) Func _ProcessWaitClose($ProcName, $TimeOut=0, $CallFunc="", $Param="") Local $iTimer = TimerInit() While ProcessExists($ProcName) > 0 If $TimeOut > 0 And TimerDiff($iTimer) >= $TimeOut Then Return 0 If $CallFunc <> "" Then Call($CallFunc, $Param) Sleep(100) WEnd Return 1 EndFunc Func My_Func($ProcID) ConsoleWrite($ProcID & @LF) EndFuncIf the taskmgr.exe process not exists yet, then all ok, the function wait until it closed and call other function while it wating, but if the process taskmgr.exe was exists already (when we start the script), then the script exits without waiting I guesing that the problem is with ProcessExists, it's return incorrect PID.Someone have an idea on how to solve it? (without specify a process name, i need it only by PID). Edited November 5, 2007 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 5, 2007 Moderators Share Posted November 5, 2007 (edited) Could try this at the beginning of the function:If UBound(ProcessList($ProcName)) - 1 = 1 Then Return SetError(1, 0, 0) Edit: Think I'm reading what you want wrong. Edited November 5, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
weaponx Posted November 5, 2007 Share Posted November 5, 2007 Maybe this. $theProcess = "taskmgr.exe" $Pid = ProcessExists($procName) If NOT $Pid $Pid = Run($theProcess) EndIf _ProcessWaitClose($Pid, 0, "My_Func", $Pid) Func _ProcessWaitClose($ProcName, $TimeOut=0, $CallFunc="", $Param="") Local $iTimer = TimerInit() While ProcessExists($ProcName) If $TimeOut > 0 And TimerDiff($iTimer) >= $TimeOut Then Return 0 If $CallFunc <> "" Then Call($CallFunc, $Param) Sleep(100) WEnd Return 1 EndFunc Func My_Func($ProcID) ConsoleWrite($ProcID & @LF) EndFunc Link to comment Share on other sites More sharing options...
MrCreatoR Posted November 5, 2007 Author Share Posted November 5, 2007 Maybe thisThanks, but i need to run again even if the process exists. I think there is a bug in ProcessWaitClose (built-in function)... If Not ProcessExists("taskmgr.exe") Then Run("taskmgr.exe") $Pid = Run("taskmgr.exe") $Ret = ProcessWaitClose($Pid) ConsoleWrite(@error & @LF & $Ret & @LF & ProcessExists($Pid)) The process ID in $Pid is the one that was executed last, so why this process not exits? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Developers Jos Posted November 5, 2007 Developers Share Posted November 5, 2007 (edited) I don't think the last Taskmgr.exe stays running when its already existing. perform these steps on the command prompt: >tasklist /FI "imagename eq taskmgr.exe" >Taskmgr >tasklist /FI "imagename eq taskmgr.exe" You will see that the same pid stays running .. Edited November 5, 2007 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 More sharing options...
PsaltyDS Posted November 5, 2007 Share Posted November 5, 2007 (edited) Thanks, but i need to run again even if the process exists. I think there is a bug in ProcessWaitClose (built-in function)... If Not ProcessExists("taskmgr.exe") Then Run("taskmgr.exe") $Pid = Run("taskmgr.exe") $Ret = ProcessWaitClose($Pid) ConsoleWrite(@error & @LF & $Ret & @LF & ProcessExists($Pid)) The process ID in $Pid is the one that was executed last, so why this process not exits? You shouldn't be able to open two instances of Task Manager. When you try to start the second, it sees the first already running and exits. So by the time you want to close it, it's already closed itself. Just run with the first two lines and nothing else. Do you see two instances of Task Manager? Edit: Beat out by the Jos-bot! Rats! Edited November 5, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
MrCreatoR Posted November 5, 2007 Author Share Posted November 5, 2007 I don't think the last Taskmgr.exe stays running when its already existingI know, it's not Do you see two instances of Task Manager?Sometimes i do, but for few seconds.Any suggestion on how to acomplish my task? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 6, 2007 Share Posted November 6, 2007 Any suggestion on how to acomplish my task?What was the task? Get two instances of Task Manager to stay open at the same time? It won't do that, because it's internally coded not to do that. So what is it you want to do? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
nikink Posted November 6, 2007 Share Posted November 6, 2007 Perhaps it's a case of wanting to to close a certain specific process when more than one process exists with the same name? So the examples would be (should be) something other than task manager. Notepad.exe perhaps? I may be misunderstanding. I had to do a similar thing a month ago. Link to comment Share on other sites More sharing options...
MrCreatoR Posted November 6, 2007 Author Share Posted November 6, 2007 What was the task?To write a proper function to wait untill process closes, and while waiting i need to call constantly certain function.But it seems that this is not work with my example (it not necessary taskmgr.exe, but the same situation can arise with any other process), it work correct only if i use process name, not process id, wich is what i need actualy. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 6, 2007 Share Posted November 6, 2007 (edited) To write a proper function to wait untill process closes, and while waiting i need to call constantly certain function. But it seems that this is not work with my example (it not necessary taskmgr.exe, but the same situation can arise with any other process), it work correct only if i use process name, not process id, wich is what i need actualy. OK, given that you don't want the function to actually close the process, just wait for it to close, it works fine for me. I made one change to see that the returned value was correct for success/timeout and it worked fine, even with Task Manager, provided Task Manager was not already running. So I changed the top to get the PID of an existing Task Manager or start a new one, but not try to have two: If ProcessExists("taskmgr.exe") Then $Pid = ProcessExists("taskmgr.exe") Else $Pid = Run("taskmgr.exe") EndIf $RET = _ProcessWaitClose($Pid, 3000, "My_Func", $Pid) ConsoleWrite("Debug: $RET = " & $RET & @LF) Func _ProcessWaitClose($ProcName, $TimeOut=0, $CallFunc="", $Param="") Local $iTimer = TimerInit() While ProcessExists($ProcName) > 0 If $TimeOut > 0 And TimerDiff($iTimer) >= $TimeOut Then Return 0 If $CallFunc <> "" Then Call($CallFunc, $Param) Sleep(100) WEnd Return 1 EndFunc Func My_Func($ProcID) ConsoleWrite($ProcID & @LF) EndFunc This seems to work exactly as you wanted, writing the PID to the console until either timeout or the process is closed. What makes you think ProcessExists() doesn't work with your $Pid? Edited November 6, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
MrCreatoR Posted November 6, 2007 Author Share Posted November 6, 2007 So I changed the top to get the PID of an existing Task Manager or start a new oneThanks for trying to help me, i really appreciate it.I thouth that it can be done from inside the UDF (manage the given pid), but probably i will have to change the concept of the function (something like _ProcessRunWaitClose()).Thanks to all, i think the problem(?) is solved. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team 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