Avoiding the MSVCR100.dll, MSVCP100D.dll, or MSVCR100D.dll is missing error (Also MSVCR110.dll, MSVCR120.dll, MSVCR140.dll)

Note: This also applies to newer MSVCR110.dll, MSVCR120.dll and MSVCR140.dll.

MSVCR100.dll

This msvcr100.dll is the Microsoft Visual C++ Redistributable dll that is needed for projects built with Visual Studio 2010. The dll letters spell this out.

MS = Microsoft
V = Visual
C = C program language
R = Run-time
100 = Version

If you create a C++ project in Visual Studio 2010, this file is probably needed.

MSVCP100.dll

This msvcp100.dll is the Microsoft Visual C++ Redistributable dll that is needed for projects built with Visual Studio 2010. The dll letters spell this out.

MS = Microsoft
V = Visual
CP = C++
100 = version

If you create a C++ project in Visual Studio 2010, this file is probably needed.

MSVCR100D.dll

The MSVCR100D.dll is almost the exact same file only the D at the end stands for Debug. This file has debugging enabled and is not considered redistributable.

Why the error?

Ok, so recently I switched to Visual Studio 2010.  I had a C++ application that worked perfectly in Visual Studio 2008.  Once I compiled it with Visual Studio 2010 and ran it on a clean 2008 server (fully patched but otherwise clean), it failed to run with the following error.

TestWin32.exe – System Error

The program can’t start because MSVCR100.dll is missing from your computer. Try reinstalling the program to fix this problem.

Here is the screen shot:

msvcr100.dll

The same things happens with the debug version of the file, only it is a the debug version of the same DLL as noted by the fact that the DLL name ends with D.

Autorun – System Error

The program can’t start because MSVCR100.dll is missing from your computer. Try reinstalling the program to fix this problem.

The screen shot is identical except for the D in the dll name.

msvcr100d.dll

I create a new project in Visual Studio 2010 using the project type of C++ Win32 Project and without making a single change to the default project, I built the file and tested it on my clean machine and the same issue occurred.

So obviously that is not acceptable.  It seems like this should just not happen by default, but unfortunately it does.

Solution

It was actually really easy to resolve for my one project.

Here is what I did.

You can solve this any of the following ways:

  1. Statically link to the dll files so they are compiled into my executable instead of referenced as separate dll files.
  2. Included the dll in the same directory as the exe (I actually didn’t try this but I assume it would work).
  3. Forced everyone to install the VC++ Runtime Redistributable before running the app.

The first option seems the most stable and robust and easiest for a single executable. So that is the one I am going to use.

The second option doesn’t really make sense to me and I would probably never do it. Maybe if I had dozens of executable files that all required the same DLL and I didn’t have an installer, and I wanted to conserve size, which probably wouldn’t happen for me since I am pretty good at creating a quick installer. Though you might be in this a situation.

The third option would make sense if I was planning on running my executable after an install. During the install I could include the VC++ Runtime Redistributable and all would be fine.

Statically Linking the DLLs

Make sure you resolve it for both Release and Debug. The steps are slightly different.

Release

  1. In Visual Studio, I went to the project Properties.
  2. I changed my Configuration to Release.
  3. I went under Configuration Properties | C/C++ | Code Generation
  4. Look at the Runtime Library setting.  It is set to this: Multi-threaded DLL (/MD)
    Change it to this: Multi-threaded (/MT)
  5. Rebuild.

Debug

Almost exactly the same as release.

  1. In Visual Studio, I went to the project Properties.
  2. I changed my Configuration to Debug.
  3. I went under Configuration Properties | C/C++ | Code Generation
  4. Look at the Runtime Library setting. It is set to this: Multi-threaded Debug DLL (/MDd)
    Change it to this: Multi-threaded Debug (/MTd)
  5. Rebuild the debug

It might be a good idea for me to figure out how to change the project so when I create a new project of this type, those settings are the default.

Install the VC++ Runtime Redistributable

Release

Download the appropriate version of VC++ Runtime Redistributable:

File Version VC++ Runtime Version
MSVCR100.dll Microsoft Visual C++ 2010 Redistributable Package (x86)
MSVCR110.dll Microsoft Visual C++ 2012 Redistributable Package (x86)
MSVCR120.dll Microsoft Visual C++ 2013 Redistributable Package (x86)
MSVCR140.dll Microsoft Visual C++ 2015 Redistributable Package (x86)

Just google these and you will find the download links. Install the correct version and you are good to go.

Debug

If you are missing MSVCR100D.dll, then that is a debug dll and is not part of the free to download Visual C++ Redistributable package. So you pretty much are stuck with copying it from your dev box. Copy it to the C:\Windows\System32 directory. You need admin privileges to do this.

Note: You would never want to redistribute the debug dll anyway.


Using OSQL with Microsoft SQL databases

OSQL basic commands

Logging into a database with osql

c:\> osql -S [servername\instance] -U username [-P password]

Example1: Specifying the user and letting the command line prompt for a password.

c:\> osql -S Core\ldmsdata -U sa
password:

Example2: Specifying the user and the password.

c:\> osql -S ld87\ldmsdata -U sa -P pw

Example3: Using a trusted connection

c:\> osql -E

Show databases

1>
2>
select * from sysdatabases
go

Note: Or to see only the database Name row do the following:

1>
2>
select Name from sysdatabases
go

Creating a database

1>
2>
create database DatabaseName
go

Selecting a database

1>
2>
USE master
go

Drop a database

1>
2>
drop database DatabaseName
go

Show tables

1>
2>
1>
2>
USE DatabaseName
go
select * from INFORMATION_SCHEMA.TABLES
go

Note: Or to see only the Table_Name row do the following:

1>
2>
1>
2>
USE DatabaseName
go
select TABLE_NAME from INFORMATION_SCHEMA.TABLES
go

Drop a table

1>
2>
1>
2>
USE DatabaseName
go
drop table TableName
go

Insert a row into a table

1>
2>
1>
2>
USE DatabaseName
go
INSERT INTO TableName Values(“Column1value”,”Column2value”,”Column3value”)
go

Note: Or to insert by only providing values for a few columns and letting the other columns take the default values. This is useful when the first column is set to AUTO_INCREMENT.

1>
2>
1>
2>
USE DatabaseName
go
INSERT INTO TableName (Col2, Col3) Values(“Column2value”,”Column3value”)
go

Update a value in row of a table

1>
2>
1>
2>
USE DatabaseName
go
UPDATE TableName set ColumnName=’NewValue’ where SomeColumn=’whereValue’
go

Drop a view

1>
2>
1>
2>
USE DatabaseName
go
drop view ViewName
go

Backup a database

1>
2>
BACKUP DATABASE ulddb TO DISK=’c:\path\to\dbbackup.bak’ WITH FORMAT
go

You can do this at the command prompt with one single command:

c:\> osql -S ld87\ldmsdata -U sa -P pw -Q “BACKUP DATABASE ulddb TO DISK=’c:\path\to\dbbackup.bak’ WITH FORMAT”

Change the SA password with one line in a command prompt

c:> osql -E -S localhost\ldmsdata -d ULDDB -Q “sp_password NULL,’P@ssword’,’sa'”

