Using C # Write the program

xiaoxiao2021-03-06  21

Back to the bedroom every night, sometimes you want to use the laboratory machine to download the upload point, but if the machine has been driving, it will reduce life. So write an automatic shutdown program, automatically shut down the machine at 12 o'clock every day. This program is easily tested under Win2k. It is easy to say that it is still possible to shut down normally even if many other programs are running.

The principle is very simple, and it is not available on the code. That is to call an API to turn off the computer, you need to declare it first.

[DLLIMPORT ("User32.dll", Exactspelling = true, setLastError = true)]

INTERNAL Static Extern Bool EXITWINDOWSEX (INT FLG, INT REA);

Then use a Timer control to determine if the current time is equal to the selected shutdown time, equal to executing EXITWINDOWSEX, OK.

But one thing to pay very attention is that after calling the Function API function, you must immediately stop TIMER Tick events. Let Timer1.enabled = false; if otherwise, you will call EXITWINDOWSEX multiple times. As a result, it is a computer to give you a blue interface, and there is nothing on the interface. Do not believe you try it. Ha ha.

转载请注明原文地址:https://www.9cbs.com/read-45664.html

New Post(0)