Solved

Windows Hook (SetWindowsHookEx) and RunAs...

Posted on 2003-11-11
5
772 Views
Last Modified: 2007-12-19
I have an app which does basically the same kind of Idle Tracking as

http://www.codeproject.com/dll/trackuseridle.asp?target=idle|hook

It works fine on 2k, 98, NT, and XP.

However, I just received a comment that a user running WinXP is having trouble running a RunAs.. Application. (iow, running an app as a different su'd user in windows xp).

I was able to verify the same problem, by running from a cmd prompt: runas /user:DOMAIN\USERNAME notepad

When Notepad comes up it's blank (i.e not accepting mouse and keyboard events) until I kill the hook-owning app described above.

What needs to be done to allow UI windows apps with system hooks to persist through multi-users in a single shell (via running "RunAs" within windows)?  I think this might be related to a recent security patch of XP, but how can I work around this?

Is this something in the code, or is this just a compile/link-time flag that I need to set?

Thanks in advance!
0
Comment
Question by:dovkatz
5 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>It works fine on 2k, 98, NT, and XP.

If you need idle tracking on these platforms, it might be worthwile to consider something 'official' - check out this MSJ Q&A column where Paul DiLascia discusses some options: http://www.microsoft.com/msj/0200/c++/c++0200.asp

 LASTINPUTINFO lpi;
 lpi.cbSize = sizeof(lpi);
 GetLastInputInfo(&lpi);

 DWORD dwIdleTime = lpi.dwTime;
0
 
LVL 2

Author Comment

by:dovkatz
Comment Utility
jkr. Thanks for the response.

The reason I mentioned the URL at codeproject is because that's exactly what I do. (MSJ's version doesn't address a subtle bug in same-position mouse events, that's why I used codeproject's at the time)....  I am familiar with both sites.

I run an app with this stuff set and while it's running I launch something via runas in winxp.

The reason I'm not going with lastinputinfo is specifically because I need NT and 98 support, which that doesn't have (hence I mentioned the windows version list).

So basically, what I'm looking for is a suggestion of why "RunAs" on xp / 2k causes the "Runned As" app to hang until I kill my Hook-Owning App.

Do I need a DLLMain() with an Unload() whenever the app attaching me is not being run in the same shell?  How can I tell if a process calling DLLMain is running as "RunAs" as opposed to within the regular windows shell?  

FYI even if I runAs notepad as my self, I stll have this problem, so I cant' just compare usernames as a solution.
-d
0
 
LVL 2

Author Comment

by:dovkatz
Comment Utility
FYI - It looks like windows XP's recent patch might have mucked with the way hooks interact with RUNAS programs such as "TaskPad" etc.

( Quote from "Patches that Patch (eWeek)" http://www.eweek.com/article2/0,4149,1383105,00.asp )
Last month's Windows upgrades, however, caused him grief. "One of the patches broke one of our applications, so Microsoft is discussing with us whether or not the patch should have a 'shim' or something." Microsoft said the patch in question changes the way Windows handles text input and that other developers should change their code to avoid any problems.
0
 
LVL 9

Expert Comment

by:tinchos
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
Comment Utility
PAQed, with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

772 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

10 Experts available now in Live!

Get 1:1 Help Now