Article View: borland.public.cppbuilder.nativeapi
Article #1595Re: Service spawns Process - EnumWindows problem
From: Remy Lebeau (TeamB)
Date: Fri, 20 Jul 2007 17:33
Date: Fri, 20 Jul 2007 17:33
50 lines
3021 bytes
3021 bytes
"Paul" <camrad@internode.on.net> wrote in message news:46a0a522$1@newsgroups.borland.com... > Each of the above is started with > if (CreateProcess(... <snip> Which means that each process is going to run in the context of the user account that the service is running it. By default, that is the SYSTEM account. Also, unless you are filling in the lpDesktop member of the STARTUPINFO structure, then each process is going to run in the context of the service's workstation as well, which is hidden and does not have access to the workstation that the user logs into. > Using Windows Messaging > - RegisterWindowMessage > - EnumWindows to get the required handle > - then PostMessage That won't work in a service unless you first connect it to the user's desktop via SetThreadDesktop(). Same thing with spawned processes - they must be running in the same desktop that the target window is running in, or else EnumWindows() and PostMessage() will fail to locate it. > At this point EnumWindows can find the required handle from > the process id. There may or may not be a user logged on at > this point - it makes no difference to the following outcomes. Yes, it does make a difference. > EnumWindows does not have this process id in the list returned > when trying to get the new window handle to use, so no messaging > is possible withou a valid handle. Every time a process is restarted, the other apps will have to rescan the active windows in order to get the new ID. Alternative, assuming the guardian is running in the same desktop as the other processes, it could simply broadcast a message containing the old and new IDs, and the processes can then update themselves accordingly. > Manually entering the windows handle of the restarted process > into the guardian and using PostMessage - The restarted process > does not see the message. That suggests to me that the guardian is not actually running in the same desktop afterall, as window messages cannot pass across desktop boundaries. Gambit
Technical Details
Message-ID:
<46a0f1f3$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<46a0a522$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b7dc9abb756c9528 X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <46a0a522$1@newsgroups.borland.com> Subject: Re: Service spawns Process - EnumWindows problem Date: Fri, 20 Jul 2007 10:33:27 -0700 Lines: 52 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 75.82.252.126 Message-ID: <46a0f1f3$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1184952819 75.82.252.126 (20 Jul 2007 10:33:39 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail X-Original-Bytes: 2875