flat assembler
Message board for the users of flat assembler.

Index > Windows > maybe stupid question about closing window

Author
Thread Post new topic Reply to topic
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 21 Jul 2010, 06:55
Last years I write code twice a year and forgot almost everything about Windows programming.
I want to run browser with specified site after system boot and then close browser's window or browse's bookmark.

I tried to code something like that:
Code:
include 'win32ax.inc'
.data

adresik dd ?
.code


  start:

        invoke ShellExecute, NULL, "open", "http://www.ippp.pl", NULL, NULL, SW_SHOWNORMAL
        mov [adresik],eax
invoke Sleep, 10000


        invoke  MessageBox,HWND_DESKTOP,"You can click to close the browsing site!",invoke GetCommandLine,MB_OK
        invoke Sleep, 2000
        invoke FindWindow,"","???"     ; How to find and close the browser or last opened bookmark ?
        invoke  CloseWindow,eax

        invoke  ExitProcess,0

.end start           

but it can't do what i want...
Could You improve my mistakes ?

best regards!

_________________
Microsoft: brings power of yesterday to computers of today.
Post 21 Jul 2010, 06:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20357
Location: In your JS exploiting you and your system
revolution 21 Jul 2010, 07:15
You need to post a WM_QUIT message to the window.

Or, if you want to ensure the quit message is not ignored, use TerminateProcess.
Post 21 Jul 2010, 07:15
View user's profile Send private message Visit poster's website Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 21 Jul 2010, 07:55
the trouble is that i have only Instance Handle (from ShellExecute) and i don't know:

How To Find a Window Handle from an Instance Handle?

MSDN: use a GetWinHandle() function to return a Window handle based on an Instance handle
but there is no such a function inside of win32dlls...

_____________
TerminateProcess wants handle to the process.
I have no hProcess.

what is relation between Process handle, Instance Handle, Windows handle and Process Id ?
_____________
what is the easiest way to do what I want ?

_________________
Microsoft: brings power of yesterday to computers of today.
Post 21 Jul 2010, 07:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20357
Location: In your JS exploiting you and your system
revolution 21 Jul 2010, 08:18
After FindWindow you can use GetWindowThreadProcessId, then OpenProcess and TerminateProcess.

But if you already have the window handle from FindWindow then just post a WM_QUIT.

But isn't the Instance Handle from "open" the process handle? Have you tried to use it as a process handle?
Post 21 Jul 2010, 08:18
View user's profile Send private message Visit poster's website Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 21 Jul 2010, 08:43
I tried to use hInstance to TerminateProcess without success and
have no idea how use FindWindow:

i don't know windows classname
when i use "chrome.exe" as a second param the result of calling FindWindow function is NULL -thayt means the function fails

_________________
Microsoft: brings power of yesterday to computers of today.
Post 21 Jul 2010, 08:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20357
Location: In your JS exploiting you and your system
revolution 21 Jul 2010, 09:55
You have to use the window title not the executable name. Just leave the class as null.
Post 21 Jul 2010, 09:55
View user's profile Send private message Visit poster's website Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 21 Jul 2010, 11:18
but..
what should I do when the browser haven't title bar with windows title ? Smile

_________________
Microsoft: brings power of yesterday to computers of today.
Post 21 Jul 2010, 11:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20357
Location: In your JS exploiting you and your system
revolution 21 Jul 2010, 11:26
Every window has a title. Just that it might not be displayed. FindWindow still finds all titles regardless of whether they are displayed. Although conceivably the title could be blank making the job harder.

Instead, if you know the executable name you can just enumerate the running processes and terminate. Not a friendly way to do it but it would work reliably unless you have a rootkit hiding things.
Post 21 Jul 2010, 11:26
View user's profile Send private message Visit poster's website Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 21 Jul 2010, 11:32
THX 4 HELP

the title in my case is IPPP - Google Chrome

_________________
Microsoft: brings power of yesterday to computers of today.
Post 21 Jul 2010, 11:32
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.