Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

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?
0
ako74
Asked:
ako74
  • 3
1 Solution
 
Ethen_huntCommented:
Well this might help

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
0
 
nffvrxqgrcfqvvcCommented:
'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$(Twaarde))))
   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
0
 
nffvrxqgrcfqvvcCommented:
' Here is how you detect if the user is logged on or not, and I also added how you shutdown the computer if the user is inactive...

'''''''''''
'Add the following code to a module .bas
''''''''''''''

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 Declare Function RtlAdjustPrivilege& Lib "ntdll" (ByVal Privilege&, ByVal NewValue&, ByVal NewThread&, OldValue&)
Public Declare Function NtShutdownSystem& Lib "ntdll" (ByVal ShutdownAction&)
 
    Public Const SE_SHUTDOWN_PRIVILEGE& = 19
 
    Public Const shutdown& = 0
    Public Const RESTART& = 1
    Public Const POWEROFF& = 2


Sub ShutDownPC()
    RtlAdjustPrivilege SE_SHUTDOWN_PRIVILEGE, 1, 0, 0 ' // Give us Shutdown Privileges
    NtShutdownSystem shutdown ' // Take System Down
End Sub
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$(Twaarde))))
   If InputCheck Then
    Exit For
    End If
 Next
End Function





'''''''''
'Add 1 TIMER
'Add the following code to a FORM
'''''''''''


Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 30000 'when you want to check

End Sub

Private Sub Timer1_Timer()

If InputCheck = True Then
Debug.Print "user is logged on and active"

Else

If InputCheck = False Then
Debug.Print "no logged on user"
Call ShutDownPC 'shutdowns computer
doEvents
End If
End If

End Sub
0
 
nffvrxqgrcfqvvcCommented:
'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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now