The source codes seem like working only for Window OS 32bit, but 64 bit works perfectly The only problem is "privilege" That's the problem. we must run this application as an administration
01.
ManagementBaseObject mboShutdown =
null
;
02.
ManagementClass mcWin32 =
new
ManagementClass(
"Win32_OperatingSystem"
);
03.
mcWin32.Get();
04.
mcWin32.Scope.Options.EnablePrivileges =
true
;
// get security privileges
05.
ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters(
"Win32Shutdown"
);
06.
mboShutdownParams[
"Flags"
] =
"1"
;
07.
mboShutdownParams[
"Reserved"
] =
"0"
;
08.
foreach
(ManagementObject manObj
in
mcWin32.GetInstances())
09.
{
10.
mboShutdown = manObj.InvokeMethod(
"Win32Shutdown"
, mboShutdownParams,
null
);
11.
}
12.
break
;
'Programming > C#' 카테고리의 다른 글
Palindromic number source (0) | 2011.10.19 |
---|