PDA

View Full Version : خاموش کردن سیستم توسط Kernel32



Farshid007
سه شنبه 11 بهمن 1390, 18:47 عصر
سلام دوستان
خیلی وفت پیش یک دوست عزیز بهم یه کدی رو گفت که باید Process رو Start می کردی تو پارامتر هاش هم کلمه های Kernel32وuserو یکی از اینها هم .exe بودند که از System32 بالا می امود(البته واسه فایل های که تو سیستم 32 هستند نمی خواد ادرس کامل باشه) اخرش هم مثلا می دادی Shutdown خاموش می شد می دادی Log ofو... خیلی هم ساده بو فقط کافی بود اینجوری پروسس رو شروع کنی
یچی تو این مایه ها بود:

System.Diagnostics.Process.Start("Kernel32.dll",@"user32\Logoff");
اما هر چقدر که فکر کردم یادم نیومد که نیومد دنبالش هم رفتم اما باز هم نشد که نشد
از دوستان کسی هست که این کد رو بلد باشه؟
م+900√
=>مر30
=>مرسی

mohammad272005
پنج شنبه 13 بهمن 1390, 00:20 صبح
با سلام،
برای اینکار 3تا راه سراغ دارم. نمیدونم بیشتر هم باشه یا نه.

1- استفاده از API:
internal class Program
{
[DllImport("advapi32.dll")]
private static extern bool InitiateSystemShutdown(string MachineName, string Message, uint Timeout, bool AppsClosed, bool Restart);
[DllImport("kernel32.dll")]
private static extern uint GetLastError();
[DllImport("kernel32.dll")]
public static extern uint FormatMessage(uint Flags, IntPtr Source, uint MessageID, uint LanguageID, StringBuilder Buffer, uint Size, IntPtr Args);
private static void Main(string[] args)
{
var Buffer = new StringBuilder(512);
uint MessageLength = 0;
GetLastError();
if (!InitiateSystemShutdown(Environment.MachineName, "Just for test", 20000, false, false))
{
MessageLength = FormatMessage(0x00001000, IntPtr.Zero, GetLastError(), 0, Buffer, (uint)Buffer.Capacity, IntPtr.Zero);
if (MessageLength > 0)
{
var Error = Buffer.ToString();
Error = Error.Substring(0, Error.Length - 2);
Console.WriteLine(Error + " (" + GetLastError().ToString() + ")");
}
}
Console.ReadKey();
}
}

2- استفاده از خود NET.:
Application.SetSuspendState(PowerState.Suspend, false, false);
3- روش command:
Process.Start("Shutdown.exe", "-t 0 -f -s");
شاید دوستان روشهای دیگه هم داشته باشن