473,776 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetCursorPos not working if desktop is locked

Hi guys...

could anyone please help me with my problem getting mouse cursor position while desktop being locked (WIN + L).

MSDN says:
"The input desktop must be the current desktop when you call GetCursorPos. Call OpenInputDeskto p to determine whether the current desktop is the input desktop. If it is not, call SetThreadDeskto p with the HDESK returned by OpenInputDeskto p to switch to that desktop."

src: http://msdn2.microsoft.com/en-us/library/ms648390.aspx

So I tried the following:

Imports System.Runtime. InteropServices

Public Class Form1

Private Const DESKTOP_SWITCHD ESKTOP As Int32 = &H100&
Private Const DESKTOP_READOBJ ECTS = &H1&
Private Const DESKTOP_WRITEOB JECTS = &H80&

Declare Function GetCursorPos Lib "User32" (ByRef lpPoint As Point) As Long

<DllImport("use r32.dll", SetLastError:=T rue)_
Private Shared Function OpenInputDeskto p(ByVal dwFlags As Integer, ByVal fInherit As Boolean, ByVal dwDesiredAccess As Integer) As IntPtr
End Function

<DllImport("use r32.dll", SetLastError:=T rue)_
Private Shared Function SetThreadDeskto p(ByVal hDesktop As Int32) As Int32
End Function

<DllImport("use r32.dll", SetLastError:=T rue)_
Private Shared Function OpenDesktop(ByV al lpszDesktop As String, ByVal dwFlags As Integer, ByVal fInderit As Boolean, ByVal dwDesiredAccess As Integer) As IntPtr
End Function
Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles Timer1.Tick
Dim xx As IntPtr = OpenInputDeskto p(0, True, DESKTOP_SWITCHD ESKTOP)
SetThreadDeskto p(xx)

Dim pt As Point
GetCursorPos(pt )
ListBox1.Items. Add(pt.X.ToStri ng + " x " + pt.Y.ToString)
End Sub

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

End Sub
End Class

But sadly, it doesn't work. After desktop gets locked all I get is 0 x 0 for x and y coordinates.
Maybe you can recommend me some different approach to observe mouse movement activity from windows service. After all, I don't need exact coordinates, all I need is to determine if someone is using the mouse.

Thank you in advance.

Cheers,
Damjan

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Dec 27 '07 #1
1 6133
Damjan,

You can't get this information while the desktop is locked. While the
desktop is locked, the security subsystem takes over, and your desktop is
off limits.