I hope this helps you.

More Information

For more information see the following website:

  1. Administering SQL Server Using osql
  2. osql Utility

How to log all sql statements in Postgresql running on FreeBSD?

Enabling SQL Statement Logging in Postgresql

It is often nice to see what SQL statements an application will run.  Maybe there is a gui app to add a user and you want to script adding one thousand users and you want to make sure you know how users are add.

So in Microsoft SQL Server there is a SQL Profiler tool that will show you all the SQL statements.  However, when using Postgresql on FreeBSD, there is often nothing but the command line.

You can easily have all SQL statements logged to a file in Postgresql on FreeBSD.

Note: I already have a post on Installing and Using Postgresql on FreeBSD.

Logging all SQL statements

Here is how to do it:

Step 1 – Configure the postgresql.conf

  1. Open the postgresql.conf file.
    ee /usr/local/pgsql/data/postgresql.conf
    
  2. Find the log_statement value in the log. Uncomment it and set it to all.
    log_statement = 'all'                   # none, ddl, mod, all
    
  3. Close and save the postgresql.conf file.

Step 2 – Configure the syslog.conf

  1. Open the syslog.conf file.
    ee /etc/syslog.conf
    
  2. Add the following line to the end of the log.
    local0.*                                        /var/log/pgsql.log
    
  3. Close and save the syslog.conf file.

Step 3 – Create the log file

  1. Create the log file.
    touch /var/log/pgsql.log
    
  2. Make the file a little more secure.
    chmod 600 /var/log/pgsql.log
    

Step 4 – Restart Posgresql and Syslog services

  1. Restart the postgresql service.
    /usr/local/etc/rc.d/postgresql restart
    
  2. Or in FreeBSD 8.1 and later, you can use this syntax.

    service postgresql restart
    
  3. Restart the syslogd service.
    /etc/rc.d/syslogd restart
    

    Or in FreeBSD 8.1 and later, you can use this syntax.

    service syslogd restart
    

Ok, now you should be able to capture the sql statements.  Here is a log entry from my /var/log/pgsql.log.

Sep  9 22:10:26 FBSD81 postgres[18507]: [5-1] LOG:  statement: select * from "Member";

Logging the time it takes to execute the SQL statement

Ok, this assumes you have already done the steps above.

Step 1 – Configure the postgresql.conf

  1. Open the postgresql.conf file.
    ee /usr/local/pgsql/data/postgresql.conf
    
  2. Find the log_min_duration_statement value in the log. Uncomment this line and set it to zero.
    log_min_duration_statement = 0          # -1 is disabled, 0 logs all statements
                                            # and their durations, > 0 logs only
                                            # statements running at least this number
                                            # of milliseconds
    

    NOTE: It is interesting to note that you can have the log_statement value on or off.  So technically, enabling the log_min_duration_statement will also log all SQL statements if it is set to 0.

  3. Close and save the postgresql.conf file.

Step 2 – Restart Posgresql

  1. Restart the postgresql service.
    /usr/local/etc/rc.d/postgresql restart
    
  2. Or in FreeBSD 8.1 and later, you can use this syntax.

    service postgresql restart
    

Ok, now you should be able to capture the sql statements.  Here is a log entry from my /var/log/pgsql.log.

Sep  9 22:26:06 FBSD81 postgres[18759]: [4-1] LOG:  statement: select * from "Member";
Sep  9 22:26:06 FBSD81 postgres[18759]: [5-1] LOG:  duration: 0.957 ms

Logging SQL queries that take too long to execute

If the log_statement value is on.  All SQL

Step 1 – Configure the postgresql.conf

  1. Open the postgresql.conf file.
    ee /usr/local/pgsql/data/postgresql.conf
    
  2. Find the log_min_duration_statement value in the log. Uncomment this line and set it to a value in milisecond.  For example, to log any statement that takes longer than 3 seconds, use 3000.
    log_min_duration_statement = 3000     # -1 is disabled, 0 logs all statements
                                          # and their durations, > 0 logs only
                                          # statements running at least this number
                                          # of milliseconds
    
  3. Find the log_statement value in the log. Comment out the line or set the value to none (or both).
    #log_statement = 'none'                   # none, ddl, mod, all
    
  4. Close and save the postgresql.conf file.

Step 2 – Restart Posgresql

  1. Restart the postgresql service.
    /usr/local/etc/rc.d/postgresql restart
    
  2. Or in FreeBSD 8.1 and later, you can use this syntax.

    service postgresql restart
    

Ok, I don’t really have a SQL statement that will take 3 seconds, so I configured it for 10 milliseconds and I could see that statements that took less than 10 milliseconds were not logged while those that took more were logged.

IMPORTANT! Turn logging off when you are done

Don’t forget to turn this logging off when you are finished as this is a huge performance hit.  Leaving this on is not efficient and can result in slowness.


How to document a function so Visual Studio's Intellisense displays it?

So, when I code, I am usually in Visual Studio and I am used to writing documentation above my functions as follows:

        /*
         * The is SomeFunction that does some action.
         */
        private void SomeFunction(int inSomeValue)
        {
                // write code here
        }

However, it annoys me that this information doesn’t show up in Visual Studio’s Intellisense. So I took time to look up the proper way to make function documentation show up in Intellisense.

It turns out that you can type /// above a function and Visual Studio will automagically populate the markup needed to have your comments show up in intellisense.

        /// <summary>
        ///  The is SomeFunction that does some action.
        /// </summary>
        /// <param name="inSomeValue">Enter an integer as some value here.</param>
        private void SomeFunction(int inSomeValue)
        {
                // write code here
        }

So it seems if you use this syntax, the function documentation will now show up in Visual Studio’s Intellisense.


Drupal, Joomla, WordPress, SilverStripe, or other, which Content Management System (CMS) is best for a BSD user?

Choosing a Content Management System

Ok, so as today, August 26, 2010, my blog is hosted by WordPress.com.  It will be this way for some time.

However, I am probably going to eventually have my own server hosted somewhere. Probably with my brother’s company, Fusion Networks.

So I will probable build a FreeBSD server that will host my site.  At this point, I think I will stop using WordPress and use a different Content Management System.

Content Management Systems Lists

So I went into this having done reasearch before, so I knew what I was getting into.  There are plenty of different Content Management Systems and unfortunately there is no way I could find time to test them all.

Wikipedia had a great list of Content Management Systems.
http://en.wikipedia.org/wiki/List_of_content_management_systems

Ok, now that  you have seen the very large list of Content Management Systems, you realize that I have to narrow my list down without really testing them all.

Narrowing down the list

First, let me document what I would like and see if which fit into the list.  These are not in order of priority, and some are important and some are not.

I want it to

  1. use PHP
  2. have a large community
  3. use a BSD License
  4. use Postgresql (as it is BSD licensed and MySQL is not)
  5. import my existing WordPress blog
  6. have great feature sets
  7. have common plugins
  8. support multiple Blogs with one install
  9. manages website as well as blog
  10. manages multiple sites
  11. have a descent editor
  12. be well documenated

PHP-Based

They have their lists separated  into tables by programming language.  The PHP table has the most options and since I for sure want to use PHP, it is the only table I will focus on.  These tables even lists the license.

