| View previous topic :: View next topic |
| Author |
Message |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Fri Mar 19, 2010 2:30 pm Post subject: Calling A Running Process |
|
|
Hello again. I'm having an issue where I need my script to call out a running process from the Task Manager. Is there a way to do this? I've tried using the following to bring it up...
| Code: | DetectHiddenWindows On
WinShow
WinActivate |
If I'm missing anything here, or if anyone knows how to call a process that is supposed to be running... Please let me know. Thank you all. _________________ -Jeremiah |
|
| Back to top |
|
 |
Murx Guest
|
Posted: Fri Mar 19, 2010 2:45 pm Post subject: |
|
|
Check the ahk help for (guess what?) --> process  |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Fri Mar 19, 2010 2:58 pm Post subject: |
|
|
Thank you. That's helpful and all but, how can I use that to make the process show its self? I am unable to find a way to get the PID from it because the Hotkey is not what ran it in the first place. _________________ -Jeremiah |
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 2926 Location: The Shell
|
Posted: Fri Mar 19, 2010 3:13 pm Post subject: |
|
|
What Murx meant was, if you use Exist in the process command with the name of the process your looking for. Errorlevel will be set to the PID of the process. So
| Code: | process, exist, **app/process name**.exe
msgbox % appPid := errorlevel | Now the variable appPid can be used with say winshow like this.
| Code: | process, exist, **app/process name**.exe
appPid := errorlevel
winshow, ahk_pid %appPid%
; or
if winexist(ahk_pid %appPid%)
msgbox Process found! | I think all other window commands will except the pid as the search criteria this way..
Just remember the process or window does not have to launched from a hotkey for it to have a PID. All windows and processes have them!
Oh and no dont use ahk_pid %errorlevel% as it changes per command and will override last found window!
hth _________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞ |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Fri Mar 19, 2010 3:17 pm Post subject: |
|
|
Great information. Thank you. I do have one question though. How do I get the PID from the process if it's not a .exe? This process is actually Microsoft's Spell Checker activated through a VBS. Sometimes, this process comes up with no issues and I am able to see it. Other times the process will run, but I can't see it and then I have to go into the Task Manger and double-click it to get it to run. _________________ -Jeremiah |
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 2926 Location: The Shell
|
Posted: Fri Mar 19, 2010 5:16 pm Post subject: |
|
|
From my experience, the PID of child windows are the same as the parent. You could verify this by running a get active PID:
| Code: | loop {
wingettitle, curTitle, A
winget, curPid, PID, A
tooltip % "The current PID is: " curPid "`nFor window: " curTitle
sleep, 50 ; For CPU load.
}
return
esc::exitapp | Note: MouseGetPos is a little more efficient so you might want to use that instead.
If you run this on both the parent and child window (MS spell checker), you should notice that the PID is the same.
Please confirm this.
edit:
Just a correction on what I said b4:
- mousegetpos will only get you the uid or the hwnd (which will return the individual child window's identity) not the pid. _________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞ |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Fri Mar 19, 2010 6:40 pm Post subject: |
|
|
Great tool! However, the PID for the MS Spell Check is always a different PID from the script that runs it. Is there a way to detect the PID on a running process that isn't viewable? _________________ -Jeremiah |
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 2926 Location: The Shell
|
Posted: Fri Mar 19, 2010 7:14 pm Post subject: |
|
|
um I'm not sure if I explained it correctly but the PID for the parent application of MS spell checker should be the same as the spell checker itself. Unless its a stand alone app or something.
What app is the spell checker being opened from? Word, or something else? Please explain. _________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞
Last edited by TLM on Fri Mar 19, 2010 7:18 pm; edited 1 time in total |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Fri Mar 19, 2010 7:18 pm Post subject: |
|
|
It's being opened from a VB script written by someone else.
| Code: | Dim oWD, RangeOriginal, RangeCorrected, Cnt, Status
Set oWD = WScript.CreateObject("Word.Application")
oWD.Visible =false
oWD.Documents.Add
On Error Resume Next
oWD.Selection.Paste
If err.number<>0 then
MsgBox "Please input text to your clipboard to check",4112,"Error"
oWD.ActiveDocument.Close wdDoNotSaveChanges
oWD.Quit
Set oWD=Nothing
Set oWD=Nothing
WScript.Quit
End If
'
Set RangeOriginal=oWD.ActiveDocument.Range(0,oWD.Selection.End)
If oWD.CheckSpelling(RangeOriginal)=False Then
oWD.ActiveDocument.CheckSpelling
Set RangeCorrected = oWD.ActiveDocument.Range(0,oWD.Selection.End)
RangeCorrected.copy
'
If RangeCorrected.Words.Count>7 Then
Cnt=RangeCorrected.Words.Count
Status= "The text beginning with: "&_
RangeCorrected.Words.Item(1)&" "&RangeCorrected.Words.Item(2)&" "&_
RangeCorrected.Words.Item(3)&"....."&vbCRLF&"and ending with: ....."&_
RangeCorrected.Words.Item(Cnt-2)&" "&RangeCorrected.Words.Item(Cnt-1)&_
" "&RangeCorrected.Words.Item(Cnt)&vbCRLF&"has been checked "&_
"and corrected version copied to the clipboard"
Else
Status= "<< "&RangeCorrected&" >>"&vbCRLF&" Your entry has been checked and "&_
" copied to your clipboard."
End If
'
Else
Status= "All words are spelled correctly"
End If
'
oWD.ActiveDocument.Close wdDoNotSaveChanges
oWD.Quit
Set oWD=Nothing
MsgBox Status,4144,"Spell Checker" |
_________________ -Jeremiah |
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 2926 Location: The Shell
|
Posted: Fri Mar 19, 2010 7:19 pm Post subject: |
|
|
Ok I think I get it now.
Can you please post a screen shot of the MS spell check window plus a window spy (AU3_Spy.exe) report for the window. This should shed some light.. _________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞ |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Fri Mar 19, 2010 7:38 pm Post subject: |
|
|
Does this return anything when spellcheck is running?
| Code: | WinGet, procID, PID, ahk_class bosa_sdm_msword
MsgBox % procID |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 2926 Location: The Shell
|
Posted: Fri Mar 19, 2010 7:39 pm Post subject: |
|
|
Ok I ran the vbs and on my system the spellchecker is linked to word. You could use process on word if theres one open.
Anyway, this works for me.
| Code: | vbFile := a_desktop "\sc.vbs"
FileDelete, % vbFile
vbsScript =
(
Dim oWD, RangeOriginal, RangeCorrected, Cnt, Status
Set oWD = WScript.CreateObject("Word.Application")
oWD.Visible =false
oWD.Documents.Add
On Error Resume Next
oWD.Selection.Paste
If err.number<>0 then
MsgBox "Please input text to your clipboard to check",4112,"Error"
oWD.ActiveDocument.Close wdDoNotSaveChanges
oWD.Quit
Set oWD=Nothing
Set oWD=Nothing
WScript.Quit
End If
'
Set RangeOriginal=oWD.ActiveDocument.Range(0,oWD.Selection.End)
If oWD.CheckSpelling(RangeOriginal)=False Then
oWD.ActiveDocument.CheckSpelling
Set RangeCorrected = oWD.ActiveDocument.Range(0,oWD.Selection.End)
RangeCorrected.copy
'
If RangeCorrected.Words.Count>7 Then
Cnt=RangeCorrected.Words.Count
Status= "The text beginning with: "&_
RangeCorrected.Words.Item(1)&" "&RangeCorrected.Words.Item(2)&" "&_
RangeCorrected.Words.Item(3)&"....."&vbCRLF&"and ending with: ....."&_
RangeCorrected.Words.Item(Cnt-2)&" "&RangeCorrected.Words.Item(Cnt-1)&_
" "&RangeCorrected.Words.Item(Cnt)&vbCRLF&"has been checked "&_
"and corrected version copied to the clipboard"
Else
Status= "<< "&RangeCorrected&" >>"&vbCRLF&" Your entry has been checked and "&_
" copied to your clipboard."
End If
'
Else
Status= "All words are spelled correctly"
End If
'
oWD.ActiveDocument.Close wdDoNotSaveChanges
oWD.Quit
Set oWD=Nothing
MsgBox Status,4144,"Spell Checker"
)
fileappend, % vbsScript, % vbFile
ifexist, % vbFile
run % vbFile
; find the spellchecker PID
settitlematchmode, 2
winwait, Spelling: English
winget, scPID, PID
msgbox % "Spell check window found!`nThe PID is: " scPID | You don't have to recreate the vbs. You just have to use everything under the 'find the spellchecker PID' section. That should work for you.
hth
edit: sinkfaze beat me to it. He's just using the ahk_class rather than the partial title in my example. _________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞ |
|
| Back to top |
|
 |
Sammy77 Guest
|
Posted: Fri Mar 19, 2010 8:08 pm Post subject: |
|
|
| BTW, there's a free tool that works like task manager but easier and much more detailed Process Explorer. You can have new processes highlighted (Options/Difference Highlight Duration), so it's easy to see which ones are created when you run the script. |
|
| Back to top |
|
 |
Jeremiah
Joined: 20 Apr 2009 Posts: 797 Location: North Dakota, USA
|
Posted: Fri Mar 19, 2010 8:45 pm Post subject: |
|
|
Thank you very much! Both of you. TLM and sinkfaze. It's working perfect now. Sammy, I'll check it out. Thanks! _________________ -Jeremiah |
|
| Back to top |
|
 |
|