At that point, you would have to hook into the O/S (people have done it
by replacing GINA.dll, but you can't do this in managed code, and on top of
that, you can't do it in Vista, as it has a different model).

While the desktop is locked, you are going to have to do without cursor
information if you are using managed code.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<Damjan Maliswrote in message news:20******** *************** @gmail.com...
Hi guys...

could anyone please help me with my problem getting mouse cursor position
while desktop being locked (WIN + L).

MSDN says:
"The input desktop must be the current desktop when you call GetCursorPos.
Call OpenInputDeskto p to determine whether the current desktop is the
input desktop. If it is not, call SetThreadDeskto p with the HDESK returned
by OpenInputDeskto p to switch to that desktop."

src: http://msdn2.microsoft.com/en-us/library/ms648390.aspx

So I tried the following:

Imports System.Runtime. InteropServices

Public Class Form1

Private Const DESKTOP_SWITCHD ESKTOP As Int32 = &H100&
Private Const DESKTOP_READOBJ ECTS = &H1&
Private Const DESKTOP_WRITEOB JECTS = &H80&

Declare Function GetCursorPos Lib "User32" (ByRef lpPoint As Point) As
Long

<DllImport("use r32.dll", SetLastError:=T rue)_
Private Shared Function OpenInputDeskto p(ByVal dwFlags As Integer,
ByVal fInherit As Boolean, ByVal dwDesiredAccess As Integer) As IntPtr
End Function

<DllImport("use r32.dll", SetLastError:=T rue)_
Private Shared Function SetThreadDeskto p(ByVal hDesktop As Int32) As
Int32
End Function

<DllImport("use r32.dll", SetLastError:=T rue)_
Private Shared Function OpenDesktop(ByV al lpszDesktop As String, ByVal
dwFlags As Integer, ByVal fInderit As Boolean, ByVal dwDesiredAccess As
Integer) As IntPtr
End Function
Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
Dim xx As IntPtr = OpenInputDeskto p(0, True, DESKTOP_SWITCHD ESKTOP)
SetThreadDeskto p(xx)

Dim pt As Point
GetCursorPos(pt )
ListBox1.Items. Add(pt.X.ToStri ng + " x " + pt.Y.ToString)
End Sub

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

End Sub
End Class

But sadly, it doesn't work. After desktop gets locked all I get is 0 x 0
for x and y coordinates.
Maybe you can recommend me some different approach to observe mouse
movement activity from windows service. After all, I don't need exact
coordinates, all I need is to determine if someone is using the mouse.

Thank you in advance.

Cheers,
Damjan

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com

Dec 27 '07 #2

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

Similar topics

1
4574
by: Scott Numbers | last post by:
Fellow C-Sharp developers, I have an application that must be able to display a message on a desktop even if the screen saver has locked the computer. If you pass "ServiceNotification" as a MessageBoxOption on the MessageBox.Show method, the MessageBox will display even if there is not a user logged in. Unfortunately, my users want to override the colors as well as make other modifications to the MessageBox that cannot be done since the...
2
1472
by: PeteCresswell | last post by:
I've been changing my apps to be compliant with MS's standard of writing temp data only to C:\Documents And Settings\.... But now I'm converting an app that creates .TXT files and spreadsheets for the user. Making them navigate to C:\Documents And Settings\.... seems needlessly onerous if I can write those files to their desktop. So, am I within the rules if I write a persistant/non-temp file that
0
2812
by: ntm | last post by:
Hi all you good m8 I try to make my first small program in vb, but im not very succesfull :D (Im using Visual Studio 2005) Form my own program i will like to set focus on an other running application. Then i will get and set cursor positon. After that i will like to send KeyCommand. But to start with i will be very happy if i can get "user32" dll to work :) Therefore i have try this code - but i got a 18 character long number back as...
3
1582
by: Jay | last post by:
Hey There, Is it possible to get an unique identifier for a desktop that a particular app is running from, from a service? If there are two instances of the app running on different desktops (one desktop is locked, the other is in use) then the service should have different values for each one. Thanks, Jay (patelj27b at gmail dot com)
0
2764
by: lucretia | last post by:
Hi, I've created a layout for an Ajax side that is "single paged" in that when the browser is resized, so is the page. The header is locked to the top, the right panel is locked to the right side and the footer is locked to the bottom leaving the main content area as a scrollable resiable area in the centre of the window. This works as expected in FF, Opera, IE7, but not in IE6. the problem with IE6 is that positioning using left and...
8
6659
by: Rajesh Soni | last post by:
Hi! I'm getting a PInvoke error while trying to execute the following code... declaration: Structure POINTAPI Dim x As IntPtr
4
1561
jinalpatel
by: jinalpatel | last post by:
I am totally new to the VBA and I have following problem. I have two tables Holderdata : Parent ; Purchasedata : child I created a search form based on holder data. the search criteria (User input) is "Lastname". I want to show the search results based on lastname from holder data in mainform and relative purchasedata from purchasedata to the subform. I have to commands called search and resetsearch. Search is working. For resetsearch I...
0
2587
by: sillz | last post by:
On Apr 8, 2:00 pm, sillz <beth.sto...@gmail.comwrote: I never could get this to work. The oracle account tested fine. I ended up creating a new account in Windows with the right permissions and this solved the problem.
6
4670
by: Jajjo | last post by:
Hey there, I'm experimenting with GetCursorPos instead of "static_cast"ing the LOWORD and HIWORD params. This is because I want to work with positions relative to teh screen. Myt question is this: Does the POINT object get updated when the mouse is outside of the edge of my program? If not, how do I constantly update the cursor position regardless of whether it's inside the edges of my program? Thanks guys/gals. -Jajjo
0
9464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.