However, I did look at the other tables, just in case one was mostly PHP-based but didn’t show up in the PHP list.  For the full PHP list, go here:
http://en.wikipedia.org/wiki/List_of_content_management_systems#PHP_2

Large community

So the big three Content Management Systems seems to be these.  I don’t have any data to back this up.  I think this is just because these three seem to be more mentioned when doing Google searches.

  • Drupal
  • Joomla
  • WordPress

BSD Licensed

However, none of those are BSD Licensed, which I prefer. I am not opposed to GPL or LGPL, but I feel more comfortable with BSD licenses software.

The Content Management Systems that are PHP-based and use the BSD License are these:

Had one of the Big 3 been BSD licensed, my decision would have probably been easy.  However, obviously I am going to have to test some of the three BSD licensed Content Management Systems.

Supports Postgresql

Of the six Content Management Systems listed above, the following support Postgresql.

  • Drupal
  • Serendipity
  • SilverStripe

Can import my WordPress blog

It appears that they all can do this.

I am worried about links, however.  My blog entries often link to each other.  I question whether they do it perfectly.  For example, a link to one of my WordPress blogs might be this:

http://rhyous.com/2010/08/25/freebsd-now-has-the-service-command/

So the link has this format:

http://homepage/YYYY/MM/DD/name-of-blog-entry/

So if I go with something other than WordPress, then after importing my blogs, are all the links going to be broken?

Making the Decision

So here is the rating, after a very small overview of the different CMS web sites, and before verifying their marketing claims.

I am giving 0 to 3 points for each feature. (This is subject to change over time, should I want to come back after the decision and report on something).

Features Worpress Drupal Joomla Serendipity SilverStripe Pimcore
1. PHP-Based 3 3 3 3 3 3
2. Large community 3 3 3 1 1 1
3.BSD License 0 0 0 3 3 3
4. Postgresql Support 0 3 0 3 3 0
5. Imports WordPress 3 1 ? 1 1 ?
6. Great Feature set 3 3 3 1 3 ?
7. Has common plugins 3 3 3 3 2 ?
8. Multiple Blogs 3 3 3 3 2 ?
9. Manages Website as well as blog 3 3 3 0 3 ?
10. Multiple Sites 2 3 ? 0 3 ?
11. Editor 3 3 ? 2 3 ?
12. Documenation 3 3 ? 1 3 ?
Score: 29 31 ? 21 30 ?

Here is what I am going to do:

I am going to build a BSD, Apache, PHP, Postgresl virtual machine and test Drupal and Serendipity to see how the import goes.

Perhaps I will have a follow-up some time because:

  1. I have to test these different CMSes
  2. I am sure there are a dozen other items that should be scored 1-3 that I haven’t thought of.

Serendipity

I started out looking at Serendipity first.

Positives

http://rhyous.wordpress.com/wp-admin/post.php?post=2212&action=edit&message=1
There was a FreeBSD port.

The install was painless.

Negatives

Their web site didn’t seem very good, which is a big turn off for a company that is a CMS.

The links to their Forum on their web site and other pages were broken.  I did find that the forum does exist, so the links are just broken.

I tried to sign up for the Forum to report the broken links.  I registered, but was supposed to be sent a confirmation email, which I never received, even after re-requesting it, so I have never reported the broken links.  They are still broken a day later. Also, there appear to only be a handful of people on their forums at any given time. Both suggest they have a small community.

I couldn’t figure out how to design my home page. It seemed the blog was my home page.  I couldn’t figure out how to move my blog entries to a different page.

Result

If you want one blog and nothing else, this would work for you.

I need more. I stopped trying and have dropped Serendipity from the list.

SilverStripe

I looked at SilverStripe second and I way more pleased with its feature set.

Positives

Though I had some install problems, I found solutions on their forums.

There are a number of theme available for download.

The default web site had some common pages premade:

  • Home
  • About Us
  • Contact Us
  • Page not found

They had both Site Management and Blog management.

There are many extensions: modules, themes, widgets.

Modules include a Blog Modules and Sub-site module, so I could manage multiple sites and multiple blogs.

It is simple to download and install modules.

The user interface is simple and easy to use.

The documentation is sufficient.

Negatives

I had install/setup problems (that were resolved) by the Forum.  Supposedly they only occur with Postgresql.

Not a lot is included in the default install.

The community is smaller than I would like.

The documentation is only sufficient.

Conclusion

I really like the SilverStripe interface.

It had almost everything I am looking for.  It is BSD Licensed.  It supports Postgresql.

It is a Content Management System first, and has modules to add to it.  There a blog module, a multi-site module, which really interested me.

However, while it has a module to import a WordPress xml, I have yet to get it to work.  That is something I can live with, but I would prefer it to work.

Drupal

Positives

It has many features, and any feature it lacks is pretty much filled by an add-on or widget.

The documentations seems thorough.

The community looks to be large.

Negatives

I had to install a different version of wordpress to support multiple blogs.

It is GPL instead of BSD Licensed.

The admin site seemed rather overwhelming. There were almost too many options.

Conclusion

If this were BSD licensed, it would be my pick.  It seems great.

WordPress

Positives

It is popular and familiar.  The most common platform of the blogging world.

It has many features, and any feature it lacks is pretty much filled by an add-on or widget.

Migrating from my existing WordPress blog is flawless.

The community is huge.

The documentation is a plenty.

Negatives

It doesn’t support Postgresql.

It is GPL instead of BSD Licensed.

Joomla

I almost feel like apologizing to Joomla.  I had two BSD servers, one with FreeBSD, Apache, PHP, MySQL where I installed WordPress a year ago for testing.  I have another brand new server with FreeBSD, Apache, PHP, and Postgresql where I tested all the postgresql capable CRMs.  However, I installed Joomla to the wordpress server and it just didn’t work.  The page was blank.  I actually think there was a php error, not a Joomla error.

Unfortunately, Joomla doesn’t support postgresql, it isn’t BSD licensed.  I did research and it appears like it would score high with WordPress, Drupal, and Silverstripe, but I can’t really see how it would be any better than Drupal, or Silverstripe so I really had to cut it loose.  Lets be honest.  As a BSD users, it was beaten out by Drupal and Silverstripe for the same reason I am looking to replace WordPress.  It doesn’t support Postgresql.

Others

There are two other Content Management Systems that I feel are worth mentioning.

Django is also a CMS that is BSD licensed and supports Postgresql. However, it runs on Python, a language which I have occasionally touched but never really developed in.  If you know Python, this might be the choice for you.

Bricolage is also a CMS that is BSD licensed and supports Postgresql. However, it runs on Perl, which I have written a few things with, but not as much as PHP.  If you know Python, this might be the choice for you.

My Decision

I know, you all want to know which I chose to use.

Drumb roll please….

I have chosen…

But don’t expect my blog to move to Silverstripe tomorrow.  It move slowly with things like this.  It could take months or get delayed for a year.

Anyone who might choose a CMS differently would be completely happy with any of the others they evaluate and feel meets their needs.  I am not saying I chose the best.  I am saying I chose the best for my needs.  Hopefully, you know your needs and this will help you choose the best Content Management System for your needs.


The Utah Open Source Conference – October 7th, 8th, and 9th

