Link to home
Start Free TrialLog in
Avatar of RGuillermo
RGuillermoFlag for United States of America

asked on

Turning off just the screen of a laptop or desktop pc programatically

Hello experts,
Is it posible to turn off the screen programatically using visual basic 2013, ? if so can you provide an example?
Regards,
ASKER CERTIFIED SOLUTION
Avatar of Duy Pham
Duy Pham
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
If you are trying to achieve this via a cross browser web application, this is not possible. In you want to create website that is limited to Internet Explorer, you can get your target done by using ActiveX.
However, even you manage to get this done, that will not work on Other Browsers and Operating systems.
Sorry that I didn't notice about Visual Basic 2013 in your question, here is an equivalent code in VB.NET 2013
' use SendMessage for synchronous call, wait until message is processed
Declare Auto Function SendMessage Lib "user32" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
' use PostMessage for asynchronous call, don't want to wait until message is processed
Declare Auto Function PostMessage Lib "user32" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

' turn off monitor
SendMessage(-1 /* HWND_BROADCAST */,  &H112 /* WM_SYSCOMMAND */, &HF170 /* SC_MONITORPOWER */, 2 /* MONITOR_OFF */)
' or
PostMessage(-1 /* HWND_BROADCAST */,  &H112  /* WM_SYSCOMMAND */, &HF170 /* SC_MONITORPOWER */, 2 /* MONITOR_OFF */)

Open in new window


P.S.: Sorry that I haven't got the time to test the VB.NET, just quickly translated it on-the-fly.
You could use this:
https://www.experts-exchange.com/questions/28686918/vb-2013-command-to-turn-off-the-screen-but-not-the-pc.html

ps.  If you close a question of by accepting something that turns out NOT to work, just click the request a tention button rather rather than opening a new question.
Avatar of RGuillermo

ASKER

Thanks to all Experts!