Archive for May 2010

Old Games…very old…1991…on 5.25" Floppies

Hey all,

Guess what gifts my brother brought me yesterday?  Yes, he cleaned out some old DOS games from his closet.  Some of the games I thoroughly loved:

  • Advanced Dungeons & Dragons’ Eye of the Beholder II – The Legend of Darkmoon
  • Nephi’s Quest – A mormon version of Kings Quest.

Unfortunately my Kings Quest set wasn’t found, though my brother has this if I want it, and Bard’s Tale II wasn’t found.

So I instantly thought of two problems I had to solve:

  1. How to read the 5.25″ floppies
  2. How to get a DOS system that isn’t so fast the games are unplayable.

Reading the 5.25 floppy drives

Yes, they are on 5.25″ floppies.  So after about 20 minutes of looking online for a USB 5.25″ floppy drive, I gave up.

So my options are:

  1. Get an old system with a floppy drive that still works.
  2. Send my floppies to a company that will migrate them to a CD at $5 a floppy.
  3. Find someone who has already moved the software from the floppies…

Yeah, one and two just weren’t for me, so the alternative was my only option.

Alternative to Reading the 5.25 floppy drives

Ok, so I almost gave up, when my decided that some one out that had a copy of the game downloadable right.  I mean, these games are 20 years old.  They are collectable. So somebody has to have them online.  Since I purchased a license in 1991, I thought I would not be breaking any laws downloading them.

Turns out I didn’t really have to worry about legalities and copyrights.

I found this site: http://www.abandonia.com/

Yes, Abandonia is the land of “abandonware”.  According to them, many of these games no longer have a copyright and are free to download, play, distribute, etc…

So I downloaded my Advanced Dungeons & Dragons’ Eye of the Beholder II – The Legend of Darkmoon game immediately.

How to get a DOS system that isn’t so fast the games are unplayable

Well, my first thought was VMWare, but again, Abandonia helped me out here.  There is a DOS Emulator called DOS Box.

I installed DOS Box on my Windows 7 box at home, with worry that it wouldn’t work well on Windows 7 64 bit, but to  my surprise, it worked well.

I do want to find a way to make the screen bigger.  And it would be cool to have a DOS VM along with DOS Box to test if it is better or worse, but hey this is sufficient for now.

Other Abandoned Games

There were many other abandoned games, such as the first Eye of the Beholder game as well as Eye of the Beholder III.  Also, Bards Tale I, II, III, and hundreds more.

So if you are looking for a blast from the past with one of your favorite games, check it out.

Changing the prop snippet for creating a Property in C#

Ok, so it is very common for the c# member variables to start with either an _ (underscore) or an m.  So when creating a property, you can save a lot of time by changing it to assume this as well.

For example, your class may look as follows:

namespace AgentConfigurationPlugin
{
    public class Class1
    {
        #region Member Variables
        String _MemberString;
        int _MemberInt;
        #endregion

        #region Constructors

        /*
		 * The default constructor
 		 */
        public Class1()
        {
        }

        #endregion

        #region Properties
        public String MemberString
        {
            get { return _MemberString; }
            set { _MemberString = value; }
        }

        public int Memberint
        {
            get { return _MemberInt; }
            set { _MemberInt = value; }
        }
        #endregion
    }
}

Note: I use the _ character even though it is hard to type (being up to the right of my pinky finger), so if you prefer, use the letter “m”, which is easy to type (being just below my pointer finger) and it also stands for “member variable”.

        #region Member Variables
        String mMemberString;
        int mMemberInt;
        #endregion

Anyway, whether it is an “m” or “_” or any other character, it is common to prefix member variables. So it would be useful if the property snippet assumed that prefix character as well.

The default snippet for creating a Property is located here:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC#\Snippets\1033\Visual C#\prop.snippet

The contents looks as follows.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>prop</Title>
			<Shortcut>prop</Shortcut>
			<Description>Code snippet for an automatically implemented property</Description>
			<Author>Microsoft Corporation</Author>
			<SnippetTypes>
				<SnippetType>Expansion</SnippetType>
			</SnippetTypes>
		</Header>
		<Snippet>
			<Declarations>
				<Literal>
					<ID>type</ID>
					<ToolTip>Property type</ToolTip>
					<Default>int</Default>
				</Literal>
				<Literal>
					<ID>property</ID>
					<ToolTip>Property name</ToolTip>
					<Default>MyProperty</Default>
				</Literal>
			</Declarations>
			<Code Language="csharp"><![CDATA[public $type$ $property$ { get; set; }$end$]]>
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>

Change it to be like this:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>prop</Title>
			<Shortcut>prop</Shortcut>
			<Description>Code snippet for an automatically implemented property</Description>
			<Author>Microsoft Corporation</Author>
			<SnippetTypes>
				<SnippetType>Expansion</SnippetType>
			</SnippetTypes>
		</Header>
		<Snippet>
			<Declarations>
				<Literal>
					<ID>type</ID>
					<ToolTip>Property type</ToolTip>
					<Default>int</Default>
				</Literal>
				<Literal>
					<ID>property</ID>
					<ToolTip>Property name</ToolTip>
					<Default>MyProperty</Default>
				</Literal>
			</Declarations>
			<Code Language="csharp"><![CDATA[public $type$ $property$
		{
    			get { return _$property$; }
    			set { _$property$ = value; }
		}
$end$]]>
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>

The key section that fixes this is:

			<Code Language="csharp"><![CDATA[public $type$ $property$
		{
    			get { return _$property$; }
    			set { _$property$ = value; }
		}
$end$]]>

Or if you use “m” instead of “_” as I do, of course you would replace the “_” with an “m”.

			<Code Language="csharp"><![CDATA[public $type$ $property$
		{
    			get { return m$property$; }
    			set { m$property$ = value; }
		}
$end$]]>

Now when you create a member variable and then a property that matches it exactly except for the prefix character, the works is done for you, making you a more efficient programmer.

You may want to change the propg snippet as well.


Copyright ® Rhyous.com – Linking to this page 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.

How to query a SQL database in C#?

How to query a SQL database in C#? or How to execute a database query against a database in C#?

Having used other languages where this is much simpler, I was surprised at how “not simple” this was in C#. I expected it to be a little more complex than in some scripting language such as PHP, but it was way more complex.

It is nice to run the Query and store the results in a DataTable, so that is what my example shows.

There are a few simple steps to remember.

  1. Create a String to hold the database connection string.
    (Note: If you don’t know the proper format for a connection string use SqlConnectionBuilder.)
  2. Create a SQL connection object.
  3. Open the SQL connection.
  4. Create a String to hold the query.
  5. Create a SqlCommand object and pass the constructor the connection string and the query string.
  6. Use the above SqlCommand object to create a SqlDataReader object.
  7. Create a DataTable object to hold all the data returned by the query.
  8. Use the DataTable.Load(SqlDataReader) function to put the results of the query into a DataTable.
  9. Do something with the data in your DataTable here. For example, it is common to use a foreach loop to do something with each row.
  10. Close the SQL connection.

Here is how I do it:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace CountRows
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a String to hold the database connection string.
            // NOTE: Put in a real database connection string here or runtime won't work
            string sdwConnectionString = @"Data Source = ServerName; user id=UserName; password=P@sswd!; Initial Catalog = DatabaseName;";

            // Create a connection
            SqlConnection sdwDBConnection = new SqlConnection(sdwConnectionString);

            // Open the connection
            sdwDBConnection.Open();

            // Create a String to hold the query.
            string query = "SELECT * FROM MyTable";

            // Create a SqlCommand object and pass the constructor the connection string and the query string.
            SqlCommand queryCommand = new SqlCommand(query, sdwDBConnection);

            // Use the above SqlCommand object to create a SqlDataReader object.
            SqlDataReader queryCommandReader = queryCommand.ExecuteReader();

            // Create a DataTable object to hold all the data returned by the query.
            DataTable dataTable = new DataTable();

            // Use the DataTable.Load(SqlDataReader) function to put the results of the query into a DataTable.
            dataTable.Load(queryCommandReader);

            // Example 1 - Print your  Column Headers
            String columns = string.Empty;
            foreach (DataColumn column in dataTable.Columns)
            {
                columns += column.ColumnName + " | ";
            }
            Console.WriteLine(columns);

            // Example 2 - Print the first 10 row of data
            int topRows = 10;
            for (int i = 0; i < topRows; i++)
            {
                String rowText = string.Empty;
                foreach (DataColumn column in dataTable.Columns)
                {
                    rowText += dataTable.Rows[i][column.ColumnName] + " | ";
                }
                Console.WriteLine(rowText);
            }

            // Close the connection
            sdwDBConnection.Close();
        }
    }
}

So now the results are stored in a DataTable.

You can now access each row of data using the DataTable.Rows collection.

 

Return to ADO.NET and Database with C#

NSIS or WiX?

Hello everyone,

I want to do a quick comparison of NSIS and WiX.  Of course, NSIS creates and executable and WiX creates an MSI, so there will have to be some discussion about whether there really are any benefits to an MSI over an EXE installer.

As many of you know, I work for LANDesk.  In 2008/2009 I developed a plugin for my company’s software.  I built the plugin in C#.  I used Visual Studio to create the plugin.

I wanted an installer that created the install package whenever ran a build in Visual Studio.

I succeeded in doing this using NSIS (Nullsoft Scriptable Install System).

Ok, so since I have a nice working solution, I am not going to change my plugin to use a different installer, even if my NSIS and WiX evaluation shows WiX to be better.  However, on future projects where a solution isn’t yet in place, or when recommending  a solution to others, I may decide to use the better one of the two.

P.S. If there is a third installer tool that is free that you think is better, feel free to comment about it.

Also, I obviously bit off more than I can chew with this post, so it is unfinished.  Of course, there is no reason that new experiences can’t lead me to update this or that comments cannot help me finish this.

NSIS (Nullsoft Scriptable Install System)

NSIS is script-based.

See the list of features here:
http://nsis.sourceforge.net/Features

It also has a lot of users.
http://nsis.sourceforge.net/Users

For my plugin, I actually created the .nsi script by hand the first time and thought it decently complex. However, shortly thereafter an Eclipse plugin was created, and I created a sample with the Eclipse plugin and modified it and it is rock solid.

Anyway, now I have a project that included my .nsi file, I was able to use the command line tool, makensis.exe, to run with two parameters: the .nsi file and the output file name.

"C:\Program Files\NSIS\makensis.exe"  "$(ProjectDir)Installer\LANDesk Support Tools.nsi" "$(ProjectDir)Installer\LANDesk Support Tools_Beta_6.exe"

I am extremely happy with NSIS.

I like it for the following features:

  1. It was easy to use (especially with the Eclipse plugin)
  2. It created a small installer.
  3. It runs silently when passed the -S parameter.
  4. There was lots of documentation.
  5. There were plenty of add-on features.
  6. I had the option to include all files in a folder in my installer or specify the files individually (same with the uninstaller).  This is nice because if I create a new file in a folder that is already picked up by the installer, I don’t have to change the installer or uninstaller at all.
  7. Support for other languages was rather easy to add into my installer.
  8. It was simple to integrate with Visual Studio (add a single command in the post-build section).
  9. Notepad++ has colored syntax for it (though unfortunately Visual Studio does not but I was able to change the default tool to open it with to be Notepad++)
  10. It has an intuitive method for creating Install Sections.
  11. I can provide my installer script open source and anyone who wants to can edit and rebuild the installers
  12. The NSIS community is huge.
  13. You don’t need to be a developer to learn to use NSIS (I gave it to two non-developers and they had solutions in little time (less than two days of work).

Some Negatives…

  1. I couldn’t quickly find a way to automate the installer with a progress bar, only completely silent.

Windows Installer XML (WiX) toolset

Ok. So I’ll be honest.  I am not on the MSI bandwagon.  What features does an MSI really give me.  I find that most people say the prefer an MSI when when pinned down, they are using basic features that NSIS provides ten times easier and when they need a more complex feature, they are writing a custom action and adding it to the MSI which is not any better than adding a custom action to an NSIS installer.

I hear arguments about it being easier to push and MSI with Active Directory, but if you can’t push a .exe with a /S parameter just as easily with Active Directory, you are probably not a very versatile AD administrator. Not to mention AD is not a very good software distribution tool to begin with. Most Desktop Management tools, such as LANDesk, are much better for the job. Besides, LANDesk and the competitors all push EXEs just fine and just as easily as they push MSIs, so the whole MSI vs. EXE is just not really a big deal like some may have you believe.

The one big deal is that MSI is a standard and so every MSI will have some default features.  These are quite good:

  1. Mostly the same command line parameters for all MSI files everywhere (though you can add more and man properties can be changed with command line too)
  2. The ability to change a property in the command line.
  3. The ability to change a lot of properties in a transform file and call the MSI with the transform file.

But are those features really an improvement on NSIS.  For example, NSIS uses the /S switch to silence and install, which is just as easy as use the /q switch for an MSI and actually a lot of installers use /S so it is very common.

Is it really easier to create a property in an MSI than to just add a supported command line parameter in an NSIS installer.  Maybe not.  However, if a public property exists, a user can change it even it the developers didn’t really know a customer would want to do that.  With NSIS, there is no such ability.

Some negatives

  1. Documentation is scarce and when it is there is scattered.
  2. Most large installers cannot be completed with an MSI and end up wrapped up in a .EXE anyway and then it is harder to pass parameters to the MSI because you have to use the /v switch and quoting becomes and issue.
  3. Development is difficult and has a high learning curve (yet again, the scattered and scarce documentation compounds this problem)
  4. You pretty much have to be a developer to make MSIs and this doesn’t change just because you use WiX (I couldn’t hand WiX to someone and expect a working installer in as little as two days as I did with NSIS)

Building an Installer

Ok, so lets choose some key general features and decide a winner.

Ease of use

I have to say that the well documented and large community base NSIS has, added to the fact that you don’t have to be a developer to use it, makes it a clear winner of the ease of use category.

Winner: NSIS

Customizable

To be determined…

Language Support

To be determined…

Maintainability/Scalability

To be determined…

Using the Installer

Lets pick out some key features for an end user.  Which installer is better for them?

End User Ease of use

To be determined…

Speed of Installer

To be determined…

Enterprise Features

Lets talk about enterprise features and pick a winner for those features too.

There are two key features that an Enterprise needs an installer to support:

  1. Automated installation
  2. Silent installations

No, these are not the same.  Technically a silent installation is an Automated installation, but an Automated installation is not necessarily silent.  There may be times when you want to show a progress bar.

Automating the Installation

Both NSIS and WiX can create installers that can be automated.  Both support automation by default. With both, care must be taken with custom actions to make them also automated.

There are times when an install should be automated but show a progress bar and/or a success or failure when finished.  This is common with install on demand or install on first use functions such as LANDesk’s Launch Pad and similar solutions.  The idea is that the icon or shortcut is there, but the software isn’t installed until first use.

MSI files and there for WiX have the following supported functions for automating and Silencing an MSI.

Display Options
	/quiet
		Quiet mode, no user interaction
	/passive
		Unattended mode - progress bar only
	/q[n|b|r|f]
		Sets user interface level
		n - No UI
		b - Basic UI
		r - Reduced UI
		f - Full UI (default)
	/help
		Help information

So I had a hard time finding whether NSIS could do this level of different UI states.  Basically, I found the silent switch, but not a switch for an automated install with progress showing.

Winner: MSI

Silencing the Installation

Both NSIS and WiX can create installers that can be silent.  Both support Silent installs by default.  However, with both, care must be taken with custom actions to make them also silent.

Silencing the install is very common.  When a corporation pushes out software, the last thing they want to do is have the user see it and create a call storm to the help desk just to ask what is going on, and then of course ever subsequent computer problem is related to the newly deployed software in the end user’s mind (even when there is no possible way the new software could have caused them to be missing some emails 🙂

Overall Winner: Tie

How to login to the new Family Search web site for the first time?

Section 1 – How the General Public Obtains an Account?

The Church of Jesus Christ of Latter-day Saints allows anyone with the desire to access and use the genealogical information on their site, even if they have no affiliation with their church at all.  All you have to do is create an account.

Note: If you are a baptized member of The Church of Jesus Christ of Latter-day Saints, go to Section2.

  1. On your computer, open a web browser (Internet Explorer, MSN, Firefox, Safari, Google Chrome, Opera, etc.
  2. Type in http://new.familysearch.org into your browser and press Enter.  This will take you to the front page.
  3. Click the link on the bottom right called: Register for the new Family Search.  This takes you to the next page.
  4. Check the radio button called: FamilySearch Account (for the general public)
  5. Fill out the form.
  6. Click Register.
  7. The next page informs you that a verification email has been sent.
  8. Now go check your email.
  9. You email should have an email address from the LDS Church.Note: If you do not see an email, check your spam folder.
  10. Once you have found the email, click the link in the email to confirm your membership.

You now have a username and password to access this site:

Section 2 – How baptized members obtain an account?

The section explains to members of The Church of Jesus Christ of Latter-day Saints how to access the new Family Search site.  If you are not a member of The Church of Jesus Christ of Latter-day Saints, please go to Section 2.

Note: Download this in a Microsoft Word document with screen shots here: How do church members access the LDS Stake and Ward web site and the new Family Search web site

Members of The Church of Jesus Christ of Latter-day Saints can login to the new Family Search with their account on lds.org that lets them access the LDS Stake and Ward Web Site.  If you already have an account and can already access the LDS Stake and Ward Web Site, then simply go to http://new.familysearch.org and login with the same user name an password.

If you don’t have an account for the LDS Stake and Ward Web Site, then you should obtain one.

Before you begin gather the following two pieces of information:

  • Membership record number
  • Date of Birth

Note: This data is on your Individual Ordinance Summary sheet. If you do not have this sheet, request it from one of the ward clerks.

How to create for yourself a login username and password for both the LDS Stake and Ward Web Site and the new Family Search?

  1. On your computer, open a web browser (Internet Explorer, MSN, Firefox, Safari, Google Chrome, Opera, etc.
  2. Type in http://www.lds.org into your browser and press Enter.  This will take you to the Church’s global home page.The home page is laid out with three columns with many links to resources for you.
  3. On the far right column, click on the link to Stake & Ward Web Sites.
    This opens the Stake and Ward Web Site Sign In page.  This page has two fields for a username and password.
    If you already have a username and password you can login to both LDS.org and new Family Search.
  1. Click on the Obtain an LDS Account link on the left below the login text fields.
    You are taking to the LDS Membership Info page.
  1. Enter your Membership Record number. If you don’t have this, you can ask your bishopric or membership clerk.
  2. Enter your Day of Birth.
  3. Enter the letters you see on the image (security feature).  These letters are difficult to read. Don’t feel bad if you get them wrong once or twice, as everyone usually does.
  4. Click Next Step.  It tries to detect who you are based on membership record information.
  5. Click Yes if it is you.
  6. The next screen has a form where it prompts for your email address.
  7. Enter your email address twice as shown.
  8. Scroll down.
  9. Provide a Username and a password. Please store this information so you do not forget it.
  10. Click Next Step.
  11. Now go check your email.
  12. You email should have an email address from the LDS Church.Note: If you do not see an email, check your spam folder.
  13. Once you have found the email, click the link in the email to confirm your membership.

You now have a username and password to access these sites:

Connecting to Active Directory with Kerberos on FreeBSD

So, I am trying to get Active Directory integration with FreeBSD and I have been researching this for a while as I have stated.
http://rhyous.com/2010/01/13/researching-the-process-for-integrating-freebsd-with-active-directory

I don’t have it all integrated yet. I keep running into road blocks.

First, I want to be able to do integration with Kerberos alone.

One part that is really easy is connecting to active directory with kerberos.

Step 1 – Collect Active Directory information.

Active Directory Domain LD.LAB
AD Domain Controller vmdc.ld.lab
Domain Admin user name administrator
Domain Admin password pw

Step 2 – Create the /etc/krb5.conf

Here is mine. Supposedly this is case sensitive, so make sure to match the case.

[libdefaults]
  clockskew = 300
  default_realm = LD.LAB

[realms]
  LD.LAB = {
    kdc = vmdc.ld.lab
    default_domain = LD.LAB
    kpasswd_server = vmdc.ld.lab
  }

[domain_realm]
  .LD.LAB = LD.LAB

Step 3 – Acquiring a ticket

  1. Use kinit and a domain user and password to acquire a certificate.# kinit administratorEnter the password when prompted.
  2. Use klist to list the kerberos tickets.

However, once I have this working, I don’t know how to change authentication using nsswitch.conf and /etc/pam.d/sshd or system to make it work.

I assumed I wouldn’t need to change nsswitch.conf and that for Step 4 I would just have to uncomment the pam_krb5.so lines in the the /etc/pam.d/sshd and /etc/pam.d/system but unfortunately, that isn’t enough.  Authentication is not working.

I can’t seem to find much documentation on pam and kerberos in FreeBSD.  I have tried to add “debug” to the lines in the /etc/pam.d/sshd and /etc/pam.d/system but if that is adding more logging then I am not seeing it.