Hey all,

I am going to be attending the Utah Open Source Conference and manning the BSD table for maybe part of or the majority of the time.

Here are some details:

There will probably be some BSD swag if you attend, courtesy of iXsystems and PC-BSD.

You can schedule a BSD Certification exam if you desire.

Hope all you computer geeks in Utah can attend.

If you aren’t into Open Source, then then this conference is especially for you. If you don’t know much about Open Source, then you are missing out.

If you are into Open Source, then you probably know about this conference already.


Installing and Using Postgresql on FreeBSD

Postrgesql is an excellent alternate to MySQL.

It is BSD Licensed instead of GPL, which is especially more attractive if you need to distribute the database software.  In fact, if you are reselling a product, and paying a license fee to MySQL you probably should save your company the money and move to Postgresql.  LANDesk, the company I work for, had just such an experience with our Management Gateway device.

Setting up FreeBSD

Ok, so I already have a post on this here:

How do I install FreeBSD?

Also, make sure to download ports.

What are the first commands I run after installing FreeBSD

Installing Postgresql on FreeBSD

As always, installing software on FreeBSD is simple using the ports system.

#
#
cd /usr/ports/databases/postgresql84-server
make WITH_OPTIMIZED_CFLAGS=true BATCH=yes install clean

Post-installation Setup

There a few post-installation steps.

Initialize the database

# /usr/local/etc/rc.d/postgresql initdb

Or starting with FreeBSD 8.1, you can now run this command:

# service postgresql initdb

Make any changes to the postgresql.conf

The postgresql.conf is located in /usr/local/pgsql/data.

Open the file and read through it and make any desired changes.

Common Changes

Here are two common changes.

Enabled remote connections

If the database is to be accessed by the network, then you should at least uncomment the setting #listen_addresses = 'localhost' and change it to listen_addresses = '*'.

Changing the default TCP Port

Uncomment the setting #port = 5432 and change the port number to the desired value.

Configure password authentication

  1. Change to the /usr/local/etc/pgsql/data directory.
  2. Edit the pg_hba.conf and change the default authentication method to something more secure, such as md5.
    # TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD# &quot;local&quot; is for Unix domain socket connections only
    local   all         all                               md5
    # IPv4 local connections:
    host    all         all         127.0.0.1/32          md5
    # IPv6 local connections:
    host    all         all         ::1/128               md5
    

Configure the postgresql server service to start on reboot

Add the string postgresql_enable="YES" to /etc/rc.conf.

# echo ‘postgresql_enable=”YES”‘ >> /etc/rc.conf

Creating a Database

To create a database, su to pgsql and run createdb.

#
$
su pgsql
createdb MyDBName

Note: Similarly, use dropdb to drop a database.

Creating a User or Role

To create a user, su to pgsql and run createuser.

#
$
su pgsql
createuser -P

Enter name of role to add: MyUserOrRoleName
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) y

If you are not using password authentication, then you can exclude the -P.

Using psql client

A simple way to connect to postgresql is using the shell-based client, psql.

Connecting

To connect, use the following command.

$ psql MyDBName

MyDBName-#

You are now at the psql prompt.

Connecting as a different user

To connect, use the following command.

$ psql MyDBName MyUserOrRoleName

MyDBName-#

You are now at the psql prompt.

Changing a a User or Role Password

To change a password, use the following syntax.

MyDBName-# alter role pgsql with password ‘pw’;

Show Databases

To show database, simply type \l, (which is the lowercase letter L not the number 1) which is short hand in psql for this query:
SELECT datname FROM pg_database;

MyDBName-# \l

Show Tables

To show tables in the current database, simply type \d, which is short hand in psql for this query:
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';

MyDBName-# \d

Show Tables

To show columns of a table in the current database, simply type \d table, which is short hand in psql for this query:
SELECT column_name FROM information_schema.columns WHERE table_name ='table';

MyDBName-# \d MyTableName

Creating a Table

To create a table, use the following syntax:

MyDBName-# CREATE TABLE Users (
FirstName text,
LastName text,
DateOfBirth date
);

Inserting data into a Table

To insert data into a table, use the following syntax:

MyDBName-# CREATE TABLE Users (
UserId serial,
FirstName text,
LastName text,
DateOfBirth date
);

Ok, from here you should be able to start figuring everything out on your own.

Resources:
http://www.postgresql.org/docs/8.4/interactive/index.html


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.


FreeBSD now has the service command

So I was reading the FreeBSD 8.1 release notes today and noticed that FreeBSD added the services command.

Basically there are a lot of start up scripts in /etc/rc.d that are enabled in the /etc/rc.conf.  However, if you wanted to restart them, you always had to run /etc/rc.d/someservice start.  And if you didn’t remember the exact service syntax, you had to ls the dir.

Anyway, now with the services command, you can simple type this:

service someservice start

service someservice restart

I am familiar with this already as that is how Red Hat gets things done with their services.

If it was just /etc/rc.d scripts that this worked for, then this command doesn’t really save much typing. But it also works for installed services or services from ports. The start up scripts for services for ports are in /usr/local/etc/rc.d.

So after installing something you can use the simple service command to start it, instead of typing in the longer path.

Of course, service has other features, such as listing the start up scripts in the two directories: /etc/rc.d and /usr/local/etc/rc.d

Take a second to run man service to see all its options.


Comments on 7 Reasons to Switch to the Dvorak Keyboard Layout

Ok, so I recently read an article that had seven resason to switch to the Dvorak keyboard layout

I will list the authors reasons and comment on them.  Please see the original post for the complete detail:
7 Reasons to Switch to the Dvorak Keyboard Layout

Reason 1 -QWERTY was designed for the typewriter, not the typist.

This is true.  But I am not a typewriter or a typist.  I am a developer.  While the Dvorak keyboard is probably faster for a typist that writes normal words and text, is it faster for a computer programmer ? Maybe.  Is it the fastest possible layout for a programmer?  I doubt it.

Also, a semicolon is common for programming languages and in QWERTY, it is on the home row.  In Dvorak, it is not.  Dvorak makes some common programming keys harder to reach.

So no, Dvorak was not designed for a programmer.

There is a programming version of the Dvorak layout: Programmer Dvorak layout.

This may address some of these issues.  Is that what the article intends? I don’t think so, because I couldn’t find an option on Windows 7 64 bit to use that layout.

Reason 2. Dvorak increases your speed.

Also, you forget about people who don’t really type that much, or that type the special keys of a programming language often.  Think of all the keyboard shortcuts.  CTRL + C, CTRL + P, CTRL + A.  WIN + E, WIN + D, etc…

Look at this quote from the article:

70% of keystrokes are on the home row; 22%, on the top row; 8%, on the bottom.

Does a programming language have the same the percentages?

So really, shouldn’t there be a separate keyboard layout for programmers than for typist?

if (keyboardLayout == sucks)
{
    DoChangeLayout();
    DoLearnKnewLayout();
}
else
{
    IgnoreTheSuck();
}

Reason 3 – Dvorak lessens your mistakes.

I have to agree, that having the most common keys on the home row might decrease mistakes.

