BSD Magazine releases its May 2010 Issue.
Hello all,
BSDMag just released the may issue. Get it here.
Archive for April 2010
Hello all,
BSDMag just released the may issue. Get it here.
Hey all,
I have a process that is a C# process. I need to do something different if someone just double-clicks the application than if it is launched by a certain other process. So I decided to check the parent process.
I couldn’t find a simple C# only method. But I did find a code snippet that works. There were actually lots of posts on that provided the following code snippet or variations thereof, so I consider it to be public domain. So obviously I didn’t write this part.
private static Process GetParentProcess()
{
int iParentPid = 0;
int iCurrentPid = Process.GetCurrentProcess().Id;
IntPtr oHnd = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (oHnd == IntPtr.Zero)
return null;
PROCESSENTRY32 oProcInfo = new PROCESSENTRY32();
oProcInfo.dwSize =
(uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(PROCESSENTRY32));
if (Process32First(oHnd, ref oProcInfo) == false)
return null;
do
{
if (iCurrentPid == oProcInfo.th32ProcessID)
iParentPid = (int)oProcInfo.th32ParentProcessID;
}
while (iParentPid == 0 && Process32Next(oHnd, ref oProcInfo));
if (iParentPid > 0)
return Process.GetProcessById(iParentPid);
else
return null;
}
static uint TH32CS_SNAPPROCESS = 2;
[StructLayout(LayoutKind.Sequential)]
public struct PROCESSENTRY32
{
public uint dwSize;
public uint cntUsage;
public uint th32ProcessID;
public IntPtr th32DefaultHeapID;
public uint th32ModuleID;
public uint cntThreads;
public uint th32ParentProcessID;
public int pcPriClassBase;
public uint dwFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szExeFile;
};
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr CreateToolhelp32Snapshot(uint dwFlags, uint th32ProcessID);
[DllImport("kernel32.dll")]
static extern bool Process32First(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
[DllImport("kernel32.dll")]
static extern bool Process32Next(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
}
I took this code snippet and improved upon it and made myself the following static class. This class more easily exposes:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Runtime.InteropServices;
namespace ParentProcess
{
public class ParentProcess
{
public static String ProcessName
{
get { return GetParentProcess().ProcessName; }
}
public static int ProcessId
{
get { return GetParentProcess().Id; }
}
public static String FullPath
{
get
{
return GetParentProcess().MainModule.FileName;
}
}
public static String FileName
{
get
{
return System.IO.Path.GetFileName(GetParentProcess().MainModule.FileName);
}
}
public static String DirectoryName
{
get
{
return System.IO.Path.GetDirectoryName(GetParentProcess().MainModule.FileName);
}
}
private static Process GetParentProcess()
{
int iParentPid = 0;
int iCurrentPid = Process.GetCurrentProcess().Id;
IntPtr oHnd = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (oHnd == IntPtr.Zero)
return null;
PROCESSENTRY32 oProcInfo = new PROCESSENTRY32();
oProcInfo.dwSize =
(uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(PROCESSENTRY32));
if (Process32First(oHnd, ref oProcInfo) == false)
return null;
do
{
if (iCurrentPid == oProcInfo.th32ProcessID)
iParentPid = (int)oProcInfo.th32ParentProcessID;
}
while (iParentPid == 0 && Process32Next(oHnd, ref oProcInfo));
if (iParentPid > 0)
return Process.GetProcessById(iParentPid);
else
return null;
}
static uint TH32CS_SNAPPROCESS = 2;
[StructLayout(LayoutKind.Sequential)]
public struct PROCESSENTRY32
{
public uint dwSize;
public uint cntUsage;
public uint th32ProcessID;
public IntPtr th32DefaultHeapID;
public uint th32ModuleID;
public uint cntThreads;
public uint th32ParentProcessID;
public int pcPriClassBase;
public uint dwFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szExeFile;
};
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr CreateToolhelp32Snapshot(uint dwFlags, uint th32ProcessID);
[DllImport("kernel32.dll")]
static extern bool Process32First(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
[DllImport("kernel32.dll")]
static extern bool Process32Next(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
}
}
This makes it easier for me to simply include the class above in my code and make simple calls:
String exename = ParentProcess.FileName; String FullPathToExe = ParentProcess.FullPath; String DirectoryInWhichExeResides= ParentProcess.DirectoryName;
…and the pid and process name, etc…
I hope this helps you.
References
http://www.facebook.com/note.php?note_id=73447531256
http://www.debugging.com/bug/6657
http://www.eggheadcafe.com/software/aspnet/35541264/how-to-get-the-parent-pro.aspx
No Copyright.
UPDATE: This is now part of the EasyXml NuGet package. There is also an EasyXml.Sources NuGet package.
Hey all,
Today I was working on XML Serialization.
After learning how to do it, I discovered it takes four lines of code to write an XML and four lines of code to read in an XML.
However, I prefer one line of code to four so I made a Serializer.cs class with two static functions.
After thinking about it, I made these classes generic so they work with any type. I hope this helps someone.
using System;
using System.IO;
using System.Xml.Serialization;
namespace BlogTool
{
public class Serializer
{
#region Functions
public static void SerializeToXML(T t, String inFilename)
{
XmlSerializer serializer = new XmlSerializer(t.GetType());
TextWriter textWriter = new StreamWriter(inFilename);
serializer.Serialize(textWriter, t);
textWriter.Close();
}
public static T DeserializeFromXML(String inFilename)
{
XmlSerializer deserializer = new XmlSerializer(typeof(T));
TextReader textReader = new StreamReader(inFilename);
T retVal = (T)deserializer.Deserialize(textReader);
textReader.Close();
return retVal;
}
#endregion
}
}
So now if you have a class, you can easily serialize it to and from an XML with a single line.
Here is an example Project that contains these files:
Blog.cs
using System;
namespace BlogTool
{
[Serializable()]
public class Blog
{
#region Member Variables
String mBlogUrl;
String mCategory;
#endregion
#region Constructors
public Blog()
{
}
public Blog(String inURL, String inCategory)
{
mBlogUrl = inURL;
mCategory = inCategory;
}
#endregion
#region Properties
public String BlogUrl
{
get { return mBlogUrl; }
set { mBlogUrl= value; }
}
public String Category
{
get { return mCategory; }
set { mCategory= value; }
}
#endregion
}
}
BlogList.cs
using System.Collections.Generic;
namespace BlogTool
{
[Serializable]
public class BlogList
{
#region Member Variables
List mBlogs = new List();
#endregion
#region Constructors
/*
* The default constructor
*/
public BlogList()
{
}
#endregion
#region Properties
public List Blogs
{
get { return mBlogs; }
set { mBlogs = value; }
}
#endregion
}
}
Program.cs
namespace BlogTool
{
class Program
{
static void Main(string[] args)
{
BlogList bloglist = new BlogList();
Blog b1 = new Blog("http://rhyous.com","Software");
Blog b2 = new Blog("http://www.alittletipsy.com", "Crafts");
bloglist.Blogs.Add(b1);
bloglist.Blogs.Add(b2);
Serializer.SerializeToXML(bloglist, "FavoriteBlogs.xml");
}
}
}
Serializer.cs
using System;
using System.IO;
using System.Xml.Serialization;
namespace BlogTool
{
public class Serializer
{
#region Functions
public static void SerializeToXML(T t, String inFilename)
{
XmlSerializer serializer = new XmlSerializer(t.GetType());
TextWriter textWriter = new StreamWriter(inFilename);
serializer.Serialize(textWriter, t);
textWriter.Close();
}
public static T DeserializeFromXML(String inFilename)
{
XmlSerializer deserializer = new XmlSerializer(typeof(T));
TextReader textReader = new StreamReader(inFilename);
T retVal = (T)deserializer.Deserialize(textReader);
textReader.Close();
return retVal;
}
#endregion
}
}
Ok, so now that you have the files, you can run this program.
In the bin\debug or bin\release directory where you executable is placed when you build, you will see the FavoriteBlogs.xml file. The XML should look as follows:
<!--?xml version="1.0" encoding="utf-8"?-->
127.0.0.1 or ::1
Software
http://www.alittletipsy.com
Crafts
I know, this is not written very well as a walk-thru, but I wrote it fast. Maybe I will clean it up later.
namespace Rhyous.EasyXml
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.Serialization;
[ExcludeFromCodeCoverage]
public static class Serializer
{
#region Functions
/// <summary>
/// This function writes the serialized XML to the file name passed in.
/// </summary>
/// <typeparam name="T">The object type to serialize.</typeparam>
/// <param name="t">The instance of the object.</param>
/// <param name="outFilename">The file name. It can be a full path.</param>
/// <param name="inOmitXmlDeclaration"></param>
/// <param name="inNameSpaces"></param>
/// <param name="inEncoding"></param>
public static void SerializeToXml<T>(T t, string outFilename, bool inOmitXmlDeclaration = false, XmlSerializerNamespaces inNameSpaces = null, Encoding inEncoding = null)
{
MakeDirectoryPath(outFilename);
var ns = inNameSpaces;
if (ns == null)
{
ns = new XmlSerializerNamespaces();
ns.Add("", "");
}
var serializer = new XmlSerializer(t.GetType());
var textWriter = (TextWriter)new StreamWriter(outFilename);
if (inEncoding != null && inEncoding.Equals(Encoding.UTF8))
textWriter = new Utf8StreamWriter(outFilename);
var xmlWriter = XmlWriter.Create(textWriter, new XmlWriterSettings { OmitXmlDeclaration = inOmitXmlDeclaration });
serializer.Serialize(xmlWriter, t, ns);
textWriter.Close();
}
/// <summary>
///
/// </summary>
/// <param name="outFilename"></param>
private static void MakeDirectoryPath(string outFilename)
{
var dir = Path.GetDirectoryName(outFilename);
if (dir != null && !Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
}
/// <summary>
/// This function returns the serialized XML as a string
/// </summary>
/// <typeparam name="T">The object type to serialize.</typeparam>
/// <param name="t">The instance of the object.</param>
/// <param name="inOmitXmlDeclaration"></param>
/// <param name="inNameSpaces"></param>
/// <param name="inEncoding"></param>
public static string SerializeToXml<T>(T t, bool inOmitXmlDeclaration = false, XmlSerializerNamespaces inNameSpaces = null, Encoding inEncoding = null)
{
var ns = inNameSpaces;
if (ns == null)
{
ns = new XmlSerializerNamespaces();
ns.Add("", "");
}
var serializer = new XmlSerializer(t.GetType());
var textWriter = (TextWriter)new StringWriter();
if (inEncoding != null && inEncoding.Equals(Encoding.UTF8))
textWriter = new Utf8StringWriter();
var xmlWriter = XmlWriter.Create(textWriter, new XmlWriterSettings { OmitXmlDeclaration = inOmitXmlDeclaration });
serializer.Serialize(xmlWriter, t, ns);
return textWriter.ToString();
}
/// <summary>
/// This function deserializes the XML file passed in.
/// </summary>
/// <typeparam name="T">The object type to serialize.</typeparam>
/// <param name="inFilename">The file or full path to the file.</param>
/// <returns>The object that was deserialized from xml.</returns>
public static T DeserializeFromXml<T>(String inFilename)
{
if (string.IsNullOrWhiteSpace(inFilename))
{
return default(T);
}
// Wait 1 second if file doesn't exist, in case we are waiting on a
// separate thread and beat it here.
if (!File.Exists(inFilename))
Thread.Sleep(1000);
// File should exist by now.
if (File.Exists(inFilename))
{
var deserializer = new XmlSerializer(typeof(T));
var textReader = (TextReader)new StreamReader(inFilename);
var reader = new XmlTextReader(textReader);
reader.Read();
var retVal = (T)deserializer.Deserialize(reader);
textReader.Close();
return retVal;
}
throw new FileNotFoundException(inFilename);
}
/// <summary>
/// This function deserializes the XML string passed in.
/// </summary>
/// <typeparam name="T">The object type to serialize.</typeparam>
/// <param name="inString">The string containing the XML.</param>
/// <returns>The object that was deserialized from xml.</returns>
public static T DeserializeFromXml<T>(ref string inString)
{
if (string.IsNullOrWhiteSpace(inString))
{
return default(T);
}
var deserializer = new XmlSerializer(typeof(T));
var textReader = (TextReader)new StringReader(inString);
var retVal = (T)deserializer.Deserialize(textReader);
textReader.Close();
return retVal;
}
#endregion
#region UTF8StringWriter
public sealed class Utf8StringWriter : StringWriter
{
public override Encoding Encoding { get { return Encoding.UTF8; } }
}
public sealed class Utf8StreamWriter : StreamWriter
{
public Utf8StreamWriter(string file)
: base(file)
{
}
public override Encoding Encoding { get { return Encoding.UTF8; } }
}
#endregion
}
}
Sources:
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx
http://www.switchonthecode.com/tutorials/csharp-tutorial-xml-serialization
Ok, so I have an IBM T40 and I am installed PC-BSD 8. Then for fun, I downloaded a more recent snapshot (PCBSD 8-Stable) and installed that.
However, woe is me, I ran into this FreeBSD bug: 131087. This prevents me from using my Wireless, which on a laptop is a show stopper.
So I got out the release version of the PCBSD 8 installer and tried to install again, however, now it fails.
Here is the log:
Running: find-update-parts kern.geom.debugflags: 0 -> 16 Cleaning up ad0 Running: dd if=/dev/zero of=/dev/ad0 count=2048 2048+0 records in 2048+0 records out 1048576 bytes transferred in 0.391058 secs (2681383 bytes/sec) Running fdisk on ad0 Running: fdisk -I /dev/ad0 fdisk: invalid fdisk partition table found fdisk: Class not found ******* Working on device /dev/ad0 ******* ERROR: The slice ad0s1 doesn't exist! FDISK Failure Running: umount /cdmnt-install umount: /cdmnt-install: statfs: No such file or directory umount: /cdmnt-install: unknown file system
So obviously something is broke with the partition table. I am not sure if this can be duplicated but it sure is annoying.
So how do I fix this? Well, right now I decided to use dd to wipe my drive.
dd if=/dev/zero of=/dev/ad0 bs=4096k
That took something more than an hour and then I reinstalled an all worked fine.
Anyway, I wonder if there is a bug with the installer that caused this or if this is a result of the multiple crashes that occurred due to the iwi bug that causes kernel panic.
Hello all,
I thought I would share my experiences of using PCBSD 8 on an IBM T40. I am going to put the information in separate headings, and I am going to document who is responsible for the feature I am talking about by prefacing each line with the responsible party. If it is a positive experience, the responsible party will be in Green. If it is a negative experience the responsible party will be in Red.
I am probably going to reinstall and do all this over again with the “snapshot” version and look for any improvements and try to submit any bugs/suggestions to Kris and his team.
Intel Pentium M
ATI Radeon Mobility M7 LQ (Mobility Radeon 7500 (fdds)
Intel PRO/Wireless 2200BG
Realtek AC97 Audio
Intel 82801DB PRO/100 VE Network Connection
UltraATA/100 EIDE Controller
34 GB 5400 RPM drive
9:20 AM started boot process
9:25 AM Finished configuring and clicked “Install”
9:37 AM 47% finished
Sorry, I was pulled away for an hour so I don’t know how long hte install took. I did find an install log, but unfortunately it had no date stamps. I rebooted before I realized that the log file itself might have had a timestamp.
PCBSD: So I don’t know how long the install took but it felt too long. I wonder if there are some tricks that can be done to speed this up. For example, the install could use an image. It could lay down the image, then extend the last partition to fill the drive, and then modify the key files after the image is laid down, add any packages not included in the image.
PCBSD: Adding the “Run X in Vesa mode” as item 6 is pretty cool.
PCBSD: Adding the “Run the Display setup wizard” is nice, so you can try to use a different video card post setup.
PCBSD: Single user mode and other boot options normal to FreeBSD still exist.
PCBSD: Splash screen works (this is an x86 box)
PCBSD: The bootup takes too long, there should be some ways to speed it up.
FreeBSD: I like to have a shorter delay when booting. 10 seconds is too long for me. So I added this to /boot/loader.conf
# Boot Options
autoboot_delay=”3″
Update: So I reinstalled because I tried a PC-BSD 8-stable snapshot, but ran into a FreeBSD bug, so I returned to PCBSD 8 release. On Reinstall, the ATI-3D-Enabled drivers worked, so I am editing this to say so. I am not sure why they didn’t appear to work the first time. Maybe because I had tried the Radeon settings first, I don’t know.
PCBSD: On first boot, there was a great interface for configuring Xorg.
PCBSD: This has a Radeon card, but there was no option for Radeon, just ATI or Radeonhd and neither worked really.
Note: I found another solution that added 3D features I wanted. See the Xorg and KDE4 Features section.
Networking
FreeBSD: Wired networking worked using DHCP without me having to do anything.
FreeBSD: Unplugging the wired network and plugging into a different subnet does not automatically cause dhclient to run again. So in order to get new IP settings, I had to run /etc/netstart as root. It didn’t work the first time either, I had to run it again.
PCBSD/KDE4: I couldn’t easily find a network tool to configure WIFI. I finally found it under System Settings.
PCBSD/KDE4: Once I did find the Newtork Configuration tool, it was easy to use and I connected to my WPA2 secured wireless network using a D-Link DIR-615 router. It worked very well and I downloaded a lot with no hiccups.
FreeBSD/ACPI: Put machine to sleep. Worked fine.
FreeBSD/ACPI/moused: Woke machine up. No mouse. Had to use Ctrl + Alt + F1 to get a command prompt and fix this by restarting the moused daemon.
Note: Added this line before exit 0 in the /etc/rc.resume. This doesn’t resolve the bug, but restarts the mouse so it works, which is a workaround, but workable none-the-less.
/etc/rc.d/moused/restart
PCBSD/FreeBSD: Closing the lid does not put the machine to sleep.
Note: I fixed this by added this line to the /etc/sysctl.conf
hw.acpi.lid_switch_state=S3
After making the above settings, you can run this command to change it in the current booted system so you don’t have to reboot. But the setting in /etc/sysctl.conf is what makes this persist on reboot.
sysctl -w hw.acpi.lid_switch_state=S3
PCBSD: Ports Console is easily confused with a regular console as Icon Text is not always looked at, I recommend a different icon and naming it Ports Jail. I created this for myself.
KDE4/PCBSD: The fonts were a little off for the four default icons vs the background…but this only seems to be an issue with dark backgrounds.
Shutdown and Reboot works as a regular user by default.
KDE4: After selecting Reboot or Shutdown, there is a hesitation before the shutdown/reboot popup, so I sometimes double click. I don’t like how the shutdown/reboot popup just disappears if a second click occurs with the mouse anywhere but on the shutdown/reboot popup.
Firefox/Flash/FreeBSD: YouTube – Went online and clicked on one of the first videos and it played.
Update: Do to a reinstall, I noticed that choosing ATI 3D actually worked an enabled 3D features. I will check on the settings below to see whey they set.
Even though I had a Radeon, only the ATI or ATI 3D drivers worked. The RadeonHd drivers did not work. Probably because it is an old Radeon and not a new RadeonHd.
Note: I got the Radeon driver to work myself by using the xorg.conf from the ati3d settting and changing the “Device” section to use the settings below. I didn’t make these up on my own, I found them here: http://userweb.cs.utexas.edu/~walter/geek/linux-t40.html#video
Section "Device" Identifier "ATI Radeon" Driver "radeon" Option "DynamicClocks" "on" Option "AGPMode" "4" Option "RenderAccel" "on" Option "EnablePageFlip" "on" Option "BIOSHotkeys" "on" BusID "PCI:1:0:0" EndSection
After doing this, I got much better settings as described below:
Xorg/KDE4: Konsole supports transparency when using ATI 3D.
Xorg/KDE4/3D: Moving the cursor to the top of the screen will do a cool screen where it shows your configured screen in a line from left to right (four by default though I always change to 3).
Xorg/KDE4/3D: Moving the cursor to the top right corner of the screen will do a cool screen where it shows your configured screens in a 3D object (cube or pyramid).
Ctrl + Alt + Backspace is disabled
Ctrl + Alt + F1 does display the terminal sessions and then:
Alt + F2, F3, F4, …, F8 will all take you to one of the open console terminal sessions.
Alt + F9 returns you to your Xorg seesion
KDE4/PCBSD: Alt + F1 does NOT open the start bar. Right-clicking on the Fireball and choosing Application Launcher settings shows no shortcut, so you can configure it if desired. When I install KDE4 the default is Alt + F1, not None, so I assume this is something PCBSD changed.
KDE4: After selecting Reboot or Shutdown, I don’t like how the reboot option or shutdown option just disappears if I click with the mouse on the desktop.
PCBSD: PBIs make installing software fairly easy.
PCBSD: There are not enough PBIs.
PCBSD: The size of PBIs are HUGE, which is by design, they include every library they need to run, but by design or not, they are huge.
PCBSD: I installed Firefox and Open Office and Pidgin post install because there are updated version to those on disk anyway.
KDE4/Firefox: Firefox prompts every single time I open it to be the default browser. Saying yes appears to do nothing. I manually went to KDE4’s System Settings and change the default application for the web browser to be /Programs/bin/firefox3.sh and this issue stopped.
PCBSD: K3b installed perfected first try.
PCBSD: K3b burnt a DVD (the latest PC-BSD snapshot) without having to perform any tweak, and for those who know how many tweaks are required when using just FreeBSD and not PC-BSD, you know why this is awesome.
Every boot when loading KDE4, the following error displays: The profile “” has been selected but it does not exist.
I plan to update this from time to time with my experiences, so this post is in no way final.
Hello all,
PC-BSD’s Ports Console in a jail is cool, but I keep clicking when I want a normal console!
So today, I got fed up and I drew a new Icon for it:
I then renamed it from Ports Console to Ports Jail.
I’ll never make this mistake again and I think I will suggest this idea on the PC-BSD forums.
Oops!
This didn’t exactly work as expected. Sure, I never confuse the Icon on the desktop anymore, or in the KDE Menu, but now I have a different problem. If I open the Jail first, then open the regular Konsole, the icon for the running Konsole and Jail apps in the task bar are both Jail icons. The same in reverse. If I open Konsole, then open the Jail, the icons for the running Konsole and Jail apps in the task bar are both Konsole icons.
I can’t seem to make this work how I want.
So today, I need to install FreeBSD clean in a VM for testing. I thought, I am going to use the PCBSD 8 install disk because it is faster.
I am sorry, but I am a Sysinstall hater.
Thanks PC-BSD for the much faster installer.
Ok, so I had a hard time finding Windows Color and Appearance in Windows 7.
It is pretty easy to get to the Windows Color and Appearance tool if you know where to go. The problem is that where to go is not obvious. So here is where you go:
Besides the problem that it is not obvious where to go, there are also some computer some diseases that make this harder than it should be.
Disease #1 – Limited Clicking Ability Disorder or LCAD
People have what is called Limited Clicking Ability Disorder or LCAD. In layman’s terms, click laziness. Yes, that means we want to get there in less clicks.
It is 4 clicks to get to the Windows Color and Appearance tool, assuming you know where you are going. Otherwise, you have to click all over till you find it. Whether it is four or more, this is way too many clicks for someone who suffers from click laziness or LCAD.
The Cure
Create desktop shortcuts or shortcuts on your startbar.
Steps for creating a shortcut to the Windows Color and Appearance tool.
You now have a shortcut on your desktop which will all you to access Windows Color and Appearance in one click and cure your LCAD.
Note: If you want, you can right-click on the shortcut and choose properties and click the Change icon button and select a different icon if you want.
Disease #2 – Keyboard-to-Mouse Tropophobia
Tropophobia is the fear of moving and yes, Keyboard-to-Mouse Tropophobia is the fear of moving the hands from the keyboard to the mouse.
The Cure
Learn to access as many features as you can without using the mouse.
So how can you access the Windows Color and Appearance tool without going to mouse? This one was not as easy as others, but the solution was found.
Steps for accessing the Windows Color and Appearance tool using only the keyboard
Do this:
Sources:
This page got me started and my own knowledge got me an easier solution than what was posted here:
http://www.sevenforums.com/tutorials/59884-window-color-appearance-shortcut-create.html
Ok, so to my dismay, Microsoft has not created a default widget for selecting a directory.
I searched and searched and searched. Found some here are there, but none were really what I wanted.
I finally found one I like, so I thought I would share it with you. Here is what I like about the one I found:
Ok, so I wanted to create a little Help | About page that looks like this.
MyProgram 1.0.0.5
Author: Jared Barneck
Contributors: John, Mike, Mark, Tom, Bill, Jane, Ryan, Josh
I don’t really want to have to remember to change the version in the help file with each release, so I wanted to get the version dynamically.
Turns out that you can get the version as a string with a single line of code:
String theVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
Once you have the version as a string, you can display it how you want.
The XAML allows you to provide what are called StaticResources. Such resources can be given to a Window or to certain controls.
For this tutorial, I assume you are in Visual Studio 2008. I assume that you already know how to create a new Project and choose WPF Application. All examples assume you have a new WPF Application.
So lets get started with three examples of binding to StaticResources.
This example will demonstrate instantiating a String as a StaticResource and binding a TextBox to it.
TextBox elements into the default Grid control.
<ListBox Margin="12,12,0,0" Name="listBox1" Height="100" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" />
<ListBox Margin="138,12,20,0" Name="listBox2" Height="100" VerticalAlignment="Top" />
<TextBox Margin="12,118,0,121" Name="textBox1" Width="120" IsReadOnly="True" HorizontalAlignment="Left" />
<TextBox Margin="138,118,20,121" Name="textBox2" Width="120" IsReadOnly="True" HorizontalAlignment="Left" />
xmlns reference to the System namespace. This is done by adding the xmlns:System line to as an attribute to the top Window element as shown:
<Window x:Class="StaticResourceBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
Strings to it as StaticResources.
<Window.Resources>
<System:String x:Key="FirstName">Jared</System:String>
<System:String x:Key="LastName">Barneck</System:String>
<System:String x:Key="Alias">Rhyous</System:String>
</Window.Resources>
TextBox elements to bind to each String added as a StaticResource by adding a Text attribute.
<TextBox Text="{StaticResource FirstName}" Height="23" Margin="51,25,107,0" Name="textBox1" VerticalAlignment="Top" />
<TextBox Text="{StaticResource LastName}" Height="23" Margin="51,54,107,0" Name="textBox2" VerticalAlignment="Top" />
<TextBox Text="{StaticResource Alias}" Height="23" Margin="51,83,107,0" Name="textBox3" VerticalAlignment="Top" />
The final XAML looks as follows. No changes were made to the code behind at all.
<Window x:Class="StaticResourceBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<System:String x:Key="FirstName">Jared</System:String>
<System:String x:Key="LastName">Barneck</System:String>
<System:String x:Key="Alias">Rhyous</System:String>
</Window.Resources>
<Grid>
<TextBox Height="23" Margin="51,25,107,0" Name="textBox1" VerticalAlignment="Top" Text="{StaticResource FirstName}"/>
<TextBox Height="23" Margin="51,54,107,0" Name="textBox2" VerticalAlignment="Top" Text="{StaticResource LastName}"/>
<TextBox Height="23" Margin="51,83,107,0" Name="textBox3" VerticalAlignment="Top" Text="{StaticResource Alias}"/>
</Grid>
</Window>
This example will demonstrate instantiating arrays as StaticResources and binding a ListBox to the arrays.
To show an example of building onto existing or previous learned knowledge, we are going to also implement binding each TextBox's Text properties to the ListBox's SelectedItem property.
ListBox and two TextBox elements into the default Grid control.
<ListBox Margin="12,12,0,0" Name="listBox1" Height="100" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" />
<ListBox Margin="138,12,20,0" Name="listBox2" Height="100" VerticalAlignment="Top" />
<TextBox Margin="12,118,0,121" Name="textBox1" Width="120" IsReadOnly="True" HorizontalAlignment="Left" />
<TextBox Margin="138,118,20,121" Name="textBox2" Width="120" IsReadOnly="True" HorizontalAlignment="Left" />
xmlns reference to the System namespace. This is done by adding the xmlns:System line to as an attribute to the top Window element as shown:
<Window x:Class="StaticResourceBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<x:Array x:Key="StringList" Type="System:String">
<System:String>Line 1</System:String>
<System:String>Line 2</System:String>
<System:String>Line 3</System:String>
<System:String>Line 4</System:String>
</x:Array>
<x:Array x:Key="IntArray" Type="System:Int32">
<System:Int32>100</System:Int32>
<System:Int32>200</System:Int32>
<System:Int32>300</System:Int32>
<System:Int32>400</System:Int32>
</x:Array>
</Window.Resources>
ListBox's Text property to bind to the String array and the other ListBox's Text property to bind to the Int32 array.
<ListBox ItemsSource="{StaticResource StringList}" Margin="12,12,0,0" Name="listBox1" Height="100" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" />
<ListBox ItemsSource="{StaticResource IntArray}" Margin="138,12,20,0" Name="listBox2" Height="100" VerticalAlignment="Top" />
TextBox to the listBox1.SelectedItem property and bind the other to the listBox2.SelectedItem.
<TextBox Text="{Binding ElementName=listBox1, Path=SelectedItem}" Margin="12,118,0,121" Name="textBox1" Width="120" IsReadOnly="True" HorizontalAlignment="Left" />
<TextBox Text="{Binding ElementName=listBox2, Path=SelectedItem}" Margin="138,118,20,121" Name="textBox2" Width="120" IsReadOnly="True" HorizontalAlignment="Left" />
The final XAML looks as follows. No changes were made to the code behind at all.
<Window x:Class="StaticResourceBinding2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<x:Array x:Key="StringList" Type="System:String">
<System:String>Line 1</System:String>
<System:String>Line 2</System:String>
<System:String>Line 3</System:String>
<System:String>Line 4</System:String>
</x:Array>
<x:Array x:Key="IntArray" Type="System:Int32">
<System:Int32>100</System:Int32>
<System:Int32>200</System:Int32>
<System:Int32>300</System:Int32>
<System:Int32>400</System:Int32>
</x:Array>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{StaticResource StringList}" Margin="12,12,0,0" Name="listBox1" Height="100" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" />
<ListBox ItemsSource="{StaticResource IntArray}" Margin="138,12,20,0" Name="listBox2" Height="100" VerticalAlignment="Top" />
<TextBox Text="{Binding ElementName=listBox1, Path=SelectedItem}" Margin="12,118,0,121" Name="textBox1" Width="120" IsReadOnly="True" HorizontalAlignment="Left" />
<TextBox Text="{Binding ElementName=listBox2, Path=SelectedItem}" Margin="138,118,20,121" Name="textBox2" Width="120" IsReadOnly="True" HorizontalAlignment="Left" />
</Grid>
</Window>
In the previous two examples, we added the resources to the main Window object. However, a resource can be added to a control.
This example will demonstrate instantiating an array as a StaticResources for a control. We will then bind a TabControl’s ItemSource property to this array. This will cause a Tab to be created for each item in the array.
TabControl into the default Grid control.
<TabControl Name="tabControl1">
xmlns reference to the System namespace. This is done by adding the xmlns:System line to as an attribute to the top Window element as shown:
<Window x:Class="StaticResourceBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
Grid.Resources section in the XAML and add an array as a StaticResource under the Grid control.
<Grid.Resources>
<x:Array x:Key="TabList" Type="System:String">
<System:String>Tab 1</System:String>
<System:String>Tab 2</System:String>
<System:String>Tab 3</System:String>
</x:Array>
</Grid.Resources>
TabControl's ItemSource property to bind to the String array.
<TabControl Name="tabControl1" ItemsSource="{StaticResource TabList}">
The final XAML looks as follows. No changes were made to the code behind at all.
<Window x:Class="StaticResourceBinding3.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.Resources>
<x:Array x:Key="TabList" Type="System:String">
<System:String>Tab 1</System:String>
<System:String>Tab 2</System:String>
<System:String>Tab 3</System:String>
</x:Array>
</Grid.Resources>
<TabControl Name="tabControl1" ItemsSource="{StaticResource TabList}">
</TabControl>
</Grid>
</Window>
Hey, there is nothing wrong with more examples, so if you have an example of your own feel free to add it as a comment.
Copyright ® Rhyous.com – Linking to this post is allowed without permission and as many as ten lines of this page can be used along with this link. Any other use of this page is allowed only by permission of Rhyous.com.
For Bugzilla authentication, LDAP is configured as the first authentication method (or the only authentication method) and the password for the user used to connect to LDAP has expired or changed.
Attempts to login result in the following error:
Failed to bind to the LDAP server. The error message was: 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece�
The change must be made manually to the bugzilla/data/params file.
Using a text editor, open the params file located under the bugzilla website and under the data folder.
Note: On FreeBSD, this was located in /usr/local/etc/www/apache22/data/bugzilla/data/params
Look for the following line to configure this manually in text:
‘LDAPbinddn’ => ‘CN=Barneck\\, Jared,OU=Support,OU=YourOU,DC=Domain,DC=tld:P@sswd!’,
As you can see the password is in clear text. You can change it with any text editor.
Authentication fails with the following error even when not using an LDAP user:
Failed to bind to the LDAP server. The error message was: 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece�
To me this is a straight up bug. I am not sure if it is reported.
Bugzilla will not even try authenticate a local user using another authentication method when LDAP integration is both list first and failing. If LDAP is the first option in the authentication methods, then if the credentials are invalid, it just stops the entire authentication process and returns this error:
Low. While this could disallow all logins to the bugzilla web page, including administrator logins. A server administrator can make a manual change to one of configuration text files.
Authentication is configured to use LDAP then DB. It needs to be reversed, where it tries DB then LDAP.
There is a setting called user_verify_class in Bugzilla that allows you to select the different authentication methods you want to use. There are two places to access this:
Log in as an administrator and go to Administration | Parameters | User Authentication.
Then look for the user_verify_class setting.
Click on DB and click to move it up to the top of the list.
Using a text editor, open the params file located under the bugzilla website and under the data folder.
Look for the following line to configure this manually in text:
‘user_verify_class’ => ‘LDAP,DB’,
Change it to:
‘user_verify_class’ => ‘DB,LDAP’,
This setting allows for enabling and disabling authentication as well as providing the order for enabled authentication methods.
By default only DB is enabled. But it can be configured so that both DB, and LDAP are enabled and they can be ordered so either is first. However, LDAP should NOT be first. The following setting should be used.
‘LDAP,DB’,
Let me tell you the dilemma I just faced and resolved.
I have a bugzilla installation that is configured to use LDAP for authentication. It is configured to fall back to DB authentication if LDAP isn’t available.
I have both a local user and a domain user that are admins just to resolve this situation where I can’t login as a domain user. I can login as the local user and make the change I need.
First, let me tell you that this is a test/educational server for learning so I “fiddle” with it. Its not in production.
Well, my password changed, as commonly happens every 90 days, and I went to update the password using the local account.
No matter what I tried, I couldn’t login with the local account. My password has changed a few times and this had never been a problem.
So this is my dillemma. I can’t login to get to the screen to update my password.
Well, I learned a few things due to this problem and I plan to post on them:
I plan to make a post on both and I will link to them here when they are done.
Hello everyone,
I have a project one computer in the My Documents folder. When I copy it to another user computer (under their My Documents directory) I want it to work with no tweaking.
My build process uses build events to copy files to an Install directory and since build events uses macros so it works perfectly. I want to use these same Macros in either or both of two debugging options:
So I attempt to use the same Macros:
Start external program: $(SolutionDir)\Install\Program.exe
This fails with the following error:
Working Directory:
The working directory you entered does not exist. Please enter a valid working directory.
Same failure pretty much if I try to use a macro int he Working directory text field.
Well, that is a let down.
So I tried to use environment variables. They didn’t work either.
Start external program: “%USERPROFILE%\My Documents\My Project\Install\Program.exe”
That wasn’t a good solution anyway, cause I want it to work whether copied to a Desktop or a D: drive or whatever.
Well, I loaded up Process Monitor for Sysinterals Suite and checked where we look. I configured it to just look for the executable.
Start external program: Program.exe
Turns out we check for the executable relative to either of two paths:
Ok, so it will check relative to the Project directory without putting in a macro if I open Visual Studio by double-clicking the the solution file. I can work with that.
So if I have an Install directory that contains the Program.exe and if I open Visual Studio by double-clicking the the solution file, I can put this in the Start external program:
Start external program: Install\Program.exe
I left the Working directory blank.
It worked!
To bad if I ever forget to open by double-clicking the the solution file, and I instead use the shortcut it doesn’t work. But no biggie, I can close and re-open correctly.
I thought that if I added a relative path, it would check there. So I should be able to put something like this:
Start external program: Program.exe
Working Directory: Install
But the relative path doesn’t work the same way. Anything put there is only relative to YourProjectDir\bin\debug (or if you are doing a release build, YourProjectDir\bin\release), so this didn’t work.
I tried to use environment variables, but they didn’t work either.
I tried Macros, they didn’t work either.
I tried this:
Start external program: Program.exe
Working Directory: ..\..\..\Install
Nope, that didn’t work.
I loaded up a project with an Install directory and debugging set to run the executable from the install directory. I added this line to the program and put a break point on it:
string workingDirectory = Directory.GetCurrentDirectory();
The working directory appears to remain this:
YourProjectDir\bin\debug\ (or if you are doing a release build, YourProjectDir\bin\release\)
Oh well.
In a few weeks I am going to try Visual Studio 2010 and I will have to check if they improved this.