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,
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.
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
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.
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 -
-
Public Class Form1
-
Inherits System.Windows.Forms.Form
-
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
-
Call Test()
-
End Sub
-
End Class
-
-
Module Module1
-
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
-
Private Declare Function SwitchDesktop Lib "user32" (ByVal hDesktop As Integer) As Integer
-
Private Declare Function CloseDesktop Lib "user32" (ByVal hDesktop As Integer) As Integer
-
Private Const DESKTOP_SWITCHDESKTOP As Integer = &H100
-
-
Public Sub Test()
-
Dim p_lngHwnd As Integer
-
Dim p_lngRtn As Integer
-
Dim p_lngErr As Integer
-
-
p_lngHwnd = OpenDesktop(lpszDesktop:="Default", dwFlags:=0, fInherit:=False, dwDesiredAccess:=DESKTOP_SWITCHDESKTOP)
-
If p_lngHwnd = 0 Then
-
Debug.WriteLine("Err with OpenDesktop: " & Err.LastDllError)
-
Else
-
p_lngRtn = SwitchDesktop(hDesktop:=p_lngHwnd)
-
p_lngErr = Err.LastDllError
-
-
If p_lngRtn = 0 Then
-
If p_lngErr = 0 Then
-
Debug.WriteLine("Desktop is locked: " & Err.LastDllError)
-
Else
-
Debug.WriteLine("Error with SwitchDesktop: " & Err.LastDllError)
-
End If
-
Else
-
Debug.WriteLine("Not Locked")
-
End If
-
p_lngHwnd = CloseDesktop(p_lngHwnd)
-
End If
-
End Sub
-
End Module
-
-
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: -
[DllImport("user32", EntryPoint ="OpenDesktopA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
-
private static extern int OpenDesktopA(String lpszDesktop, int dwFlags, int fInherit, int dwDesiredAccess);
-
-
public int OpenDesktop(String lpszDesktop,int dwFlags,int fInherit,int dwDesiredAccess)
-
{
-
return OpenDesktopA(lpszDesktop,dwFlags,fInherit,dwDesiredAccess);
-
}
-
-
[DllImport("user32", EntryPoint ="SwitchDesktop", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
-
private static extern int SwitchDesktop(int hDesktop);
-
-
public int Switch_Desktop(int hDesktop)
-
{
-
return SwitchDesktop(hDesktop);
-
}
-
-
[DllImport("user32", EntryPoint = "CloseDesktop", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
-
private static extern int CloseDesktop(int hDesktop);
-
-
public int Close_Desktop(int hDesktop)
-
{
-
return CloseDesktop(hDesktop);
-
}
-
-
And in your application:
-
private const int DESKTOP_SWITCHDESKTOP = 0x100;
-
-
int p_lngHwnd;
-
int p_lngRtn;
-
try
-
{
-
p_lngHwnd = _ModalDesktop.OpenDesktop("default", 0, 0, DESKTOP_SWITCHDESKTOP);
-
p_lngRtn = _ModalDesktop.Switch_Desktop(p_lngHwnd);
-
if (p_lngRtn == 0)
-
{
-
//Do somthing here .....
-
}
-
p_lngHwnd = _ModalDesktop.Close_Desktop(p_lngHwnd);
-
}
-
catch(Exception ex)
-
{
-
//Some code here .....
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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)
|
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...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |