Solved

Problem with FindWindow in A Service (Vista SP1)

Posted on 2009-05-03
11
1,655 Views
Last Modified: 2012-06-27
Hi.

Here is my Delphi code:

procedure SendMessageToWindow(msg: LongWord;value:longword=0);
var Wnd: THandle;
begin
  Wnd := FindWindow('myClass', NIL);
  if Wnd > 0 then
  begin
       if IsWindowResponding(Wnd,100) then
          SendMessage( HWND_BROADCAST,
               RegisterWindowMessage('myAppMessage'),
               msg,
               value )
       else
           Error('hung!!');
  end;
end;

It searches for the handle of a window and sends a message to that window.

The code works when used in an normal application (both in xp and vista).
The code works when used in a service application running windows xp.
The code does NOT work when used in a service application running vista (handle is always = 0).

Apparently Vista restricts Services so they cannot use the FindWindow api function anymore.

Is there a way around this? If not, which other (simple) way to send messages to an application from a service (so the app can go to front etc).

Thanks in advance.
0
Comment
Question by:ThomasReimann
  • 5
  • 5
11 Comments
 

Author Comment

by:ThomasReimann
ID: 24292741
p.s.

The service is marked as non-interactive (and works with XP perfectly).
0
 

Author Comment

by:ThomasReimann
ID: 24293068
I found the explanation here:

http://www.microsoft.com/whdc/system/vista/services.mspx

I still do need a work-around how to communicate something to an application without using something like tcp/ip.
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 24295863
If you do not wnat to use TCP/IP you could use mailslots which are not like email.

I have used them and they work just great.

You could also use a components called TssSimpleIPC from SunnisSoft. This uses I believe Windows messaging.
http://www.sunisoft.com
http://www.torry.net/vcl/system/appscommunications/simpleipc.zip

It works very well in services and applications and it is free. Not sure what version of Delphi so could take some tweaking in newer versions.

John
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 24295996
What happens with your service when you compile as Interactive and run it in Vista?

The SimpleIPC uses FindWindow(). I have written several services and they run on Vista just fine using SimpleIPC but I have the service compiled as Interactive... never tried the other way since there is interaction between the service and other services and running applications.

Just really curious...

John
0
 

Author Comment

by:ThomasReimann
ID: 24296269
Vista does not allow interactive service anymore. I'll look at your suggestions.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 18

Expert Comment

by:Johnjces
ID: 24296320
So my services when running under Vista would run as a non interactive service?

I guess I had better read that Microsoft paper.

THANKS!

John
0
 

Author Comment

by:ThomasReimann
ID: 24296758
Rather they will not run at all. It's a security issue.
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 24296870
Hmmm...

Just to make certain that I was not blowing smoke, I checked one of my services that is written for Windows 2000 up to and including Vista.

I have an XP/Vista manifest compiled in as well (see snippet for manifest).

And Interactive := True.

The service works just fine under Vista! It starts, runs; does everything it is supposed to do. I read nothing about a manifest and I really didn't read anything stating that the service would not run. It would just not run as expected or the expected interactive behavior would not function.

Just for info and trying to learn along the way too!

John
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

<assemblyIdentity

    version="2.0.1.1"

    processorArchitecture="X86"

    name="CDLibServerSvc.EXE"

    type="win32"

/>

<description>A server service application for THE CD Library</description>

<dependency>

        <dependentAssembly>

                <assemblyIdentity

                        type="win32"

                        name="Microsoft.Windows.Common-Controls"

                        version="6.0.0.0"

                        processorArchitecture="X86"

                        publicKeyToken="6595b64144ccf1df"

                        language="*"

                />

        </dependentAssembly>

</dependency>

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">

    <security>

        <requestedPrivileges>

            <requestedExecutionLevel level="asInvoker" uiAccess="false"/>

        </requestedPrivileges>

    </security>

</trustInfo>

</assembly>

Open in new window

0
 

Author Comment

by:ThomasReimann
ID: 24297119
"Important  Services cannot directly interact with a user as of Windows Vista. Therefore, the techniques mentioned in the section titled Using an Interactive Service should not be used in new code."

http://msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 24297197
Thomas.

Thanks.. I saw, "Rather they will not run at all. It's a security issue." above but did not read that but did read, "Important  Services cannot directly interact with a user as of Windows Vista....",

and therefore my confusion since even though Interactive is true, (so that I have one exe for multiple versions), all works just fine. Obviously I don't need Interactive := true and never changed it to see what would happen since I "assumed" (Hate that word) that the WindowsMessaging (SimpleIPC) would require that.

Interesting and thank-you!

Let us know what happens in your quest! ...out!

John
0
 
LVL 2

Accepted Solution

by:
djdj earned 500 total points
ID: 25287682
Have you looked into the "Interactive Services Detection" service installed with Vista?  
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 89
Mobile Keyboard covers the display of the TMemo 3 78
Delphi XE10 Round Image 2 77
Making delphi communicate with a c# service 16 89
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now