Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shutdown PC

Status
Not open for further replies.

johnisotank

Technical User
Aug 8, 2008
258
GB
Hi All,

I am trying to make a program which will shutdown a PC.

I have the following code:

Code:
Call Shell("Shutdown /s") 'to shutdown

This does set off the shutdown process but if there are any programs running then some of them just hang and the system never actually shuts down.

Is there a switch to say "Force all programs to close"?

Thanks
John
 
Found it now,

Call Shell("Shutdown -s -f") 'to shutdown

F switch to force shutdown.

Thanks anyway

John
 
Back again! this question ties in with the previous one so thought best not to raise another thread..

I have some code that puts my monitor into sleep mode but I wondered if there was a way to actually turn the monitor off- i.e user must physically press the button to turn it back on again (a simple mouse move or keyboard stroke should not re-awaken it)

Code:
Public Class Form1
    Public Declare Function PostMessage Lib "user32.dll" _
Alias "PostMessageA" _
(ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32) As Int32

    Public Const WM_SYSCOMMAND = &H112&
    Public Const SC_MONITORPOWER = &HF170& ' (-1)=On; 1=stdby; 2=Off

'Button to turn off monitor
 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        PostMessage(Me.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2&)
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top