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,
RGuillermoProject ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Duy PhamFreelance IT ConsultantCommented:
You might try to use Windows API functions SendMessage or PostMessage:
// use SendMessage for synchronous call, wait until message is processed
[DllImport("user32.dll")]
static extern IntPtr SendMessage(int hWnd, int msg, int wParam, int lParam);
// use PostMessage for asynchronous call, don't want to wait until message is processed
[DllImport("user32.dll")]
static extern IntPtr PostMessage(int hWnd, int msg, int wParam, int lParam);

// turn off monitor
SendMessage(-1 /* HWND_BROADCAST */,  0x112 /* WM_SYSCOMMAND */, 0xF170 /* SC_MONITORPOWER */, 2 /* MONITOR_OFF */);
// or
PostMessage(-1 /* HWND_BROADCAST */,  0x112 /* WM_SYSCOMMAND */, 0xF170 /* SC_MONITORPOWER */, 2 /* MONITOR_OFF */);

Open in new window


More details about WM_SYSCOMMAND message can be found here: https://msdn.microsoft.com/en-us/library/ms646360(VS.85).aspx.

Hope it helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John BhattManagerCommented:
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.
0
Duy PhamFreelance IT ConsultantCommented:
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.
0
AndyAinscowFreelance programmer / ConsultantCommented:
You could use this:
http://www.experts-exchange.com/Programming/Languages/.NET/Q_28686918.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.
0
RGuillermoProject ManagerAuthor Commented:
Thanks to all Experts!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.