How to turn off pc via windows API?

前端 未结 6 740
南旧
南旧 2021-01-03 11:03

I never programmed a winapi so i have a little problem here .

I need turn off my pc from my application .

I found this example link text the

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-03 11:36

    This is a bit much for the comments on Daniel's answer, so I'll put it here.

    It looks like your main issue at this point is that your process isn't running with the priveleges required to perform a system shutdown.

    The docs for ExitWindowsEx contain this line:

    To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege. For more information, see Running with Special Privileges.

    They also have some example code. In a pinch, you can just copy that.

提交回复
热议问题