Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to detect Windows 2000 workstation is locked/unlocked?

Posted on 2008-10-01
Medium Priority
Last Modified: 2013-11-07
Using: VB.NET 2008 with Framework 2.0
Platform: WIndows 2000 SP4

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

Question by:blitzzy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 11

Expert Comment

ID: 22621502
WTSRegisterSessionNotification is only supported by XP and Vista.

Have you tried to build it on a win2k machine ?

Author Comment

ID: 22623642
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?
LVL 11

Accepted Solution

melmers earned 2000 total points
ID: 22623695
a quick goolge have bring me this site where is an example

But i don't know if it works with Win2k because i have no win2k pc
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal


Author Comment

ID: 22624071
I've seen this example before. It's so complicated! I tested it but it doesn't seem to work on 2000.
LVL 11

Expert Comment

ID: 22643962
are there any errors ?

Author Comment

ID: 22649780
I've played around with and made modifications tothe code in the link that you sent me and finally got it to work.

Author Closing Comment

ID: 31502148
Provided useful information and code sample that required modification. Thanks for the help.

Featured Post

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

661 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