AutoHotkey Community

It is currently May 27th, 2012, 3:03 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: March 19th, 2010, 3:30 pm 
Offline

Joined: April 20th, 2009, 1:10 pm
Posts: 817
Location: North Dakota, USA
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 3:45 pm 
Check the ahk help for (guess what?) --> process :roll:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 3:58 pm 
Offline

Joined: April 20th, 2009, 1:10 pm
Posts: 817
Location: North Dakota, USA
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 4:13 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
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

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 4:17 pm 
Offline

Joined: April 20th, 2009, 1:10 pm
Posts: 817
Location: North Dakota, USA
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 6:16 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
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.

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 7:40 pm 
Offline

Joined: April 20th, 2009, 1:10 pm
Posts: 817
Location: North Dakota, USA
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 8:14 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
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.

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Last edited by TLM on March 19th, 2010, 8:18 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 8:18 pm 
Offline

Joined: April 20th, 2009, 1:10 pm
Posts: 817
Location: North Dakota, USA
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 8:19 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
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..

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 8:24 pm 
Offline

Joined: April 20th, 2009, 1:10 pm
Posts: 817
Location: North Dakota, USA
Certainly.

http://img641.imageshack.us/img641/6742/spellcheck.png

_________________
-Jeremiah


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 8:38 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Does this return anything when spellcheck is running?

Code:
WinGet, procID, PID, ahk_class bosa_sdm_msword
MsgBox % procID

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 8:39 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
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.

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 9:08 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 9:45 pm 
Offline

Joined: April 20th, 2009, 1:10 pm
Posts: 817
Location: North Dakota, USA
Thank you very much! Both of you. TLM and sinkfaze. It's working perfect now. Sammy, I'll check it out. Thanks!

_________________
-Jeremiah


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], rbrtryn, Yahoo [Bot] and 28 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group