ako74
asked on
Reboot a computer if nobody is logged in
I want to reboot a lof of computers (130) from my server, but only those that is not logged on to. I have used the shutdown.exe command, but this takes down the computer even if a user is logged on. Is there a check in VB that checks if a user is logged in?
'Add this to a module declerations
'''''''''''''''''''''
Option Explicit
Private Declare Sub GetCursorPos Lib "user32.dll" (lpPoint As POINTAPI)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Type POINTAPI
X As Integer
Y As Integer
End Type
Private posOld As POINTAPI
Private posNew As POINTAPI
Public Function InputCheck() As Boolean
Dim i As Integer
Call GetCursorPos(posNew)
If ((posNew.X <> posOld.X) Or (posNew.Y <> posOld.Y)) Then
posOld = posNew
InputCheck = True
Exit Function
End If
Dim Twaarde As Integer
For Twaarde = 32 To 126
InputCheck = CBool(GetAsyncKeyState(Asc (Chr$(Twaa rde))))
If InputCheck Then
Exit For
End If
Next
End Function
ADD 1 TIMER
'Add this to form_declerations
'''''''''''''''''''''''
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 30000 'when you want to check
End Sub
Private Sub Timer1_Timer()
Debug.Print
If InputCheck = True Then
Debug.Print "user is logged on and active"
Else
If InputCheck = False Then
Debug.Print "no logged on user"
'reboot system code here
End If
End If
End Sub
'''''''''''''''''''''
Option Explicit
Private Declare Sub GetCursorPos Lib "user32.dll" (lpPoint As POINTAPI)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Type POINTAPI
X As Integer
Y As Integer
End Type
Private posOld As POINTAPI
Private posNew As POINTAPI
Public Function InputCheck() As Boolean
Dim i As Integer
Call GetCursorPos(posNew)
If ((posNew.X <> posOld.X) Or (posNew.Y <> posOld.Y)) Then
posOld = posNew
InputCheck = True
Exit Function
End If
Dim Twaarde As Integer
For Twaarde = 32 To 126
InputCheck = CBool(GetAsyncKeyState(Asc
If InputCheck Then
Exit For
End If
Next
End Function
ADD 1 TIMER
'Add this to form_declerations
'''''''''''''''''''''''
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 30000 'when you want to check
End Sub
Private Sub Timer1_Timer()
Debug.Print
If InputCheck = True Then
Debug.Print "user is logged on and active"
Else
If InputCheck = False Then
Debug.Print "no logged on user"
'reboot system code here
End If
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
'Just to remind you that you might not want to check every 30 seconds, instead you might want to check every 5 - 10 minutes, just like a screen saver.
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=55828&lngWId=1
it is a link to a project that you can dowload and i bet with a few ulterations of the code you can come up with
the one you want i can't check the code since i don't have a network nor 2 PC :(
so if it comes handy do let me know :D
hopefully you will find your answer