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("SeShutdownPrivilege");
if (force)
how = how | EWX_FORCE;
if (ExitWindowsEx(how, 0) == 0)
throw new PrivilegeException(FormatError(Marshal.GetLastWin3 2Error()));
}
/// <summary>
/// Tries to enable the specified privilege.
/// </summary>
/// <param name="privilege">The privilege to enable.</param>
/// <exception cref="PrivilegeException">There was an error while
requesting a required privilege.</exception>
/// <remarks>Thanks to Michael S. Muegel for notifying us about a bug in
this code.</remarks>
protected static void EnableToken(string privilege ) {
if (Environment.OSVersion.Platform != PlatformID.Win32NT ||
!CheckEntryPoint("advapi32.dll", "AdjustTokenPrivileges"))
return;
IntPtr tokenHandle = IntPtr.Zero;
LUID privilegeLUID = new LUID();
TOKEN_PRIVILEGES newPrivileges = new TOKEN_PRIVILEGES();
TOKEN_PRIVILEGES tokenPrivileges ;
if (OpenProcessToken(Process.GetCurrentProcess().Hand le,
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref tokenHandle) == 0)
throw new PrivilegeException(FormatError(Marshal.GetLastWin3 2Error()));
if (LookupPrivilegeValue("", privilege, ref privilegeLUID) == 0)
throw new PrivilegeException(FormatError(Marshal.GetLastWin3 2Error()));
tokenPrivileges.PrivilegeCount = 1;
tokenPrivileges.Privileges.Attributes = SE_PRIVILEGE_ENABLED;
tokenPrivileges.Privileges.pLuid = privilegeLUID;
int size = 4;
if (AdjustTokenPrivileges(tokenHandle, 0, ref tokenPrivileges, 4 + (12 *
tokenPrivileges.PrivilegeCount), ref newPrivileges, ref size) == 0)
throw new PrivilegeException(FormatError(Marshal.GetLastWin3 2Error()));
}
I suggest you may and this class in your project and set break point in the
method of EnableToken(string 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(string 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.