473,425 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

Trapping when Workstation is locked

Hi,
I need to trap when a workstation is locked. I saw this article
http://msdn.microsoft.com/library/de...n_packages.asp,
but i don't understand how to do an event handler of Winlogon Notification
Events. Also I saw the "WlNotify.dll" but either understand how to use it.

Somebody can help me? :$

Thanks
Nov 17 '05 #1
2 9349
I need to trap when a workstation is locked. I saw this article
http://msdn.microsoft.com/library/de...n_packages.asp,
but i don't understand how to do an event handler of Winlogon Notification
Events. Also I saw the "WlNotify.dll" but either understand how to use it.

Somebody can help me? :$

It's not something you do in C#, more likely in C. You need to export
a function entry point and you can't do that in C#.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2

"Kevin" <l@l.l> wrote in message
news:u6**************@TK2MSFTNGP09.phx.gbl...
Hi,
I need to trap when a workstation is locked. I saw this article
http://msdn.microsoft.com/library/de...n_packages.asp,
but i don't understand how to do an event handler of Winlogon Notification
Events. Also I saw the "WlNotify.dll" but either understand how to use it.

Somebody can help me? :$

Thanks


When running on XP or higher you can register for session change
notifications by calling (through PInvoke) TS API
"WTSRegisterSessionNotification", note that you need a Windows procedure to
capture the messages .
Here are the PInvoke declarations..

[DllImport("wtsapi32.dll")]
private static extern bool WTSRegisterSessionNotification(IntPtr hWnd,
int dwFlags);

[DllImport("wtsapi32.dll")]
private static extern bool WTSUnRegisterSessionNotification(IntPtr
hWnd);

and how to register,

private const int NotifyForThisSession = 0; // This session only

WTSRegisterSessionNotification(this.Handle, NotifyForThisSession);

and here the messages you can check..

private const int SessionChangeMessage = 0x02B1;
private const int SessionLockParam = 0x7;
private const int SessionUnlockParam = 0x8;

in your overriden WndProc.

protected override void WndProc(ref Message m)
{
// check for session change notifications
if(m.Msg == SessionChangeMessage)
{
if(m.WParam.ToInt32() == SessionLockParam)
OnSessionLock(); // Do something when locked
else if(m.WParam.ToInt32() == SessionUnlockParam)
OnSessionUnlock(); // Do something when unlocked
}

base.WndProc(ref m);
return;
}
void OnSessionLock() {...}

...
void OnSessionUnlock() {...}
call "WTSUnRegisterSessionNotification" when you no longer need to be
notified...

Willy.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Patrick | last post by:
I understand that with IIS5.1 on Windows XP Professional SP1, I can 1) Either set under IIS Manager-> Any specific Virtual Directory-> Configuration->Options->ASP Script timeout for all pages...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
21
by: Neil | last post by:
Is there a way to trap an error generated in another app that is controlled via automation? I have an Access 2000 app that opens Word 2000 and proceeds to open a series of documents and, in each...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
1
by: David | last post by:
Hi, There are anyway to detect when a workstation is locked like does the MSN Messenger that set the status to "Be Right Back" when the workstation is locked ? Some API ? Thanks =)
0
by: Neil | last post by:
I am trying shut down work stations that are left on over night. This works great when a user is logged in or the machine is locked but fails miserably when no body is using the work station, the...
14
by: ThunderMusic | last post by:
Hi, I want to detect in my C# app (can use iterop) if the workstation is locked. I've seen on the web people saying it's impossible except by looking if the Screensaver process is running. There...
7
by: dcruncher4 | last post by:
I have a condition in which I have to ignore an error while SELECTING. The error is lock timeout (Db2 error code -911). When fetchrow_arrayref fetches the locked row, I do get -911 which I trap...
20
by: miroku800 | last post by:
I don't know if this should be here or in an Access forum but here goes I have a VB6 program that uses an access database to record competitors and scores from a competion this works fine and i...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.