A1VBCode Forums

Why can't shutdown, restart or unlock!?


http://www.a1vbcode.com/vbforums/Topic16882.aspx

By Eric - 2/17/2006

Can't restart,shutdown or unlock pc The code is right but still can't function. Please modified my code. I have many sampels. Please help me ......  i used this command

Case "Reboot"
ExitWindowsEx (EWX_FORCE Or EWX_REBOOT), 0&


Case "Shutdown"
ExitWindowsEx (EWX_FORCE Or EWX_SHUTDOWN), 0&

Below is my full program:-


Private Sub sckControlPanel_DataArrival(ByVal bytesTotal As Long)
Dim Command As String, txtData As String
Dim Position As Integer

On Error Resume Next
sckControlPanel.GetData txtData

Position = InStr(1, txtData, "#")
Command = Left(txtData, Position - 1)
txtData = Mid(txtData, Position + 1)

Select Case Command

Case "ScreenSaver"
RunScreenSaver
Case "CDDoor"
If txtData = "Open" Then
OpenCDDoor
Else
CloseCDDoor
End If
Case "LockSystem"
SystemParametersInfo SPI_SCREENSAVERRUNNING, _
1&, Null, SPIF_UPDATEINIFILE
LockForm.Show
Case "UnLockSystem"
Call UnLock_Close
Case "Logoff"
ExitWindowsEx (EWX_FORCE Or EWX_LOGOFF), 0&
Case "Reboot"
ExitWindowsEx (EWX_FORCE Or EWX_REBOOT), 0&
Case "Shutdown"
ExitWindowsEx (EWX_FORCE Or EWX_SHUTDOWN), 0&
Case "GetUserName"
txtData = GetUser()
sckControlPanel.SendData "GetUserName#" & txtData
Case "GetTickCount"
txtData = GetLoginTime
sckControlPanel.SendData "GetTickCount#" & txtData
Case "SystemInfo"
txtData = "SystemInfo#" & SystemInfo()
sckControlPanel.SendData txtData
Case "CrezyMouse"
Timer1.Enabled = True
Case "NormalMouse"
Timer1.Enabled = False
Case "Message"
MsgBox txtData, vbExclamation, "Windows Message"
Case "Date&Time"
Case "Mouse"
End Select
End Sub




LockForm

Option Explicit
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

'hides and shows the desktop
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

'swap the mouse buttons
Private Declare Function SwapMouseButton& Lib "user32" (ByVal bSwap As Long)

'enable and disable ctrl+alt+delete
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long

Private Const SPI_SCREENSAVERRUNNING = 97
Private Const HWND_TOPMOST = -1
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOOWNERZORDER = &H200 ' Don't do owner Z ordering

Private Sub Form_Load()
'when you lock the program...
'disables ctrl+alt+delete
'hides mouse
'swaps the mouse buttons
'hides taskbar
'hides desktop
Dim rtn As Long
Dim Ret As Long
Dim pOld As Boolean
Dim hWnd As Long
hWnd = FindWindowEx(0&, 0&, "Progman", vbNullString)
ShowWindow hWnd, 0
Ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, pOld, 0)
ShowCursor (False)
SwapMouseButton (True)
rtn = FindWindow("Shell_traywnd", "")
Call SetWindowPos(rtn, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
Me.Hide

SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, Screen.Width, _
Screen.Height, SWP_SHOWWINDOW Or SWP_NOOWNERZORDER
End Sub

Private Sub UnLock_Close()
'when you unlock the program...
'enables ctrl+alt+delete
'shows mouse
'unswaps the mouse buttons
'shows taskbar
'shows desktop
Dim hWnd As Long
Dim Ret As Integer
Dim pOld As Boolean
Dim rtn As Long
rtn = FindWindow("Shell_traywnd", "")
Call SetWindowPos(rtn, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)
hWnd = FindWindowEx(0&, 0&, "Progman", vbNullString)
ShowWindow hWnd, 5
Ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, pOld, 0)
ShowCursor (True)
SwapMouseButton (False)
Me.Hide
End Sub


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

SystemParametersInfo SPI_SCREENSAVERRUNNING, 0&, Null, _
SPIF_UPDATEINIFILE
End Sub

The coding are part of the coding in the client program. I have try to restart and shutdown but seems like nothing is happening. I used this

Private Sub tutup_Click() 'To shutdown the computer

sckControlPanel.SendData "Shutdown#"

End Sub

Private Sub restart_Click() 'To restart the computer

sckControlPanel.SendData "Reboot#"

End Sub

I have put in the command to force the window to restart,shutdown but nothing seems to be happening.Also how do i unlock a computer? One more things how do we disable Alt+Crl+Del. The above coding is not that good. Please advise.


By Mobius - 4/13/2006

You could use a shell. For example:

Shell("shutdown -l")