Click here to Skip to main content
15,894,630 members
Home / Discussions / C#
   

C#

 
GeneralRe: problem in datagridview Pin
rah_sin28-Dec-08 23:02
professionalrah_sin28-Dec-08 23:02 
GeneralRe: problem in datagridview Pin
SreejithKumar M28-Dec-08 23:07
SreejithKumar M28-Dec-08 23:07 
QuestionHow to send shutdown-restart command with TCP/IP Pin
Member 465172928-Dec-08 22:31
Member 465172928-Dec-08 22:31 
AnswerRe: How to send shutdown-restart command with TCP/IP Pin
Dave Kreskowiak29-Dec-08 1:51
mveDave Kreskowiak29-Dec-08 1:51 
GeneralRe: How to send shutdown-restart command with TCP/IP Pin
Member 465172929-Dec-08 3:43
Member 465172929-Dec-08 3:43 
GeneralRe: How to send shutdown-restart command with TCP/IP Pin
Dave Kreskowiak29-Dec-08 3:50
mveDave Kreskowiak29-Dec-08 3:50 
GeneralRe: How to send shutdown-restart command with TCP/IP Pin
Member 465172929-Dec-08 4:57
Member 465172929-Dec-08 4:57 
GeneralRe: How to send shutdown-restart command with TCP/IP Pin
Member 465172930-Dec-08 0:39
Member 465172930-Dec-08 0:39 
I couldn't cope with the ex-code and I found different code which is similar to other.

Finall code is;

[StructLayout(LayoutKind.Sequential)]
private struct LUID
{
public long dwLowPart;
public long dwHighPart;
}

[StructLayout(LayoutKind.Sequential)]
private struct LUID_AND_ATTRIBUTES
{
public LUID udtLUID;
public long dwAttributes;
}

[StructLayout(LayoutKind.Sequential)]
private struct OSVERSIONINFO
{
public long OSVSize;
public long dwVerMajor;
public long dwVerMinor;
public long dwBuildNumber;
public long PlatformID;
public string szCSDVersion;
}

[StructLayout(LayoutKind.Sequential)]
private struct TOKEN_PRIVILEGES
{
public long PrivilegeCount;
public LUID_AND_ATTRIBUTES laa;
}

[DllImport("advapi32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long AdjustTokenPrivileges(long TokenHandle, long DisableAllPrivileges, TOKEN_PRIVILEGES NewState, long BufferLength, long PreviousState, long ReturnLength);

private static bool EnableShutdownPrivledges()
{
bool EnableShutdownPrivledges = true;
long hTokenHandle = 0;
long hProcessHandle = GetCurrentProcess();
if ((hProcessHandle != 0L) && (OpenProcessToken(hProcessHandle, 40L, hTokenHandle) != 0L))
{
LUID lpv_la = new LUID();

string VBS0 = null;
string VBS1 = "SeShutdownPrivilege";
if (LookupPrivilegeValue(ref VBS0, ref VBS1, lpv_la) != 0L)
{
TOKEN_PRIVILEGES token;
token.PrivilegeCount = 1L;
token.laa.udtLUID = lpv_la;
token.laa.dwAttributes = 2L;
if (AdjustTokenPrivileges(hTokenHandle, 0L, token, 0L, 0L, 0L) != 0L)
{
EnableShutdownPrivledges = true;
}
}
}
return EnableShutdownPrivledges;
}

[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long ExitWindowsEx(long dwOptions, long dwReserved);

[DllImport("kernel32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long GetCurrentProcess();

[DllImport("kernel32", EntryPoint = "GetVersionExA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long GetVersionEx(OSVERSIONINFO lpVersionInformation);

private static bool IsWinNTPlus()
{
bool IsWinNTPlus = true;
return IsWinNTPlus;
}

[DllImport("advapi32", EntryPoint = "LookupPrivilegeValueA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long LookupPrivilegeValue([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpSystemName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpName, LUID lpLuid);

[DllImport("advapi32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long OpenProcessToken(long ProcessHandle, long DesiredAccess, long TokenHandle);

When I use the method

long uflags = 2L; // reboot

if (EnableShutdownPrivledges() == true)
ExitWindowsEx(uflags, 0L);
else
ExitWindowsEx(uflags, 0L); // to run method in any case, but It doesn't work without
// giving privileges to a user.


The problem is to give privileges to a user When the 'LookupPrivilegeValue' runs 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt' error returns.

I think If I solve giving privileges to a user that will be ok.

Any suggestions you might have?

Thansk all Mr. Kreskowiak.
QuestionRe: How to send shutdown-restart command with TCP/IP Pin
Member 46517292-Jan-09 1:42
Member 46517292-Jan-09 1:42 
AnswerRe: How to send shutdown-restart command with TCP/IP Pin
Member 46517292-Jan-09 2:37
Member 46517292-Jan-09 2:37 
QuestionI have Macros in Excel and I want it to run through my application in .NET Pin
sejal12328-Dec-08 21:45
sejal12328-Dec-08 21:45 
AnswerRe: I have Macros in Excel and I want it to run through my application in .NET Pin
Member 447035429-Dec-08 8:43
Member 447035429-Dec-08 8:43 
GeneralRe: I have Macros in Excel and I want it to run through my application in .NET Pin
sejal1231-Jan-09 23:27
sejal1231-Jan-09 23:27 
QuestionRun exe from web page Pin
yesu prakash28-Dec-08 21:11
yesu prakash28-Dec-08 21:11 
AnswerRe: Run exe from web page Pin
N a v a n e e t h28-Dec-08 21:48
N a v a n e e t h28-Dec-08 21:48 
GeneralRe: Run exe from web page Pin
yesu prakash28-Dec-08 22:11
yesu prakash28-Dec-08 22:11 
GeneralRe: Run exe from web page Pin
N a v a n e e t h28-Dec-08 22:32
N a v a n e e t h28-Dec-08 22:32 
GeneralRe: Run exe from web page Pin
yesu prakash28-Dec-08 23:01
yesu prakash28-Dec-08 23:01 
GeneralRe: Run exe from web page Pin
Dave Kreskowiak29-Dec-08 1:59
mveDave Kreskowiak29-Dec-08 1:59 
Questionhow to use the login controls in asp.net ? Pin
venkatnara28-Dec-08 20:26
venkatnara28-Dec-08 20:26 
AnswerRe: how to use the login controls in asp.net ? Pin
Brij28-Dec-08 20:57
mentorBrij28-Dec-08 20:57 
Questionhow to use Connection Zone in Webpart Control Pin
faizicrazy28-Dec-08 19:55
faizicrazy28-Dec-08 19:55 
QuestionRecommend T-SQL book? Pin
George_George28-Dec-08 19:37
George_George28-Dec-08 19:37 
AnswerRe: Recommend T-SQL book? Pin
N a v a n e e t h28-Dec-08 19:45
N a v a n e e t h28-Dec-08 19:45 
GeneralRe: Recommend T-SQL book? Pin
George_George28-Dec-08 19:50
George_George28-Dec-08 19:50 

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.