|
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
|
|
|
|
|
Hi,
I would like to know of an advanced log library/component for .NET, something that supports logging to Event Log, File, E-Mail, maybe some realtime console.
I'm looking for something robust for .NET. If it's free even better .
Any comments and suggestions are appreciated.
(I've seen log4net on sourceforge already)
Thanks,
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
How do I tab to the next edit box using the Enter key??
Also how do I do a message box in c#??
Thanks
|
|
|
|
|
I don't know about tabbing with the enter key but i can help you with the message box. do this and make sure caps are correct it is important in C#
MessageBox.Show("type string to display here, in quotes","here in quotes again type what do be displayed at the top of the message box",MessageBoxButtons.OK(this is to choose from different buttons on a message box),MessageBoxIcon.Error) hope this helped
|
|
|
|
|
C#:
<font color="blue">private</font> <font color="blue">void</font> textBox1_KeyUp(<font color="blue">object</font> sender, System.Windows.Forms.KeyEventArgs e) <br> { <br> <font color="#0000FF">if</font> (e.KeyData.Equals(Keys.Enter)) <br> { <br> textBox2.Focus(); <br> } <br> }
Vb:
<font color="blue">Public Function</font> TwinsOnWay(<font color="blue">ByVal</font> twins <font color="blue">As String</font>) <font color="blue">As String <br> Select Case</font> twins<br> <font color="blue">Case</font> "Gender" <br> <font color="blue">Return</font> "Two Girls" <br> <font color="blue">End Select <br> End Function</font> <br>
|
|
|
|
|
I like it when you get an error message box and forgot that you had your speakers turned up all the way...
/\ |_ E X E GG
|
|
|
|
|
Hey All,
Just wondering if there is a simple way to save a resource to disk. If I embed an exe into my program as a resource, how could I then save that exe to disk so I could execute it.
Regards,
Brian Dela
|
|
|
|
|
|
|
|
Brian Delahunty wrote:
I'm embedding plink.exe
I have putty installed on my computer now, I love that little app, so many things that you simply can't do with MS Telnet.
-Nick Parker
|
|
|
|
|
Hi!
I write a simple image processing tookit in c#. I face a trouble that c# seems didn't release the garbage. because my image is fairly large (around 6000*6000), it is very apparent. After several operations, physical used up, the pc works very slowly.
Give a simple example. There is a picturebox in the form, in form_load, load a 6000*6000 gray image into picturebox.
Then
private void button1_Click(object sender, System.EventArgs e)
{
Bitmap dst;
bool ret = Form1.Dup(this.pictureBox1.Image as Bitmap, out dst);
if (ret)
{
this.pictureBox1.Image = dst;
}
}
//get a new image from the original one
public static bool Dup(Bitmap src, out Bitmap dst)
{
dst = new Bitmap(src.Width, src.Height, src.PixelFormat);
dst.Palette = src.Palette; //it will be black, but never mind, just take the space
return true;
}
After press the button several time, i can see a lot of memory is taken by this process. and it seems not to release it at all. But in my code, only one copy is reference by pictureBox1.Image.
anybody know how to solve it?
Thanks!!
|
|
|
|
|
|
I have two sets: A{1,2,3,4,5} and B{1,3,5}
I need to create set C{2,4}.
Is there an optimal algorithm designed for this task?
Right now I’m simply going to stick A into an array and sort it.
Then I’ll iterate through each element in B and do a binary search for it in A. If not found then put it into C.
Is there a better way?
|
|
|
|
|
Try the following site
http://home.att.net/~srschmitt/Sets_class.html
|
|
|
|
|
Try this[^].
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
CP rules! Thanks guys. Your suggestions were great . . . and that set article is terrific!
|
|
|
|
|
I’m not familiar with the Modified property but the locked property, from what I understand, is only used by the designer. I find that it comes in handy when you don’t what a control to get moved by mistake.
Did you write the designer in C#? I’m not trying to be cute, but perhaps you should make this “bug” a “feature”.
|
|
|
|
|
Hey Zero,
Sorry to get off topic but I tried to create a designer in C# about a year ago and gave up. The problem that I ran into was:
1)Place a control onto the workspace.
2)Place a second larger control that completely covers the first control.
3)Click and do a rubber band select of the second control (the rubber band rect completely surrounds both controls.)
4)Release the mouse.
Now both controls should be "highlighted" to show that they are selected. You should see the highlight of the fist control appear on top of the second control - even though it is totally "under" the second control and not visible. (That's how it works in visual studio.)
I overrode every thing I could think of and even tried doing things in the WndProc to get the first control’s "highlight" rect to appear on top of the second control but nothing I did would make it appear because the second control was always drawn over the first’s highlight rec.
How did you accomplish it?
|
|
|
|
|
The Visual Studio IDE is used by Developers. These kinds of people dislike being restricted.
|
|
|
|
|
My web service methods return some non-string value(for example DateTime) , I want when some error(Exception) happend in my method I retuurn that error to the client. How can I report it to the client,for example send a string messsage error?
Mazy
No sig. available now.
|
|
|
|
|
One way could be to always return an XML string that could contain one of the following elements:
<ERRORS>
or
<RETURNVALUE>
Cheers,
Simon
"Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
animation mechanics in SVG (my first abstract photo)
|
|
|
|
|
Thanks Simon.
How can I do this in my web service code?
Mazy
No sig. available now.
|
|
|
|
|
You'd need to wrap the error/return value into a string manually.
Not sure how you could automate that. Maybe using an HTTPHandler?
Cheers,
Simon
"Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
animation mechanics in SVG (my first abstract photo)
|
|
|
|
|
hmmm..I'll try it.
Mazy
No sig. available now.
|
|
|
|