Click here to Skip to main content
15,888,070 members
Home / Discussions / C#
   

C#

 
GeneralRe: Am I missing something? Pin
Unsy21-Jan-10 7:45
Unsy21-Jan-10 7:45 
GeneralRe: Am I missing something? Pin
Som Shekhar21-Jan-10 7:48
Som Shekhar21-Jan-10 7:48 
GeneralRe: Am I missing something? Pin
Som Shekhar21-Jan-10 7:49
Som Shekhar21-Jan-10 7:49 
GeneralRe: Am I missing something? Pin
AspDotNetDev21-Jan-10 15:44
protectorAspDotNetDev21-Jan-10 15:44 
Questionsecurity init failure error in win32 dll's method when calling from C# (windows and web) application. Pin
sund7wells21-Jan-10 4:55
sund7wells21-Jan-10 4:55 
AnswerRe: security init failure error in win32 dll's method when calling from C# (windows and web) application. Pin
Dave Kreskowiak21-Jan-10 5:23
mveDave Kreskowiak21-Jan-10 5:23 
GeneralRe: security init failure error in win32 dll's method when calling from C# (windows and web) application. Pin
sund7wells21-Jan-10 22:01
sund7wells21-Jan-10 22:01 
QuestionAuto Shutdown by code c# Pin
nmhai8321-Jan-10 4:37
nmhai8321-Jan-10 4:37 
To Auto shutdown by c# I call function:
public void ShutDownComputer()
{
ManagementBaseObject outParameters = null;
ManagementClass sysOS = new ManagementClass("Win32_OperatingSystem");
sysOS.Get();
// enables required security privilege.
sysOS.Scope.Options.EnablePrivileges = true;
// get our in parameters
ManagementBaseObject inParameters = sysOS.GetMethodParameters("Win32Shutdown");
// pass the flag of 0 = System Shutdown
inParameters["Flags"] = "1";
inParameters["Reserved"] = "0";
foreach (ManagementObject manObj in sysOS.GetInstances())
{
outParameters = manObj.InvokeMethod("Win32Shutdown", inParameters, null);
}
}
Or call function DoExitWin(1) below:

[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);
}

Function can perform when application run in desktop, but when pc locked then it can't perform. Why can't? Who can help me? please. Or a way automatic log in from pc locked by c#.
Thanks any help!
AnswerRe: Auto Shutdown by code c# Pin
Covean21-Jan-10 5:30
Covean21-Jan-10 5:30 
GeneralRe: Auto Shutdown by code c# Pin
nmhai8328-Jan-10 21:11
nmhai8328-Jan-10 21:11 
Questionuse of a value in a form in another one Pin
naghoumeh1421-Jan-10 4:36
naghoumeh1421-Jan-10 4:36 
AnswerRe: use of a value in a form in another one Pin
OriginalGriff21-Jan-10 5:06
mveOriginalGriff21-Jan-10 5:06 
QuestionRe: use of a value in a form in another one Pin
sanforjackass21-Jan-10 5:23
sanforjackass21-Jan-10 5:23 
AnswerRe: use of a value in a form in another one Pin
naghoumeh1421-Jan-10 23:49
naghoumeh1421-Jan-10 23:49 
QuestionRe: use of a value in a form in another one Pin
sanforjackass22-Jan-10 0:07
sanforjackass22-Jan-10 0:07 
AnswerRe: use of a value in a form in another one Pin
naghoumeh1425-Jan-10 0:09
naghoumeh1425-Jan-10 0:09 
QuestionSuggestions on developing C# Application Pin
hariprasad_120421-Jan-10 4:15
hariprasad_120421-Jan-10 4:15 
AnswerRe: Suggestions on developing C# Application Pin
Dave Kreskowiak21-Jan-10 6:48
mveDave Kreskowiak21-Jan-10 6:48 
QuestionHow to Create UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;) Pin
bruze21-Jan-10 2:08
bruze21-Jan-10 2:08 
AnswerRe: How to Create UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;) Pin
Phil J Pearson21-Jan-10 2:22
Phil J Pearson21-Jan-10 2:22 
GeneralRe: How to Create UI AUTOMATION for OUTLOOK 2007 using C# .Net 3.0 (using System.Windows.Automation;) Pin
bruze21-Jan-10 2:24
bruze21-Jan-10 2:24 
QuestionManagement Scope in connection options Pin
vinothkumar_Dhakshinamoorthy21-Jan-10 1:40
vinothkumar_Dhakshinamoorthy21-Jan-10 1:40 
QuestionTutorial on developing custom\user control in c# Pin
matixsc21-Jan-10 1:08
professionalmatixsc21-Jan-10 1:08 
AnswerRe: Tutorial on developing custom\user control in c# Pin
N a v a n e e t h21-Jan-10 1:32
N a v a n e e t h21-Jan-10 1:32 
AnswerRe: Tutorial on developing custom\user control in c# Pin
Eddy Vluggen21-Jan-10 1:44
professionalEddy Vluggen21-Jan-10 1:44 

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.