473,480 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Tell if lock screen is up!

RAJSPY
18 New Member
Hi all,

I want to start a program through a SMS job. Only, the program must wait until the user is logged on. so far so good realizing this with SMS. The problem is that our company has a screen lock within 10 minutes (company policy) if the program starts with the lock screen on I want to wait until the user unlocks the desktop. Is there some variable that records if the screen is locked?

Thanks in advanced,
Aug 11 '08 #1
5 2085
Plater
7,872 Recognized Expert Expert
I wish I were more help on this, but yes I think there was a way to get this information. I saw it on here a long time ago. Don't remember how or where though, sorry.
Aug 11 '08 #2
RAJSPY
18 New Member
Yeah i have seen one with session switch hooks. But that doesn't give a answer back if the screen is already locked.

Anybody else has a clue??

Thanx
Aug 13 '08 #3
Plater
7,872 Recognized Expert Expert
I am thinking somewhere burried in WMI you can get the current user state, which should include if screen is locked or not.
Aug 13 '08 #4
KodeKrazy
32 New Member
Try this. You may have to tweak it a bit as I converted it to .NET from some old VB6 snippet I used previously in an app that required it. Also, you may get an error on the "Switch Screen" part, if you do, it means the desktop is locked.

KK

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Class Form1
  3. Inherits System.Windows.Forms.Form
  4. Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  5. Call Test()
  6. End Sub
  7. End Class
  8.  
  9. Module Module1
  10. Private Declare Function OpenDesktop Lib "user32" Alias "OpenDesktopA" (ByVal lpszDesktop As String, ByVal dwFlags As Integer, ByVal fInherit As Integer, ByVal dwDesiredAccess As Integer) As Integer
  11. Private Declare Function SwitchDesktop Lib "user32" (ByVal hDesktop As Integer) As Integer
  12. Private Declare Function CloseDesktop Lib "user32" (ByVal hDesktop As Integer) As Integer
  13. Private Const DESKTOP_SWITCHDESKTOP As Integer = &H100
  14.  
  15. Public Sub Test()
  16. Dim p_lngHwnd As Integer
  17. Dim p_lngRtn As Integer
  18. Dim p_lngErr As Integer
  19.  
  20. p_lngHwnd = OpenDesktop(lpszDesktop:="Default", dwFlags:=0, fInherit:=False, dwDesiredAccess:=DESKTOP_SWITCHDESKTOP)
  21. If p_lngHwnd = 0 Then
  22. Debug.WriteLine("Err with OpenDesktop: " & Err.LastDllError)
  23. Else
  24. p_lngRtn = SwitchDesktop(hDesktop:=p_lngHwnd)
  25. p_lngErr = Err.LastDllError
  26.  
  27. If p_lngRtn = 0 Then
  28. If p_lngErr = 0 Then
  29. Debug.WriteLine("Desktop is locked: " & Err.LastDllError)
  30. Else
  31. Debug.WriteLine("Error with SwitchDesktop: " & Err.LastDllError)
  32. End If
  33. Else
  34. Debug.WriteLine("Not Locked")
  35. End If
  36. p_lngHwnd = CloseDesktop(p_lngHwnd)
  37. End If
  38. End Sub
  39. End Module
  40.  
  41.  
Aug 13 '08 #5
RAJSPY
18 New Member
Thanx it works perfect.

I had some code like this but the syntaxes where not good. And I was just searching for some answers and you dropped them here Thanx again.

I've turned it to this C# code:
Expand|Select|Wrap|Line Numbers
  1. [DllImport("user32", EntryPoint ="OpenDesktopA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
  2. private static extern int OpenDesktopA(String lpszDesktop, int dwFlags, int fInherit, int dwDesiredAccess);
  3.  
  4. public int OpenDesktop(String lpszDesktop,int dwFlags,int fInherit,int dwDesiredAccess)
  5. {
  6.     return OpenDesktopA(lpszDesktop,dwFlags,fInherit,dwDesiredAccess);
  7. }
  8.  
  9. [DllImport("user32", EntryPoint ="SwitchDesktop", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
  10. private static extern int SwitchDesktop(int hDesktop);
  11.  
  12. public int Switch_Desktop(int hDesktop)
  13. {
  14.   return SwitchDesktop(hDesktop);
  15. }
  16.  
  17. [DllImport("user32", EntryPoint = "CloseDesktop", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
  18. private static extern int CloseDesktop(int hDesktop);
  19.  
  20. public int Close_Desktop(int hDesktop)
  21. {
  22.    return CloseDesktop(hDesktop);
  23. }
  24.  
  25. And in your application:
  26. private const int DESKTOP_SWITCHDESKTOP = 0x100;
  27.  
  28. int p_lngHwnd;
  29. int p_lngRtn;
  30. try
  31. {            
  32.   p_lngHwnd = _ModalDesktop.OpenDesktop("default", 0, 0, DESKTOP_SWITCHDESKTOP);
  33.  p_lngRtn = _ModalDesktop.Switch_Desktop(p_lngHwnd);
  34.  if (p_lngRtn == 0) 
  35. {
  36.   //Do somthing here .....
  37. }
  38.  p_lngHwnd = _ModalDesktop.Close_Desktop(p_lngHwnd); 
  39. }
  40. catch(Exception ex)
  41. {
  42.   //Some code here .....
  43. }
Aug 18 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
20886
by: Richard Holliingsworth | last post by:
Hello: I have an Access 2K form I built from a SQL Server 7.0 view. I want to lock certain fields in the database from users so they can see them on the views and forms, but NOT be able to edit...
1
1539
by: Jurgen Haan | last post by:
Hi. We just experienced an odd phenomenon in Control Center. One of my colleagues just performed a browse on a table and accidentally changed a value in the resultset. He didn't press OK or...
2
2802
by: Janice | last post by:
How to obtain the lock status of a file held by other process? If I read the file that is locked by other process, the read would return -1. If the file is locked by other process, how to put the...
0
1187
by: Jennyfer J Barco | last post by:
Hello I have a datagrid and I'm showing many records. I need 2 things: I need that everytime they scroll down, the header stays lock so the user can see it all the time. I need to scroll only the...
3
1695
by: Bryan Shaw | last post by:
I do not want my users to be able to copy and paiste anything on these web pages, which will be on an internal web site. Is there a way to prevent the printing of a web page? Is there a way to...
8
3345
by: Joe Weinstein | last post by:
Hi. create table joe(c1 integer not null, c2 integer not null) Two sessions: Session 1: BEGIN TRAN insert into joe (c1,c2) values (1,2)
2
3751
by: E C H (He of too much code) | last post by:
I am very weak in VB.NET, I am using VB.NET 2k5 Express. I have only created one program, and heck it was my first ;-) (URL below if it matters). I am trying to create a program that stays...
94
30176
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock...
26
4402
werks
by: werks | last post by:
Hi there programmers does does anyone know how to lock the screen? i mean when you click the Lock Button everything in the desktop will be LOCK unless you input the correct password to unlock it..pls...
0
7055
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
6920
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...
0
7106
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...
1
6760
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
7022
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
5365
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,...
1
4799
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...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.