Click here to Skip to main content
15,887,746 members
Home / Discussions / C#
   

C#

 
GeneralSecurity a la Palladium ¿? ;) Pin
antoine@orchus-tech27-Jul-03 12:34
antoine@orchus-tech27-Jul-03 12:34 
GeneralRe: Security a la Palladium ¿? ;) Pin
Alex Korchemniy27-Jul-03 18:13
Alex Korchemniy27-Jul-03 18:13 
GeneralRe: Security a la Palladium ¿? ;) Pin
StealthyMark27-Jul-03 23:27
StealthyMark27-Jul-03 23:27 
GeneralListboxes Pin
StorBruze27-Jul-03 10:31
StorBruze27-Jul-03 10:31 
GeneralRe: Listboxes Pin
Alex Korchemniy27-Jul-03 18:20
Alex Korchemniy27-Jul-03 18:20 
QuestionHow to restart windows from c# code? Pin
Member 9627-Jul-03 9:17
Member 9627-Jul-03 9:17 
AnswerRe: How to restart windows from c# code? Pin
Mazdak27-Jul-03 9:48
Mazdak27-Jul-03 9:48 
AnswerRe: How to restart windows from c# code? Pin
Erick Sgarbi27-Jul-03 15:10
Erick Sgarbi27-Jul-03 15:10 
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}

[DllImport("kernel32.dll", ExactSpelling=true) ]
internal static extern IntPtr GetCurrentProcess();

[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool OpenProcessToken( IntPtr h, int acc, ref IntPtr phtok );

[DllImport("advapi32.dll", SetLastError=true) ]
internal static extern bool LookupPrivilegeValue( string host, string name, ref long pluid );

[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool AdjustTokenPrivileges( IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen );

[DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool ExitWindowsEx( int flg, int rea );

internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
internal const int EWX_LOGOFF = 0x00000000;
internal const int EWX_SHUTDOWN = 0x00000001;
internal const int EWX_REBOOT = 0x00000002;
internal const int EWX_FORCE = 0x00000004;
internal const int EWX_POWEROFF = 0x00000008;
internal const int EWX_FORCEIFHUNG = 0x00000010;

private void DoExitWin( int flg )
{
bool ok;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok );
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid );
ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero );
ok = ExitWindowsEx( flg, 0 );
}

// usage:
DoExitWin( EWX_POWEROFF );

Cheers
ES
QuestionAdvanced Log Capabilities ? Pin
Andres Manggini27-Jul-03 8:51
Andres Manggini27-Jul-03 8:51 
GeneralTabbing to next edit box using Enter key Pin
IrishSonic27-Jul-03 8:23
IrishSonic27-Jul-03 8:23 
GeneralRe: Tabbing to next edit box using Enter key Pin
kharr102727-Jul-03 13:13
kharr102727-Jul-03 13:13 
GeneralRe: Tabbing to next edit box using Enter key Pin
dynamic27-Jul-03 13:36
dynamic27-Jul-03 13:36 
GeneralRe: Tabbing to next edit box using Enter key Pin
eggie527-Jul-03 19:07
eggie527-Jul-03 19:07 
GeneralEmbedded Resources Pin
Brian Delahunty27-Jul-03 4:35
Brian Delahunty27-Jul-03 4:35 
GeneralRe: Embedded Resources Pin
leppie27-Jul-03 5:23
leppie27-Jul-03 5:23 
GeneralRe: Embedded Resources Pin
Brian Delahunty27-Jul-03 5:29
Brian Delahunty27-Jul-03 5:29 
GeneralRe: Embedded Resources Pin
leppie27-Jul-03 5:35
leppie27-Jul-03 5:35 
GeneralRe: Embedded Resources Pin
Nick Parker27-Jul-03 18:22
protectorNick Parker27-Jul-03 18:22 
QuestionRelease memory quickly? Pin
novachen26-Jul-03 23:38
novachen26-Jul-03 23:38 
AnswerRe: Release memory quickly? Pin
leppie27-Jul-03 3:14
leppie27-Jul-03 3:14 
GeneralAlgorithm needed Pin
albean26-Jul-03 15:02
albean26-Jul-03 15:02 
GeneralRe: Algorithm needed Pin
Anonymous26-Jul-03 17:00
Anonymous26-Jul-03 17:00 
GeneralRe: Algorithm needed Pin
Jim Stewart26-Jul-03 17:01
Jim Stewart26-Jul-03 17:01 
GeneralRe: Algorithm needed - Thanks! Pin
albean26-Jul-03 17:28
albean26-Jul-03 17:28 
GeneralRe: Annoying Properties Pin
albean26-Jul-03 14:57
albean26-Jul-03 14:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.