Solved

How to detect Windows 2000 workstation is locked/unlocked?

Posted on 2008-10-01
7
1,414 Views
Last Modified: 2013-11-07
Using: VB.NET 2008 with Framework 2.0
Platform: WIndows 2000 SP4

Error:
Unable to find an entry point named 'WTSRegisterSessionNotification' in DLL 'wtsapi32.dll'.

I need to detect when the user has locked or unlocked their workstation in order to start/stop certain procedures from being called. I have gotten the following code to work on machines running Windows XP or above, but receive the error described if the OS is Windows 2000. Unfortunately, there are still a lot of users that run Windows 2000.

This doesn't throw an error in Windows 2000, but it also doesn't work. :(

Dim SessionSwitchHandler As New SessionSwitchEventHandler(AddressOf PhoneQueueMonitor_SessionSwitch)

Can someone please show me (sample code, please) how to do this on Windows 2000 using VB.NET 2005/2008?
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load

' Works in Windows XP and above but not Windows 2000

AddHandler SystemEvents.SessionSwitch, AddressOf SampleForm1_SessionSwitch

End Sub

 

Private Sub SampleForm1_SessionSwitch(ByVal sender As System.Object, ByVal e As SessionSwitchEventArgs)

        If e.Reason = SessionSwitchReason.SessionLock Then

            ' Computer locked

            Console.WriteLine("Workstation locked at: " & Now)

        ElseIf e.Reason = SessionSwitchReason.SessionUnlock Then

            ' Computer unlocked

            Console.WriteLine("Workstation unlocked at: " & Now)

        End If

    End Sub

Open in new window

0
Comment
Question by:blitzzy
  • 4
  • 3
7 Comments
 
LVL 11

Expert Comment

by:melmers
Comment Utility
WTSRegisterSessionNotification is only supported by XP and Vista.

Have you tried to build it on a win2k machine ?
0
 
LVL 1

Author Comment

by:blitzzy
Comment Utility
Hi melmers,

Yes, I have tried to run the program on a Windows 2000 machine. That's when I get that error on load. If WTSRegisterSessionNotification is not supported on Windows 2000, then how can I get the same functionality?
0
 
LVL 11

Accepted Solution

by:
melmers earned 500 total points
Comment Utility
a quick goolge have bring me this site where is an example


http://www.codeproject.com/KB/vb/DetectWindowslockunlock.aspx

But i don't know if it works with Win2k because i have no win2k pc
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:blitzzy
Comment Utility
I've seen this example before. It's so complicated! I tested it but it doesn't seem to work on 2000.
0
 
LVL 11

Expert Comment

by:melmers
Comment Utility
are there any errors ?
0
 
LVL 1

Author Comment

by:blitzzy
Comment Utility
I've played around with and made modifications tothe code in the link that you sent me and finally got it to work.
0
 
LVL 1

Author Closing Comment

by:blitzzy
Comment Utility
Provided useful information and code sample that required modification. Thanks for the help.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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