Hello,
I just check the source code of Windows Controller class, and I found
following code:
protected static void ExitWindows(int how , bool force) {
EnableToken("Se ShutdownPrivile ge");
if (force)
how = how | EWX_FORCE;
if (ExitWindowsEx( how, 0) == 0)
throw new PrivilegeExcept ion(FormatError (Marshal.GetLas tWin32Error())) ;
}
/// <summary>
/// Tries to enable the specified privilege.
/// </summary>
/// <param name="privilege ">The privilege to enable.</param>
/// <exception cref="Privilege Exception">Ther e was an error while
requesting a required privilege.</exception>
/// <remarks>Than ks to Michael S. Muegel for notifying us about a bug in
this code.</remarks>
protected static void EnableToken(str ing privilege ) {
if (Environment.OS Version.Platfor m != PlatformID.Win3 2NT ||
!CheckEntryPoin t("advapi32.dll ", "AdjustTokenPri vileges"))
return;
IntPtr tokenHandle = IntPtr.Zero;
LUID privilegeLUID = new LUID();
TOKEN_PRIVILEGE S newPrivileges = new TOKEN_PRIVILEGE S();
TOKEN_PRIVILEGE S tokenPrivileges ;
if (OpenProcessTok en(Process.GetC urrentProcess() .Handle,
TOKEN_ADJUST_PR IVILEGES | TOKEN_QUERY, ref tokenHandle) == 0)
throw new PrivilegeExcept ion(FormatError (Marshal.GetLas tWin32Error())) ;
if (LookupPrivileg eValue("", privilege, ref privilegeLUID) == 0)
throw new PrivilegeExcept ion(FormatError (Marshal.GetLas tWin32Error())) ;
tokenPrivileges .PrivilegeCount = 1;
tokenPrivileges .Privileges.Att ributes = SE_PRIVILEGE_EN ABLED;
tokenPrivileges .Privileges.pLu id = privilegeLUID;
int size = 4;
if (AdjustTokenPri vileges(tokenHa ndle, 0, ref tokenPrivileges , 4 + (12 *
tokenPrivileges .PrivilegeCount ), ref newPrivileges, ref size) == 0)
throw new PrivilegeExcept ion(FormatError (Marshal.GetLas tWin32Error())) ;
}
I suggest you may and this class in your project and set break point in the
method of EnableToken(str ing privilege ). I suspect the problem occur here.
So, may run the application in debug mode, or add and some code to record
log information in the function, to check if there is any problem when
running the application in the real environment, for example, are all the
functions call successful in the method of EnableToken(str ing privilege )?
Sincerely,
Luke Zhang
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.