Guten Morgen Maywood.
Ja habe den Code umgeändert und auch die abfrage, die Prüft welches OS man hat rausgenommen. Weis ja schon das bei mir WIN2K läuft
Hier mal der Code.
Public Class Form1
Inherits System.Windows.Forms.Form
Private Declare Function LockWorkstation Lib "User32.dll" Alias _
"LockWorkStation" () As Long
Private Declare Function SwitchDesktop Lib "user32" (ByVal hDesktop As _
Long) As Long
Private Declare Function OpenDesktop Lib "user32.dll" Alias "OpenDesktopA" ( _
ByVal lpszDesktop As String, ByVal dwFlags As Long, ByVal fInherit As _
Boolean, ByVal dwDesiredAccess As Long) As Long
Private Declare Function CloseDesktop Lib "user32.dll" (ByVal hDesktop As _
Long) As Long
Private Declare Function SystemParametersInfo Lib "user32.dll" Alias _
"SystemParametersInfoA" (ByVal uiAction As Long, ByVal uiParam As Long, _
ByRef pvParam As Long, ByVal fWinIni As Long) As Long
Private Const SPI_GETSCREENSAVERRUNNING As Long = 114&
Private Const DESKTOP_READOBJECTS As Long = &H1
Private Const DESKTOP_CREATEWINDOW As Long = &H2
Private Const DESKTOP_CREATEMENU As Long = &H4
Private Const DESKTOP_HOOKCONTROL As Long = &H8
Private Const DESKTOP_JOURNALRECORD As Long = &H10
Private Const DESKTOP_JOURNALPLAYBACK As Long = &H20
Private Const DESKTOP_ENUMERATE As Long = &H40
Private Const DESKTOP_WRITEOBJECTS As Long = &H80
Private Const DESKTOP_SWITCHDESKTOP As Long = &H100
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles cmdStopMonitoring.Click
Me.Timer1.Enabled = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles cmdJustMonitor.Click
Me.Timer1.Enabled = False
Me.Timer1.Interval = 3000
Me.Timer1.Enabled = True
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles cmdLockWorkstation.Click
LockWorkstation()
Me.Timer1.Enabled = False
Me.Timer1.Interval = 3000
Me.Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Timer1.Tick
Dim p_lngHwnd As Long
Dim p_lngRtn As Long
Dim p_lngErr As Long
Dim p_lngScreenSaver As Long
Dim p_blnIsScreenSaver As Boolean
' ---------------------------------------
' W2K+ -- Will determine if screen saver
' is running whether or not the
' "Password Protected" box is checked
' ---------------------------------------
p_lngRtn = SystemParametersInfo(uiAction:=SPI_GETSCREENSAVERRUNNING, _
uiParam:=0&, pvParam:=p_lngScreenSaver, fWinIni:=0&)
If p_lngRtn = 0 Then
Debug.Print(Err.LastDllError)
Else
p_blnIsScreenSaver = CBool(p_lngScreenSaver)
End If
' ------------------------------------------
' If screen saver is *not* running, then
' check for locked workstation
' ------------------------------------------
If p_blnIsScreenSaver = True Then
Debug.Print("Screen saver is running on W2K+")
Else
p_lngHwnd = OpenDesktop("default", 0, False, DESKTOP_SWITCHDESKTOP)
If p_lngHwnd = 0 Then
Label2.Text = ("Error with OpenDesktop: " & Err.LastDllError)
Else
p_lngRtn = SwitchDesktop(p_lngHwnd)
p_lngErr = Err.LastDllError
If p_lngRtn = 0 Then
If p_lngErr = 0 Then
Label2.Text = ("Desktop is locked: " & Err.LastDllError)
Else
Label2.Text = ("Error with SwitchDesktop: " & _
Err.LastDllError)
End If
Else
Label1.Text = ("Not locked!" & p_lngErr)
End If
p_lngHwnd = CloseDesktop(p_lngHwnd)
End If
End If
End Sub
End ClassGruß
Ralf |