SetWindowsHookEx from service to user window

I can call successfully hook into another window's message proc but the same 
won't work from a service.
Even after turning 'allow to interact with desktop' i still get 
ERROR_ACCESS_DENIED when calling SetWindowsHookEx.

I know it has to do with security, desktops and window stations but I still 
havent figured it out. I'm not sure if I need an extra thread and which 
thread needs to be associated with which desktop. This is what I've tried so 
far:


hWnd -> hooked window
DWORD thid = GetWindowThreadProcessId(hWnd,NULL);
HDESK desk = OpenDesktop("default", DF_ALLOWOTHERACCOUNTHOOK, FALSE, 
GENERIC_ALL);
if (desk == NULL) return GetLastError();
if (!SetThreadDesktop(desk)) return GetLastError();
g_hHook = SetWindowsHookEx( WH_CALLWNDPROC,(HOOKPROC)HookProc,hDll, thid);
DWORD dw = GetLastError();

Any clues?


0
Oleg
4/21/2007 6:19:56 AM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
1408 Views

Similar Articles

[PageSpeed] 32

No surprise here.  You can't set a hook from a service to an application, because this
would require crossing a desktop boundary, which is forbidden.  It is not going to be
possible.

Note that the specification of DF_ALLOWOTHERACCOUNTHOOK does not allow cross-desktop hook
setting; it only allows other accounts in the *same* desktop to hook the CURRENT process;
it does not allow you to hook some other process, even in the same desktop.

Note the warning about security: it says that the thread which is assigned to the desktop
could be hooked; it does not say the thread can hook other windows in the desktop to which
it is assigned.
				joe

On Fri, 20 Apr 2007 23:19:56 -0700, "Oleg Mustiazza" <.> wrote:

>I can call successfully hook into another window's message proc but the same 
>won't work from a service.
>Even after turning 'allow to interact with desktop' i still get 
>ERROR_ACCESS_DENIED when calling SetWindowsHookEx.
>
>I know it has to do with security, desktops and window stations but I still 
>havent figured it out. I'm not sure if I need an extra thread and which 
>thread needs to be associated with which desktop. This is what I've tried so 
>far:
>
>
>hWnd -> hooked window
>DWORD thid = GetWindowThreadProcessId(hWnd,NULL);
>HDESK desk = OpenDesktop("default", DF_ALLOWOTHERACCOUNTHOOK, FALSE, 
>GENERIC_ALL);
>if (desk == NULL) return GetLastError();
>if (!SetThreadDesktop(desk)) return GetLastError();
>g_hHook = SetWindowsHookEx( WH_CALLWNDPROC,(HOOKPROC)HookProc,hDll, thid);
>DWORD dw = GetLastError();
>
>Any clues?
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
4/22/2007 4:30:56 PM
Joe, thanks. I'll move the functionality to console app instead of service.

Oleg

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:b4ul23p52sm7ndjn1rgimrkfi21rr4273a@4ax.com... 


0
Oleg
4/22/2007 9:12:19 PM
Reply:

Similar Artilces:

Path to user's desktop
I want to have an app default to saving its data files to the desktop if the user doesn't specify otherwise, or specifies a non-writable location. Is there a function or recommended registry entry that provides the path to the user's desktop? I found what looks like a what I want in the registry, fully spelled out in a REG_SZ: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders. The "Desktop" value contains "C:\Documents and Settings\myusername\Desktop", which is my current desktop folder. It also is available as a REG_EXPAN...

Delivery status notification not sent to external users
When external users send messages with the "Request Delivery Receipt.." option, the message is delivered successfully, but a DSN success message is not sent back to the sender. Delivery receipts are generated correctly on messages sent between internal users. External users do recieve NDR's for mail that is mis-addressed and also receive read receipts correctly. Under Global Settings, Internet Message Formats, Default format (that is the only format), Advanced tab, I've selected the Allow Delivery Reports option. I've tried toggling the settings on this tab in b...

Add new user in CRM 3.0
On a new system, using the web interface to add a new user, ust after putting in domain\username I get the message "An error has occurred. For more information contact your system admnistrator" - no info from AD is displayed. Using the Deployment Manager, I never manage to get any domains or users listed. This leaves me unable to add users at all.. Single Domain: Win2003 with AD. SQL 2005 Svr SP1 Any help would be appreciated.. You might go to the web.config file in the CRM root folder and set remote errors to Off so you can get an informative error message. -- Matt Wittema...

Another user can't email us -- can't tell if it's b/c his system or ours...
Can anyone help me to decipher this NDR? This certain user from another company has been trying to email three people here a very small word document (it's three attachments -- each one about 56kb big). I don't have any email quotas for sending and receiving on any of my users. And, I was successfully able to email person1, person2, and person3 a very large (6MB) attachment from my gmail.com account. So.... can anyone tell where the issue lies? Thanks, Blake -----Original Message----- From: ABillig@fdfsfd.com] [mailto:ABillig@fdfsfd.com] Sent: Tuesday, November 22, 2005 ...

Error generating the xml document when trying to access the web service
Hi There, I get this error when I try to access the web method..I can see that the objects are constructed properly before they are passed....All I am doing is this... ------------------------------------ I have these two classes in the client class as well as the web service.... public class ResponseChartImage { public int InstanceId; public int VariableId; public byte[] ImageByte; public ResponseChartImage(){} } public class RequestChartImage { public int InstanceId; public int VariableId; public RequestChartImage(){} } ------------------------------------------------...

users sending messages to themselves
Hello all, I'm running a Exchange 2000 server w SP3 on W2K box w SP4. I have some users who have this old habit of sending a copy of out going message to themselves when they compose a new message by cc or bcc or even To field. I ask them not to do but they are still doing it. Is there a way (may be a script or rule or anything in Exchange or third party software) to stop this. I was told by someone that there is nothing of that nature but I'm still not convinced. There's gotta be a way. Thanks Raj Bambrah Why not let them do whatever they damn well please? Raj Bambrah wro...

Bring an app window to the front
In my app, I have the HWND of another application (that is not written by us). From my app I want to bring this other app to the front but NOT in front of any system model dialogs that may be knocking about i.e. if this other app's window is obscured by other applications I want to bring it to be made visible., Is this impossible ? My window must always be in front of this other app, thats why I made my app system modal. If I SetWindowPos( hwndOtherApp, MyWindow, ..... ) then this initially achieves my goal, but now the other app automatically becomes system modal and so can app...

How to Connect Comcast Box to Windows Xp to TV Tuner
Hi , I have been trying to figure this out for a week now can someone please help greatly appreciated ? I have Dell Xps Gen 5 Desktop with built in Dual Tv tuner and have been trying to figure out how to set it up To my Comcast Box (Only 1 Comcast box) no top box , I had the cable hooked up from the comcast box to my desktop and threw Media Center setup I saw Tv picture , but when it comes to the option to change channels it Will not change the channels threw the Xp Controller. I don't know what I'm doing wrong any answers greatley appreciated thank you . what do...

Service Pack 2 Installation Questions
I have a few questions about the SP2. - Is it now supported? - Should I turn off the Exchange services as well as the AV services before the install? On Thu, 8 Dec 2005 09:41:02 -0800, "Griff" <Griff@discussions.microsoft.com> wrote: >I have a few questions about the SP2. > >- Is it now supported? Yes. > >- Should I turn off the Exchange services as well as the AV services before >the install? Disable all 3rd party services and manually stop Exch Services if desires. the update will stop the exch services manually however. Backups before and after ...

Outlook doesn't remember window size...
Hello, we have the problem that outlook doesn't remember the window size. If I want to write a new mail the 'new mail' window opens very very small (but not miminized). If I change the size of this window like I want and close the window next it opens as I closed it. -> this is what it should be. But when I close outlook and reopen it, the 'new email' window is again small. Outlook 2003, SP3 (with Exchange 2003 Server) No macros activated Word is not used as mail editor. The problem exists on 2 of 15 computers. I tried to close the window and even outlook with ctrl ...

Excel 2003 Viewer: No more "Browse in same window" IE functionality?
With Excel viewer '97, by going into the file associations in explorer, you could modify the '.xls' entry and choose 'browse in same window'. In IE, this would then launch the excel attachment in the same window. After installing the recently released Excel Viewer 2003, the 'browse in same window' checkbox is greyed out. Is this a feature that was dropped in the new release? If so, is there any registry hack I can use to re-enable it? I'd really like to have the old functionality in the new version...without it, I can't push out the new version. Any hel...

Restored GP 8.0 from server crash, users can't log in and SA oddit
The server that hosts GP 8.0 crashed, we had a backup and restored it. Upon boot SQL 2000 was giving us issues, we had to reinstall it to get it running again. The GP 8.0 DB's were reattached. I can see the users in their respective DB's from Enterprise Manager but when I attempt to log in as said users, it gives the dreaded: "Your SQL Server login record is not a valid user record in Great Plains. Enter a different login, or contact your Great Plains system administrator." Right now the only account that lets me on is the SA but even so, whenever I attempt to do ...

Receiving UDP streaming through Windows Media Player
Hi All, I am using Windows Media Player Version 11.0.5721.5268 and VLC version 1.0.3 I am trying to stream video over UDP between two media players, the transmitter is VLC and the receiver is Windows Media Player. To roll out networking problem I have installed VLC and Windows Media Player on the same IP host and I use 127.0.0.1 or the IP address assigned to the computer from my DHCP server. Please send free to send your reply as well to ramig-at-comsysmobile-dot-com I manage to do so when the receiver is VLC as well -- so there is no networking or firewall issue. My...

user quota is exceeded
I can't get my email on outlook 2002 it says user quota is exceeded.. any help would be nice "rahman abdul" <rahmany@yahoo.com> wrote in message news:098f01c366d6$f305e470$a301280a@phx.gbl > I can't get my email on outlook 2002 it says user quota > is exceeded.. > any help would be nice That means you are using Exchange as your mail server (be sure to mention such important details). You are allocated a fixed amount of disk space for your mailbox. You've been saving way too much in your mailbox. Delete the garbage and start using AutoArchive to move s...

Window placement problem: SW_HIDE, GetWindowPlacement, SetWindowPlacement etc.
Hi, In my OnInitDialog method I have some controls decide whether it's appropriate for them to be visible. If they decide against being visible, they'll call SetWindowPlacement for hiding and do some rearranging of other controls. To do all of this in a neatly manner, a control in progress of hiding wants to know the "hidden" state of other controls in the same dialog. One would expect GetWindowPlacement to be a nice source of this information. But the GetWindowPlacement / SetWindowPlacement combo seems very unreliable to me. I've narrowed it down to this: WI...

SQL Server reporting services
Has anyone tried to install the new SQL Server reporting services on a server running CRM and SQL Server? I'm getting an error during install saying that the data base is invalid but i've applied all the right service packs as far as i can tell. So the only thing i can think of is that the CRM is causing issues. ...

Users external email addresses
On an Exchange 2003, I have a couple of users that have other SMTP addresses that were added manually. Usually you get your rules from 2003 RUS, but there is some users that have 2 or 3 email addresses assigned to their user account because they were added manually. How can I go about running some type of find to see what are the different email addresses that other users are publishing. I do not want to go one by one and go to email address tab on the user account and search for these type of users. Thanks in advance. On Fri, 14 Jan 2005 05:57:01 -0800, Vic <Vic@discussions.microsof...

Homepage Quick Links for Fixed Assetss Windows
Similar to other GP windows, the fixed assets windows should be allowed to be added to a user's homepage as a Quick Link. -- Haiden Turner Winged Disc Technologies, LLC Dallas, Texas ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Business...

ie 8 in windows XP crash
ie 8 loads PDF file then crashes, reloads file then crashes..... IE 8 is upto date Adobe reader 9.3 is up to date Any suggestions. "Tmeister" wrote: > ie 8 loads PDF file then crashes, reloads file then crashes..... > > IE 8 is upto date > Adobe reader 9.3 is up to date > > Any suggestions. Get rid of Adobe reader & get Foxit--faster, much smaller & less complicated. Been using it for 2 years with no problems, even when message is "must have Adobe...." TIC "Tmeister" wrote: > ie 8 loads PDF file...

Urgent: Exchange 2003 user missing emails...
Hi there. SBS, Exchange 2003. One user seems to be missing items from his inbox from a certain date period. He logs into multiple computers, I have checked the usual things such as local PST's, Archive Folders, Views and Recover Deleted Items to no avail. There is a backup on the server, is this the best way to go about recovering the items? http://searchexchange.techtarget.com/originalContent/0,289142,sid43_gci969555,00.html Anything else I can try? Anyone know where these messages could have gone? Thanks for your time. Colin. You could use a Recovery Storage Group and Exmerge to g...

adjusable columns in original dynamics windows
adjusable columns in original dynamics windows, that you can sort on and size properly. Is there a way to post a screenshot to show you what i'm on about ?? ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGr...

How to change the service config through program?
Hi, I am trying to change the configuration of the service SQLSERVER AGENT using the API ChangeServiceConfig. In that I am passing a new user name and password as arguments. That API returns successfully and I can change the StartType (AUTOMATIC,DEMAND_START etc) as well. But after that when I try to start the service using the API StartService, it returns the error like "The user doesn't have the permission to log on as a service". Why is this so? How can I change the configuration successfully through the program? When I set the User name and password(which I p...

Outlook Task Window Flickering Rapidly
I am running Outlook 2007, but the same issue happened in Outlook 2003. When I go to the Task window and click the field labeled "Click Here to Add a New Task", the entire window begins to flicker rapidly as soon as I start typing. It still allows me to enter the task without any issue, but it is very annoying. The only way to make it stop is to select another open window and then go back to the Outlook window. Any ideas? I cannot find anything on this. Thanks. ...

Win7 backup error: Windows Backup skipped I:\ because it cannot be found on drive I:\
After expanding my O/S disk and thus deleting "Disk I" my windows 7 backup completes successfully but gives me the above error for the previously deleted Disk. More of an annoyance. I DID have a disk I on the first Backup file I did before the expansion and I have NOT tried to restore any files, etc yet. I am looking for a registry or ? change that can fix this and not necessarily a 'work-around.' My Computer, Device Manager, Win 7 Backup devices, etc do NOT show any "Disk I." available on the computer. All help is appreciated. Backup error: Window...

windows 7 search not working
Hi, I have a brand new laptop running Windows 7 Home Premium x64. Windows Search does not work - there is no drive activity and I get no results. I've seen the KB article 977380 about Win7 search not working and I have tried the hotfix, but with no luck. Search still does not work. The indexing service is running, AFAICT, and the drive properties are set to allow indexing. Anyone know the answer to this? (please don't say Google Search 8-) George On Thu, 19 Aug 2010 03:33:47 -0400, George Neuner <gneuner2@comcast.net> wrote: I was advised by email to tr...