Negative1 Posted June 2, 2009 Share Posted June 2, 2009 So I have searched help and I found plenty of topics on how to get handle from PID!!! success I thought... but no wait i need PID from handle, blast! I used _singleton to get the handle of the existing process. Now i want to kill the existing process for sake of the new process to run. Thanks in advance -1 What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world. Link to comment Share on other sites More sharing options...
martin Posted June 2, 2009 Share Posted June 2, 2009 So I have searched help and I found plenty of topics on how to get handle from PID!!! success I thought... but no wait i need PID from handle, blast!I used _singleton to get the handle of the existing process. Now i want to kill the existing process for sake of the new process to run.Thanks in advance-1If you can get the handle from a PID then the reverse must be just a question of looking through the pids.ProcessList to get the list of processesfor each process if handleof(process) = handleIwant then ProcessIwant = process. (Excuse my lack of language skills ) 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...
Exit Posted June 2, 2009 Share Posted June 2, 2009 (edited) This post is obsolete. Please use new _SingleScript at http://www.autoitscript.com/forum/index.php?showtopic=178681 ------------------------------------ If you just want to kill the previous script, use this: ;--- _SingleScript.au3 ;--- remove all running scripts wirh the same name ;--- Usage: #include "_SingleScript.au3" ;--------------------------------------------------------------------- __SingleScript() Func __SingleScript() Local $O = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $OI, $CI = $O.ExecQuery("SELECT * FROM Win32_Process", "WQL", 0x30) For $OI In $CI If $OI.ProcessId = @AutoItPID Then ContinueLoop If $OI.Name = StringTrimRight(@ScriptName, 4) & ".EXE" Then ProcessClose($OI.ProcessId) If $OI.Name = "AutoIt3.exe" And StringInStr($OI.CommandLine, StringTrimRight(@ScriptName, 4) & ".au3") Then ProcessClose($OI.ProcessId) Next EndFunc ;==>__SingleScript Edited March 9, 2019 by Exit point to new #include location App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
ProgAndy Posted June 2, 2009 Share Posted June 2, 2009 (edited) Why do you use WMI for this simple task? ProcessList does the same much faster Edited June 2, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Exit Posted June 2, 2009 Share Posted June 2, 2009 (edited) Why do you use WMI for this simple task? ProcessList does the same much faster ProcessList has no information of "AutoIt3.exe" command parameter. This is necessary for noncompiled scripts See this lime:If $OI.Name = "AutoIt3.exe" And StringInStr($OI.CommandLine, StringTrimRight(@ScriptName, 4) & ".au3") Then ProcessClose($OI.ProcessId)Btw, it takes 250 milliseconds to execute. Not much for a function running only once per script. Edited June 2, 2009 by forumer100 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
ProgAndy Posted June 2, 2009 Share Posted June 2, 2009 (edited) Oh, i missed that line I have another Method: $UniqueIsntanceKey = "My Unique String, e.g a GUID 31eafd0c-5d98-442f-ab88-639512c0c128" While WinClose($UniqueIsntanceKey) ; closes all windows with this title (you could also use WinKill) WEnd AutoItWinSetTitle($UniqueIsntanceKey) ; set title for own script This still works if multiple Scripts have the same name or if a script is executed twice with different names. Edited June 2, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
rajeshontheweb Posted June 3, 2009 Share Posted June 3, 2009 you could use the windows api call to get the commandline which is much more efficient and less time consuming than wmi calling, i think.check this Started late is much better than having never started it!!!!Failure is another step towards success. I've been messing around with: Adding Entry to 'Hosts'File Information Lister (Logger)Yet Another AutoIT Error Handler Yet Another AutoIT Error Handler & Debugger Control your App's TaskBar Button YCurrency Ticker (Latest Release : 16 Apr 2009)_WinInetInternetCheckConnection UDF Symantec Definitions Lister UDF _GetLocalIPAddresses UDF UDF to get Special Folder Information WMI_NetworkAdapterConfiguration2Array WMI_CDRomDriveCapabilities _ScriptExists - Check if your au3 script is running!! Uninstaller UDF Get Version for your application (at script level or compiled stage) Uninstaller Pro - faster alternative to windows application removal applet Link to comment Share on other sites More sharing options...
wraithdu Posted June 3, 2009 Share Posted June 3, 2009 PID from windows handle? Just use this, it's foolproof - GetWindowThreadProcessId() Link to comment Share on other sites More sharing options...
Skruge Posted June 4, 2009 Share Posted June 4, 2009 Foolproof? Really? The OP wants to get the PID of a process by using that process' handle. Can you explain how _WinAPI_GetWindowThreadProcessId() is going to do that? _WinAPI_GetWindowThreadProcessId($hWnd, ByRef $iPID)You emphasized the wrong word there. ByRef means the $iPID parameter is passed by reference and the function is able to update the value directly. Here's how:#Include <WinAPI.au3> Run("Notepad.exe") WinWait("[CLASS:Notepad]") Local $hWnd =WinGetHandle("[CLASS:Notepad]") Local $iPID _WinAPI_GetWindowThreadProcessId($hWnd, $iPID) ConsoleWrite("PID set by function: " & $iPID & @CRLF) [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
wraithdu Posted June 4, 2009 Share Posted June 4, 2009 Yep. I was thinking of the direct DllCall (didn't know it was in WinAPI.au3), but same result. @Thanubis Also, don't confuse the term 'handle' with 'hWnd'. 'handle' usually refers to a process handle returned by OpenProcess, for example. 'hWnd' usually refers to a process' window's handle. Close, but not quite interchangeable. If you want more info, search that function on MSDN. 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