Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've already got the code written but for some reason, when i click the
button, nothing occurs. Here is the code.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

[DllImport("advapi32.dll",EntryPoint="InitiateSyste mShutdown")]
public static extern bool InitiateSystemShutdownA(string
lpMachineName, string lpMessage, int dwTimeout, int bForceAppsClosed, int
bRebootAfterShutdown);

private void button1_Click(object sender, System.EventArgs e)
{
InitiateSystemShutdownA(null,null, 30, 1, 1);
}


It compiles fine, but when i click button1, nothing happens. Any ideas?
Posted
Updated 9-Apr-15 0:59am
v2

1 solution

Do you have the proper rights?
 
Share this answer
 
Comments
nishac189 10-Apr-15 0:55am    
yes,I have proper rights
there is any other API in C# for restart PC
nishac189 10-Apr-15 0:58am    
I got Getlasterror is ACCESS DENIED

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900