Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Service waiting for a WM_ message 2

Status
Not open for further replies.

ncotton

IS-IT--Management
Jan 27, 2006
2,841
GB
Hey ya'll
Im trying to create a windows Service that bascially does nothing but wait for any instance of WM_SETTINGCHANGE and then launch an application, say MyApp, then go back to the waiting game.

I dont really have the foggiest, I'm coming up with blanks in reference to finding stuff on services triggering on WM messages, jsut stuff about launching messages.

Any help is very greatfully appreciated....juicy stars await the winner. :)

Neil J Cotton
njc Information Systems
Systems Consultant
 
See my reply in thread732-1220498.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I know how to launch a process, but I dont know how to detect the message event to trigger the launch.

Neil J Cotton
njc Information Systems
Systems Consultant
 
Anybody?

Neil J Cotton
njc Information Systems
Systems Consultant
 
On one hand, MS says that
The system sends the WM_SETTINGCHANGE message to all top-level windows when the SystemParametersInfo function changes a system-wide setting or when policy settings have changed.
so I doubt you will be able to catch the desired message within a windows service.

I am not sure about this, but couldn't you use SetWindowsHookEx with WH_GETMESSAGE ?
 
You should still be able to detect it. It is to catch instances of GPUpdates/refreshes.

Any ideas?

Regs
njc

Neil J Cotton
njc Information Systems
Systems Consultant
 
I know for a fact that command-windows don't respond to WM_SETTINGSCHANGE, so maybe services are the same.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
can u suggest anything

Neil J Cotton
njc Information Systems
Systems Consultant
 
ncotton said:
can u suggest anything

B00gyeMan said:
I am not sure about this, but couldn't you use SetWindowsHookEx with WH_GETMESSAGE ?

Have you tried it and it didn't work?

Or you could describe the problem in detail, maybe we will find a better solution, other then launching an application.

Microsoft Journal said:
One thing the Service Control Manager will not do is properly prepare a user's environment for a service. Environment variables are stored in the user's hive. The only environment variables a service will inherit are from the Service Control Manager. Its environment is based upon the system environment variables. If you make changes to the system environment variables, they will not be propagated back to your service until you reboot the machine. The Service Control Manager does not handle the WM_SETTINGCHANGE message as other system processes do when system environment variables change. -

So I suggest you try SetWindowsHookEx with WH_GETMESSAGE (there are some things you should be aware of such as: you must implement it in a separate library if you want it to be available for other apps; sometimes the callback method you register could be called twice for the same message (i.e. if the application calls PeekMessage with PM_NOREMOVE and later GetMessage).

Hope it helps.
 
The only thing that I want to do is:

Have a service running
Detect any time Group Policy refreshes (what ever way possible)
When a policy refresh is detected
Run my program.

any code snips on detecting these messages, i would be more than greatful.





Neil J Cotton
njc Information Systems
Systems Consultant
 
Cheers BM, I'll take a look at these and get back if I have any more problems.

DING!

Neil J Cotton
njc Information Systems
Systems Consultant
 
Seems to be what im looking for, but I cant manage to get it to work.

Confussed by the need to "CreateEvent", etc.

Any clues on actually making it work, in a coded example.

I have hte service set up, and it runs, just need to enter this event condition into it.

One thing about the RegisterGPNotification method is that it is a bool that returns t for ComputerSettingsChange, and f for UserSettingChange, so how would you work with it detecting any change rather than just one?

Neil J Cotton
njc Information Systems
Systems Consultant
 
Basically you create an event and then wait for it to become signaled.

Steps required:
1) Create the event.
2) Pass it to RegisterGPNotification.
3) Create a thread which will call WaitForSingleObject to wait until the event becomes signaled. Perform whatever actions you might need.

Here's a link to Using event objects (with an example)
ncotton said:
One thing about the RegisterGPNotification method is that it is a bool that returns t for ComputerSettingsChange, and f for UserSettingChange, so how would you work with it detecting any change rather than just one?
I imagine that you can call RegisterGPNotification twice with the same event but with different second parameter (one set to true and once set to false) and that would mean you get notified for both changes in the same event.
But I also imagine it would be easier to setup two events, one for each notification.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top