However, many of my mistakes are usually due to the really far away keys, such as _ – + | \ } ] ~ ` ^ and both layouts leave those characters in the same place.  What if there was another button, like Caps Lock or SHIFT or CTRL or ALT, that moved those characters to the home row.

Reason 4. Dvorak is more comfortable and better for your health.

I think I agree with this.  I wonder if people with Carpal Tunnel Syndrome could be prevented or lessened by this.

I do have to say that a natural keyboard helps but is not enough.

A better shape for a keyboard would be if the keyboard were cut in half and the two piece leaned together like this: /\

Or maybe some type of ball with keys:  ( )

Reason 5. Switching to Dvorak is easier than ever.

Really.  I think it is harder than ever.  I agree that some of the features mentioned make it easier in ways, but other features, such as keyboard shortcuts make it harder. When I switch to Dvorak, does my keyboard shortcut keys switch too?  Unfortunately no, they don’t.

Until that is fixed, it is going to be difficult to move.

Also, I have used QWERTY since i was 7.  Yes, in 1983 my family had a computer and a digital typewriter. Both were QWERTY.  So after 26 years of using QWERTY, it is not easy to switch to anything.

Everybody has a computer.  Sometimes you use a friends computer. Of course they use QWERTY, so you have to remember how to use that.  Or if you have to fix someone’s computer.  Or worse, you remote control someone who is using QWERTY but you are using Dvorak.  How would that work?

Reason 6. Dvorak is cool.

Is this really a reason?  This is an opinion.

And this quote is just silly.

You’ll also be in the company of some cool people, including Bram Cohen, inventor of BitTorrent; Matt Mullenweg, lead developer of WordPress; and Barbara Blackburn, world’s fastest typist.

Yeah, but if I use QWERTY, the company is even that much better since it encompasses 99.99999% of the English typing world, right?

Reason 7. Using Dvorak is a noble cause.

Ok, so digging wells in Africa is a noble cause.  Manning a soup kitchen in your spare time is a noble cause.  But using a different type of keyboard than everyone else is just annoying. Sorry.

My Experience

Ok, sorry to rag on this article, but I tried Dvorak for a while and I am less than impressed.

Lets get down to what we really want.  We want to be faster at typing whatever it is we type. We want to have more comfort when we type.

My Keyboard Gripes

  1. Why is the spacebar so frieking wide. Why can’t it be half the size, so my thumbs can be used to push CTRL or ALT or the Windows key or SHIFT. Why do both my thumbs need access to the space bar?
  2. My hands do not fit well on a keyboard. Not even an ergonomic or natural keyboard. A better shape for a keyboard would be if the keyboard were cut in half and the two piece leaned together like this: /\I can’t find one.
  3. There should be a mouse pad, like on laptops, but directly below the space bar. Why do I have to have to separate interface devices that are both inefficient.  Taking my right hand away from the keyboard to use the mouse is one of the biggest faults of keyboards.Oh…there is: http://www.newegg.com/Product/Product.aspx?Item=N82E16823166076&nm_mc=OTC-Froogle&cm_mmc=OTC-Froogle-_-Keyboards-_-Adesso-_-23166076

    But is there an ergonomic version? I guess so.
    http://www.newegg.com/Product/Product.aspx?Item=N82E16823166028

    But they are expensive.

  4. As a programmer, I want to be able to have one key for these three keys: ();Most the improvements in speed for programming are in the IDEs and so the keyboard layout is becoming insignificant.  Especially with IDEs with Intellisense.

Maybe you like Dvorak and maybe you have never heard of it.  Either way.

All right.  I am done rambling.


A windows annoyance: Copying folders with thousands of files

Ok, so have you ever started to copy a folder from the network and had it crash on you? And the folder of course has hundreds of subfolders and thousands of files, so you have to copy it again.

Why doesn’t windows handle this better. Why don’t I get a nice prompt that says: The copy failed…do you want to try again?  Yes / No

If i drag the folder over again, it seems to copy everything and give me annoying prompts for whether I want to overwrite the folder and the prompts can be endless.

I know I could avoid this by zipping the directory first, but really, zipping 1.5 GB of thousands of files takes even longer.

Sorry to drop a complaint today, but restarting massive folder transfers seems like an area where Microsoft has really not put any effort.

I will say that on my Windows 7 64 bit box, the number of annoying prompts to copy and replace were far less if I checked the box to not copy, so that is a positive.


Why my categories span such broad topics?

Hey all,

I recently noticed I was added to another blogs blogroll.  It was funny what he said:

Rhyous’s 127.0.0.1 or ::1 covers an interesting mix of FreeBSD, PC-BSD, C# and even Windows 7 issues. An unusual mix…

Well, here is the deal.

  1. One of my hobbies is learning about open source.  My operating system of choice is FreeBSD and I am partial to PC-BSD for desktop use as well.  So naturally, I am going to post about that.
  2. However, I work for LANDesk as a Developer (previously I was a Level III support engineer), using primarily C#.  We have a lot of legacy C++ code as well.  LANDesk is mostly a Microsoft shop.  Our server software runs on Windows Servers only and we support MS SQL and Oracle back ends.  Our agent goes to Windows, Mac, Linux, and some Unix devices.  Yes, I have had the Linux version of the LANDesk agent running on FreeBSD using Linux Emulation.  I am probably going to post more on WIX now as I am on a development team that deals with our product installation.
  3. I am also just a techie in the first place so I have lots of tech interests outside my career and my hobbies.
  4. I now realize the importance of experience and I want to increase my experience and make my experience more meaningful by retaining it.  I used to do support for Nortel Networks equipment before coming to LANDesk so I have intense networking skills that are uncommon among developers. I also have 10+ years of support and troubleshooting which gives my a unique perspective.  The more you do something the easier it is.  I have a lot of experiences where some support guys were working on something for days and I walk over and solve the problem in five minutes.  It is something that comes with 10+ years experience or troubleshooting. No, that is not unique to me.  LANDesk tech support engineers are some of the best out there and there are a number of guys that can do that here.  But all of them have about 10+ years experience.
  5. I help others with their computer issues which often leads to figuring things out.

My one regret is that I didn’t start my blog in 10+ years ago.  Think of the content I would have had.

So anytime I have to look something up or research a problem and the first or second Google link is not an exact answer, I am going to blog about it, whatever the topic may be.


Netcraft: Most Reliable Hosting Company Sites in July 2010

Netcraft has posted the most reliable hosting companies and of the top ten, five are using FreeBSD.
Most Reliable Hosting Company Sites in July 2010

I was informed about this by an email to the FreeBSD advocacy mailing list: advocacy@freebsd.org

Seems that this is something worth pointing out to companies who ask whether to use Windows, Linux, or BSD.


A DottedDecimal Object

Ok, so there are a lot of objects that are represented in dotted decimal notation.  The most common are versions and IP addresses.

Version 3.1.9.27

IP Address: 192.168.0.1

I have to wonder why I have never found in the Standard C++ Library, or in the C# libraries an object for these?  Are they there and I just don’t know how to find them.  It seems they are always just treated as Strings and this makes no sense to me.  Also these seem common enough that they should be standard objects in all languages.

Which IP Address is greater?

192.168.0.2
192.168.0.100

Well, since these are usually treated as strings, then .2 is greater than .100.  Unfortunately that is not correct.  We all know that .100 is greater.

So I created some objects that overload the >,>=,<=,<,==,!= functions.  Maybe these are completely finished, but hey, they are a start. I created C# and C++ versions.  The C# is first, scroll down if you are looking for C++ versions. This is really great for versions that can be different.  However, I think that for an IP address object, that because it is limited to three characters and each section is one byte and only can be seen as 0-255, that a very efficient object could be created, but for now, a more generic DottedDecimal object is fine, though if you had a large list of IP addresses, you may want that efficiency. Also, this is only tested with digits 0-9, not hex, so there is plenty more work to do, but usually version are just 0-9, though sometimes people throw in an "a" or "b" build such as 1.0.0.1a.  That is not handled yet.  So again, much more work to do.  But for my needs these are more than enough for now. If there are already objects like this that are awesome, efficient, tested, and free, let me know.

C# DottedDecimal object for IP address and Versions

For C#, I implement a lot of interfaces too as you can see in the object.

DottedDecimal.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace DottedDecimalProject
{
    public class DottedDecimal
        : IComparable, IComparable<DottedDecimal>, IComparable<String>, ICloneable, IEquatable<string>, IEquatable<DottedDecimal>
    {
        #region Member Variables
        List<long> _DecimalValues;
        CompareDirection _CompareDirection = CompareDirection.LeftToRight;
        #endregion

        #region Constructors
        /*
         * The default constuctor.
         * The default compare direction is left to right
         * No values are added by default.
         */
        public DottedDecimal()
        {
        }

        /*
         * This constructor takes a string in this regex format
         * [0-9]+(\.[0-9])*
         */
        public DottedDecimal(String inDottedDecimalString)
        {
            _DecimalValues = null;
            _DecimalValues = StringToDottedDecimalList(inDottedDecimalString);
        }

        /*
         * This constructor takes two parameters.
         * Parameter 1 is a string in this regex format: [0-9]+(\.[0-9])*
         * Parameter 2 sets the compare direction. See this.Direction.
         */
        public DottedDecimal(String inDottedDecimalString, CompareDirection inCompareDirection)
        {
            _CompareDirection = inCompareDirection;
            _DecimalValues = null;
            _DecimalValues = StringToDottedDecimalList(inDottedDecimalString);
        }
        #endregion

        #region Properties
        /*
         * Returns the dotted decimal object in string format.
         */
        public String DottedDecimalString
        {
            get { return DottedDecimalListToString(); }
            set { _DecimalValues = StringToDottedDecimalList(value); }
        }

        /*
         * The decimal values are stored in order.  If LeftToRight, the left
         * most value is first.  If RightToLeft, the right most value is first.
         */
        public List<long> DecimalValues
        {
            get { return _DecimalValues; }
            set { _DecimalValues = value; }
        }

        /*
         * Determines whether to compare left to right or right to left.
         *
         * LeftToRight - 1.0.0.1 is greater than 1.0.0.0
         *               1.0.10 is greater than 1.0.0.27
         *
         * RightToLeft - 1.0.0.1 is less than 1.0.0.0
         *             - 1.0.10 is less than 1.0.0.27
         */
        public CompareDirection Direction
        {
            get { return _CompareDirection; }
            set
            {
                if (!(this.Direction == value))
                {
                    this._DecimalValues.Reverse();
                }
                _CompareDirection = value;
            }
        }
        #endregion

        #region Functions
        /*
         * Verifies that the CompareDirection values match between two DottedDecimal objects.
         */
        private static bool CompareDirectionsMatch(DottedDecimal left, DottedDecimal right)
        {
            if (left.Direction == right.Direction)
                return true;
            else
                return false;
        }

        /*
         * Overloads the greater than operator (>) to allow for a syntax as follows:
         *
         *      bool b = dd1 > dd2;
         */
        public static bool operator >(DottedDecimal left, DottedDecimal right)
        {
            int count = (left.DecimalValues.Count > right.DecimalValues.Count) ? right.DecimalValues.Count : left.DecimalValues.Count;

            for (int i = 0; i < count; i++)
            {
                // If left side is greater then true;
                if (left.DecimalValues&#91;i&#93; > right.DecimalValues[i])
                {
                    return true;
                }
                // If right side is greater then false;
                if (left.DecimalValues[i] < right.DecimalValues&#91;i&#93;)
                {
                    return false;
                }
                // If it is equal, check the next decimal values over
                if (left.DecimalValues&#91;i&#93; == right.DecimalValues&#91;i&#93;)
                {
                    continue;
                }
            }

            if (left.DecimalValues.Count > right.DecimalValues.Count)
            {
                // If the left side has the same values as the right,
                // but then has more values, true.
                return true;
            }

            if (left.DecimalValues.Count < right.DecimalValues.Count)
            {
                // If the left side has the same values as the right,
                // but then the right side has more values, false.
                return false;
            }
            // If we get here both sides are equals, so false
            return false;
        }

        /*
         * Overloads the less than operator (<) to allow for a syntax as follows:
         *
         *      bool b = dd1 < dd2;
         */
        public static bool operator <(DottedDecimal left, DottedDecimal right)
        {
            int count = (left.DecimalValues.Count > right.DecimalValues.Count) ? right.DecimalValues.Count : left.DecimalValues.Count;
            for (int i = 0; i < count; i++)
            {
                // If right side is greater then true;
                if (left.DecimalValues&#91;i&#93; < right.DecimalValues&#91;i&#93;)
                {
                    return true;
                }
                // If the left is greater then false;
                if (left.DecimalValues&#91;i&#93; > right.DecimalValues[i])
                {
                    return false;
                }
                // If it is equal, check the next decimal values over
                if (left.DecimalValues[i] == right.DecimalValues[i])
                {
                    continue;
                }
            }

            if (left.DecimalValues.Count > right.DecimalValues.Count)
            {
                // If the left side has the same values as the right,
                // but then has more values, false.
                return false;
            }

            if (left.DecimalValues.Count < right.DecimalValues.Count)
            {
                // If the left side has the same values as the right,
                // but then the right side has more values, true.
                return true;
            }
            // If we get here both sides are equals, so false
            return false;
        }

        /*
         * Overloads the equals operator (==) to allow for a syntax as follows:
         *
         *      bool b = dd1 == dd2;
         */
        public static bool operator ==(DottedDecimal left, DottedDecimal right)
        {
            // If there are more values in either side, they aren't equal
            if (!(left.DecimalValues.Count == right.DecimalValues.Count))
            {
                return false;
            }
            for (int i = 0; i < left.DecimalValues.Count; i++)
            {
                // If any one value is not equal, then false
                if (left.DecimalValues&#91;i&#93; != right.DecimalValues&#91;i&#93;)
                {
                    return false;
                }
            }
            // If you get here they are all equal so true
            return true;
        }

        /*
         * Overloads the not equals operator (!=) to allow for a syntax as follows:
         *
         *      bool b = dd1 != dd2;
         */
        public static bool operator !=(DottedDecimal left, DottedDecimal right)
        {
            // If there are more values in either side, they aren't equal
            if (!(left.DecimalValues.Count == right.DecimalValues.Count))
            {
                return true;
            }
            for (int i = 0; i < left.DecimalValues.Count; i++)
            {
                // If any one value is not equal, then true
                if (left.DecimalValues&#91;i&#93; != right.DecimalValues&#91;i&#93;)
                {
                    return true;
                }
            }
            // If you get here they are all equal so false
            return false;
        }

        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override string ToString()
        {
            return DottedDecimalString;
        }

        /*
         * Appends a new string value to the left side of a DottedDecimal object.  Adding "12" to
         * 1.0.0 makes it 1.0.0.12.  Because it is a string, you can also add multiple values at
         * a time so adding the string "12.24" makes 1.0.0.12.24.
         */
        void AddToLeftSide(String inVal)
        {
            foreach (string decimalString in inVal.Split('.'))
            {
                _DecimalValues.Insert(0, Convert.ToInt64(inVal));
            }
        }

        /*
         * Appends a new value to the left side of a DottedDecimal object.  Adding 12 to
         * 1.0.0 makes it 1.0.0.12
         */
        public void AddToLeftSide(long inVal)
        {
            _DecimalValues.Insert(0, inVal);
        }

        /*
         * Appends a new string value to the right side of a DottedDecimal object.  Adding "12" to
         * 1.0.0 makes it 12.1.0.0.  Because it is a string, you can also add multiple values at
         * a time so adding the string "12.24" makes 12.24.1.0.0.
         */
        public void AddToRightSide(String inVal)
        {
            foreach (string decimalString in inVal.Split('.'))
            {
                _DecimalValues.Add(Convert.ToInt64(decimalString));
            }
        }

        /*
         * Appends a new value to the right side of a DottedDecimal object.  Adding 12 to
         * 1.0.0 makes it 12.1.0.0
         */
        public void AddToRightSide(long inVal)
        {
            _DecimalValues.Add(inVal);
        }

        private string DottedDecimalListToString()
        {
            string retVal = "";
            if (this.Direction == CompareDirection.LeftToRight)
            {
                foreach (long l in _DecimalValues)
                {
                    if (!retVal.Equals(""))
                    {
                        retVal += ".";
                    }
                    retVal += l;
                }
            }
            else
            {
                for (int i = _DecimalValues.Count - 1; i >= 0; i--)
                {
                    if (!retVal.Equals(""))
                    {
                        retVal += ".";
                    }
                    retVal += _DecimalValues[i];
                }
            }
            return retVal;
        }

        private List<long> StringToDottedDecimalList(String inString)
        {
            List<long> retList = new List<long>();
            foreach (string decimalString in inString.Split('.'))
            {
                retList.Add(Convert.ToInt64(decimalString));
            }
            if (this.Direction == CompareDirection.RightToLeft)
            {
                retList.Reverse();
            }
            return retList;
        }

        #endregion

        #region Interface Functions

        #region IComparable Members
        public int CompareTo(object inOjbect)
        {
            DottedDecimal dd = (DottedDecimal)inOjbect;
            return CompareTo(dd);
        }
        #endregion

        #region IComparable<DottedDecimal> Members
        public int CompareTo(DottedDecimal inDottedDecimal)
        {
            if (this < inDottedDecimal)
                return -1;
            if (this == inDottedDecimal)
                return 0;
            if (this > inDottedDecimal)
                return 1;
            return -2; // Should never get here.
        }
        #endregion

        #region IComparable<string> Members
        public int CompareTo(string inString)
        {
            DottedDecimal dd = new DottedDecimal(inString);
            return CompareTo(dd);
        }
        #endregion

        #region ICloneable Members
        public object Clone()
        {
            return new DottedDecimal(this.DottedDecimalString, this.Direction);
        }

        #endregion

        #region IEquatable<string> Members
        public bool Equals(string inString)
        {
            DottedDecimal dd = new DottedDecimal(inString);
            return this == dd;
        }

        #endregion
        #region IEquatable<DottedDecimal> Members
        public bool Equals(DottedDecimal inDottedDecimal)
        {
            return this == inDottedDecimal;
        }
        #endregion

        #endregion

        #region Enums
        public enum CompareDirection
        {
            LeftToRight,
            RightToLeft
        }
        #endregion
    }
}

C++ DottedDecimal object for IP address and Versions

I tried to overload the common operators, if there is one you would like overloaded, let me know.

DottedDecimal.h

#pragma once
#include <vector>
#include <iostream>
#include "windows.h"

using namespace std;

class DottedDecimal
{
public:
	// Constructors
	DottedDecimal(); // Default constructor
	DottedDecimal(DottedDecimal & inDottedDecimal); // Copy constructor
	DottedDecimal(string inString);
	DottedDecimal(char * inString);
	DottedDecimal(LPTSTR inString);

	// Destructors
	~DottedDecimal();

	// Public functions
	string GetDottedDecimal();

	template <class T>
	void SetDottedDecimal(const T& t);

	vector<long> GetDecimals();

	// Functions Overloading Operators
	friend ostream &operator<<(ostream & dataStream, DottedDecimal & dd);

	friend bool operator==(DottedDecimal & left, DottedDecimal & right);
	friend bool operator!=(DottedDecimal & left, DottedDecimal & right);

	friend bool operator>(DottedDecimal & left, DottedDecimal & right);
	friend bool operator>=(DottedDecimal & left, DottedDecimal & right);

	friend bool operator<(DottedDecimal & left, DottedDecimal & right);
	friend bool operator<=(DottedDecimal & left, DottedDecimal & right);

private:
	// Member Variables
	vector<long> _decimals;

	// Private Functions
	void StringSplit(string inString, string inDelim, vector<string> * outResults);

	template <class T>
	string AnyTypeToString(const T& t);

	template <class T>
	void StringToAnyType(T& t, std::string inString);
};

DottedDecimal.cpp

#include "StdAfx.h"
#include "DottedDecimal.h"
#include <iostream>
#include <sstream>

using namespace std;

DottedDecimal::DottedDecimal()
{
}

DottedDecimal::DottedDecimal(DottedDecimal & inDottedDecimal)
{
	SetDottedDecimal(inDottedDecimal.GetDottedDecimal());
}

DottedDecimal::DottedDecimal(string inString)
{
	SetDottedDecimal(inString);
}

DottedDecimal::DottedDecimal(LPTSTR inString)
{
	wstring ws = wstring(inString);
	string s;
	s.assign(ws.begin(), ws.end());
	SetDottedDecimal(s);
}

DottedDecimal::DottedDecimal(char * inString)
{
	SetDottedDecimal(inString);
}

DottedDecimal::~DottedDecimal()
{
}

string DottedDecimal::GetDottedDecimal()
{
	string retVal = "";
	for (unsigned short i = 0; i < _decimals.size(); i++)
	{
		if (retVal.compare("") != 0)
		{
			retVal += ".";
		}
		retVal += AnyTypeToString(_decimals.at(i));
	}
	return retVal;
}

template <class T>
void DottedDecimal::SetDottedDecimal(const T& t)
{
	_decimals.clear();
	string valueString = AnyTypeToString(t);
	vector<string> * values = new vector<string>();
	StringSplit(valueString, ".", values);
	for (unsigned short i = 0; i < values->size(); i++)
	{
		long l;
		StringToAnyType(l, values->at(i));
		_decimals.push_back(l);
	}
	delete values;
}

vector<long> DottedDecimal::GetDecimals()
{
	return _decimals;
}

ostream &operator<<(ostream & dataStream, DottedDecimal & dd)
{
	dataStream << dd.GetDottedDecimal();
	return dataStream;
}

bool operator==(DottedDecimal & left, DottedDecimal & right)
{
	// If the value count isn't the same, then false
	if (left.GetDecimals().size() != right.GetDecimals().size())
		return false;

	for (unsigned short i = 0; i < left.GetDecimals().size(); i++)
	{
		// If at any time values don't match, return false
		if (left.GetDecimals().at(i) != right.GetDecimals().at(i))
			return false;
	}

	// If you get here they are the same.
	return true;
}

bool operator!=(DottedDecimal & left, DottedDecimal & right)
{
	// If the value count isn't the same, then true
	if (left.GetDecimals().size() != right.GetDecimals().size())
		return true;

	for (unsigned short i = 0; i < left.GetDecimals().size(); i++)
	{
		// If at any time values don't match, return true
		if (left.GetDecimals().at(i) != right.GetDecimals().at(i))
			return true;
	}

	// If you get here they are the same.
	return false;
}

bool operator>(DottedDecimal & left, DottedDecimal & right)
{
	// If one has three values and the other has four, only check three
	short count = (left.GetDecimals().size() <= right.GetDecimals().size() ? left.GetDecimals().size() : right.GetDecimals().size());
	for (unsigned short i = 0; i < count; i++)
	{
		if (left.GetDecimals().at(i) > right.GetDecimals().at(i))
			return true;
	}

	// If you get here, then the checked values were the same.
	// Return true if the left side has more values than the right side.
	if (left.GetDecimals().size() > right.GetDecimals().size() )
		return true;
	else
		return false;
}

bool operator>=(DottedDecimal & left, DottedDecimal & right)
{
	// If one has three values and the other has four, only check three
	short count = (left.GetDecimals().size() <= right.GetDecimals().size() ? left.GetDecimals().size() : right.GetDecimals().size());
	for (unsigned short i = 0; i < count; i++)
	{
		// If any compared value is greater, return true;
		if (left.GetDecimals().at(i) > right.GetDecimals().at(i))
			return true;
	}

	// If you get here, then the checked values were the same.
	// Return true if the left side has more values than or the same values as the right side.
	return left.GetDecimals().size() >= right.GetDecimals().size();
}

bool operator<(DottedDecimal & left, DottedDecimal & right)
{
// If one has three values and the other has four, only check three
	short count = (left.GetDecimals().size() <= right.GetDecimals().size() ? left.GetDecimals().size() : right.GetDecimals().size());
	for (unsigned short i = 0; i < count; i++)
	{
		// If any compared value is less, return true;
		if (left.GetDecimals().at(i) < right.GetDecimals().at(i))
			return true;
	}

	// If you get here, then the checked values were the same.
	// Return true if the left side has less values than the right side.
	return left.GetDecimals().size() < right.GetDecimals().size();
}

bool operator<=(DottedDecimal & left, DottedDecimal & right)
{
	// If one has three values and the other has four, only check three
	short count = (left.GetDecimals().size() <= right.GetDecimals().size() ? left.GetDecimals().size() : right.GetDecimals().size());
	for (unsigned short i = 0; i < count; i++)
	{
		// If any compared value is greater, return true;
		if (left.GetDecimals().at(i) > right.GetDecimals().at(i))
			return true;
	}

	// If you get here, then the checked values were the same.
	// Return true if the left side has less values than or the same values as the right side.
	return left.GetDecimals().size() <= right.GetDecimals().size();
}

// Private

template <class T>
string DottedDecimal::AnyTypeToString(const T& t)
{
	std::stringstream ss;
	ss << t;
	return ss.str();
}

template <class T>
void DottedDecimal::StringToAnyType(T& t, std::string inString)
{
	std::stringstream ss(inString);
	ss >> t;
}

void DottedDecimal::StringSplit(string inString, string inDelim, vector<string> * outResults)
{
	int cutAt;
	while( (cutAt = inString.find_first_of(inDelim)) != inString.npos )
	{
		if(cutAt > 0)
		{
			outResults->push_back(inString.substr(0,cutAt));
		}
		inString = inString.substr(cutAt+1);
	}
	if(inString.length() > 0)
	{
		outResults->push_back(inString);
	}
}

Copyright ® Rhyous.com – Linking to this article is allowed without permission and as many as ten lines of this article can be used along with this link. Any other use of this article is allowed only by permission of Rhyous.com.


How to enumerate installed MSI Products and their MSP Patches using C#

Hey all,

I already have a C++ example of doing this, but that isn’t much help when you have to do it in C#. So it is good to know how to do this in both languages.

Here is what I did:

  1. Created a new C# Console Application project in Visual Studio and named it WindowsInstallerTest.
  2. I added a reference to Microsoft.Deployment.WindowsInstaller. I found this by installing Windows Installer XMl and looking here:
    C:\Program Files (x86)\Windows Installer XML v3.6\bin\Microsoft.Deployment.WindowsInstaller.dll
  3. I added a using statement to the same Microsoft.Deployment.WindowsInstaller.
  4. I enumerated the installed MSI products and then with a foreach loop output data on each.
  5. I enumerated the MSP patches for each product and used another foreach loop to output data on each product.

Here is the simple code.  Hopefully this is enough to get your started with writing code to work with installed MSI products.

using System;
using System.Collections.Generic;
using System.Linq;
// 
// Step 1 - Add a reference to Microsoft.Deployment.WindowsInstaller
//          and then add this using statement.
using Microsoft.Deployment.WindowsInstaller;

namespace WindowsInstallerTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Step 2 - Get the installed MSI Products
            IEnumerable<ProductInstallation> installations = Microsoft.Deployment.WindowsInstaller.ProductInstallation.GetProducts(null, "s-1-1-0", UserContexts.All);
            int i = 0;

            // Step 3 - Loop through the installed MSI Products and output information

            foreach (ProductInstallation installation in installations)
            {
                Console.WriteLine("Id: " + ++i);
                Console.WriteLine("Name: " + installation.ProductName);
                Console.WriteLine("ProductVersion: " + installation.ProductVersion);
                Console.WriteLine("Install Source: " + installation.InstallSource);
                Console.WriteLine("Patches: ");

                // Step 4 - Get the installed MSP Patches for the current installation
                IEnumerable<PatchInstallation> patches = PatchInstallation.GetPatches(null, installation.ProductCode, "s-1-1-0", UserContexts.All, PatchStates.All);

                // Step 5 - Loop through the installed MSP Patches and output information
                int j = 0;
                foreach (PatchInstallation patch in patches)
                {
                    Console.WriteLine("  " + ++j + ": " + patch.DisplayName);
                    Console.WriteLine("  Cache: " + patch.LocalPackage);
                }
                Console.WriteLine();
            }
        }
    }
}

StarCraft II available for predownload

I am downloading StarCraft II right now.

Supposedly you can download it, then purchase your activation key online and install and activate tomorrow.

It is available for pre-download here.

http://www.starcraft2.com/