forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Find a window from a task

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Mon Apr 05, 2010 3:37 pm    Post subject: Find a window from a task Reply with quote

Is it possible to find the name of a window that belongs to a task? I want to be able to send a Window Close event to a program so it closes properly w/o having to kill the task.

I guess a better way would be, how can I send a WM_CLOSE command to all top level windows of a running process? (I.E. iexplore.exe, firefox.exe, winrar.exe, etc..)

Thank You

_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Mon Apr 05, 2010 7:43 pm    Post subject: Reply with quote

I had some code somewhere which allows you to identify which programs running are Windowed programs that show up on the task bar.

Yup, here it is:

Code:
GT-API_GetTaskBarWindows
Version: 1.0
First release date: September 8, 2004
Size: 1 kB
Rating: No ratings have been made
Comments: Add comment    
   
   Compatible with Visual DialogScript 5


Description:
Example showing how to get a list of all open windows like the taskbar, with a little help from some api calls.

The use of this script and calling dlls is at your own risk and you agree that the authors of this code will not be held responsible for any damages in any form that may or may not occur from the use of this information or code.

http://www.vdsworld.com/download.php?id=453&sid=0454a9400998465a1050cde556116800

I don't remember much about this though.. But I'm sure you have the information you need to manipulate the programs listed, such as close them etc.

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Mon Apr 05, 2010 7:50 pm    Post subject: Reply with quote

Cool Thanks! I'll check it out. Have you had a chance to test CJ Portable yet?

Edit:
I just tried it it does what it's supposed to, but I need to be able to close programs that are running from a specific location. I want CJP to close all running program that are running from the portable device that CJP is running on. I don't want to use killtask because the user might need to save work or the program needs to "clean up" as it exists.

Right now, I am using nircmd.exe to do this, but if I can find a way to do this using VDS, I can eliminate this extra file.

_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1562

PostPosted: Tue Apr 06, 2010 5:31 am    Post subject: Reply with quote

I'm sure if you know the windows handle to the window you can send it the WM_CLOSE message. Most programs that check if a file is open/editing usually prompt on the WM_CLOSE message if you want to save files before exiting.
Back to top
View user's profile Send private message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Tue Apr 06, 2010 11:51 am    Post subject: Reply with quote

That's just it. How can I find the handle if the top level window from the the process ID or the exe name if it is running (I.E. winrar.exe)? I can get all the running tasks using tasklist and then find where it is running from using modules.
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Tue Apr 06, 2010 12:43 pm    Post subject: Reply with quote

I'm thinking you would have to loop through all windows and check to see if the process they belong to matches the one you want to close.
Check out GetWindowModuleFileNameA:
http://msdn.microsoft.com/en-us/library/ms633517%28VS.85%29.aspx

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Tue Apr 06, 2010 2:20 pm    Post subject: Reply with quote

That looks like that might work.... now to convert it to VDS. I'm going to see if I can figure it out, but if anyone else knows and is willing to share.... Smile
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Tue Apr 06, 2010 2:31 pm    Post subject: Reply with quote

This is what I tried, but doesn't work. What am I doing wrong?

Code:

  loadlib user32.dll
  %H = @STRDEL(@WINEXISTS(#Progman),1,1)
  %Z = @LIB(USER32,GetWindowModuleFileName,%h,20,20)
  freelib user32.dll

_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed Apr 07, 2010 12:18 am    Post subject: Reply with quote

First it should be GetWindowModuleFileNameA since there is an ANSI and Unicode version of this function in the API.
You forgot the Return type in the @lib() function.
The 2nd param of GetWindowModuleFileName is a pointer to a buffer so the function can give you the information.
The 3rd param is the length that buffer can hold..most string buffers are 255 characters plus 1 spot for a NULL.
So here is what works:
Code:

  loadlib user32.dll
  %H = @strdel(@winexists(#Progman),1,1)
  %T = @fill(256)
  %Z = @lib(USER32,GetWindowModuleFileNameA,INT:,%h,@addr("%T"),255)
  info %T
  freelib user32.dll

_________________
-Sheep
My pockets hurt...


Last edited by SnarlingSheep on Wed Apr 07, 2010 1:37 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Wed Apr 07, 2010 12:29 am    Post subject: Reply with quote

Cool, thanks! I was on the right track though. LOL
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Wed Apr 07, 2010 4:45 pm    Post subject: Reply with quote

That's not working like I hoped. For some reason, it's not finding listing applications that are running from a drive other than C:.

Is there a function that can get a window name from a process ID?

_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1562

PostPosted: Wed Apr 07, 2010 5:11 pm    Post subject: Reply with quote

from the VDS help file:

Quote:

LIST WINLIST is used to obtain a list of all the windows (including hidden windows) present on the system. The flags may be specified as: C - class name; I - window identifier; N - window name or title. If more than one flag is specified then the values are concatenated in the list with each one separated by the current field separator character in a form suitable for splitting up with the PARSE command.


You can loop through this list and get all the windows handles, then use the windows api: GetWindowThreadProcessID

http://msdn.microsoft.com/en-us/library/ms633522(VS.85).aspx

That function will return the process id when you pass it a windows handle, by using winlist and passing each windows handle to this api function you can check to see if it matches the process id you are looking for, once it matches send the wm_close to the program/windows handle.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group