How to use LogonUser properly to impersonate domain user from workgroup client

Very few posts suggest using LOGON_TYPE_NEW_CREDENTIALS instead of LOGON_TYPE_NETWORK or LOGON_TYPE_INTERACTIVE. I had an impersonation issue with one machine connected to a domain and one not, and this fixed it. The last code snippet in this post suggests that impersonating across a forest does work, but it doesn’t specifically say anything about trust being set … Read more

C# Xml Serialization & Deserialization

In your deserialization code you’re creating a MemoryStream and XmlTextWriter but you’re not giving it the string to deserialize. using (MemoryStream memStream = new MemoryStream()) { using (XmlTextWriter textWriter = new XmlTextWriter(memStream, Encoding.Unicode)) { // Omitted } } You can pass the bytes to the memory stream and do away with the XmlTextWriter altogether. using … Read more

How do I prevent print screen

You can’t. The best you can do is render to a hardware accelerated device on an overlay, similar to what video players used to do. Basically, you paint your entire window blue, and render your graphics onto the video card, and internally the video card will replace the blue with the graphics. The downside to … Read more

Embedding a DOS console in a windows form

It’s possible to redirect the standard input/output of console/dos applications using the Process class. It might look something like this: var processStartInfo = new ProcessStartInfo(“someoldapp.exe”, “-p someparameters”); processStartInfo.UseShellExecute = false; processStartInfo.ErrorDialog = false; processStartInfo.RedirectStandardError = true; processStartInfo.RedirectStandardInput = true; processStartInfo.RedirectStandardOutput = true; processStartInfo.CreateNoWindow = true; Process process = new Process(); process.StartInfo = processStartInfo; bool processStarted … Read more

C#: multiline text in DataGridView control

You should set DefaultCellStyle.WrapMode property of column to DataGridViewTriState.True. After that text in cells will be displayed correctly. Example (DataGridView with one column): dataGridView1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True; dataGridView1.Rows.Add(“test” + Environment.NewLine + “test”); (Environment.NewLine = \r\n in Windows)