Get Windows Version from Output of ‘ver’

This is a quick way to get the version string from the output of the Command Prompt ver command within a VBScript.

Dim oShell, oExec
Dim sText, bQuit
Dim iIndexStart, iIndexEnd

sText = ""
bQuit = False

Set oShell = CreateObject("WScript.Shell")
Set oExec = oShell.Exec("%comspec% /c ver")

Do While bQuit = False
    If Not oExec.StdOut.AtEndOfStream Then
        sText = sText & oExec.StdOut.ReadAll()
    End If

    If oExec.Status = 1 Then
        bQuit = True
    Else
        WScript.Sleep(100)
    End If
Loop

'ver returns Microsoft Windows [Version 6.0.6001]
'parse it to return only the version number string
iIndexStart = InStr(1, sText, "[", 1)
iIndexEnd = InStr(1, sText, "]", 1)

MsgBox Mid(sText, iIndexStart+9, iIndexEnd-iIndexStart-9)

Version Strings for Windows Releases

Windows 2000 Microsoft Windows 2000 [Version 5.00.2195]
Windows XP Microsoft Windows XP [Version 5.1.2600]
Windows Vista Microsoft Windows [Version 6.0.6001]
Windows 2008 Microsoft Windows [Version 6.0.6001]
Bookmark and Share

Windows 7 RC

Windows 7 RC System Info

Working like a charm.

Bookmark and Share

Job Processing System – Getting Started

Let’s implement a really simple job processing system. The purpose of this system is to process URIs. We will build this system using C# 3.5 and SQL Server will be used to manage the job repository. Just for fun, let’s build a friendly interface for the user to provide data and retrieve results and a friendly interface for managing the system. I’m using Visual Studio 2008 and SQL Server 2008 for development.

 JobEngine-HighLevel

First things first, we need to document the requirements. We will track two kinds of requirements:

  1. Functional Requirements document what the system should do to satisfy the user.
  2. Non-Functional Requirements document what the system should do in order to meet operating criteria.

Let’s begin.

Functional Requirements

  1. User provides the input criteria as a file or by typing in the text.
  2. File uploads are limited to 10 MB and are in CSV format with a CSV header.
  3. The user should be able to view the following statuses for a job: Pending, Processed, Failed.
  4. The user should be able to access the original criteria.
  5. The user should be able to access the results as CSV.
  6. The system should support variable pricing for different types of behaviors.
  7. The system should support variable pricing for different counts of records.
  8. The system will support the following behaviors:
    1. ISBN – given a list, identify the name of the book and the Amazon sales rank
    2. URL – given a list, identify the HTTP code returned
    3. Zip Code – given a list, identify the city and state

Non-Functional Requirements

  1. A job should run independent of any other jobs in the system.
  2. A job can be started or be stopped independent of any other jobs.
  3. A job should be able to restart from the last successfully processed record.
  4. A job should be failed if it has run for over 200 minutes.
  5. Jobs should notify via email of catastrophic errors.
  6. Jobs should provide statistics:
    1. number of records processed
    2. total number of records
    3. average time per record
    4. number of records that failed processing
    5. length of time the job has run

Ok, we now have sufficient information to get started. Remember that real-world requirement are fluid so you should be able to adapt to them. Let’s begin implementing what we know in the next post.

Bookmark and Share

Beginner’s Guide to OAuth

I’m creating an iGoogle widget that displays personalized financial portfolios and I decided to implement OAuth as the authentication standard. This is a series of posts by Eran Hammer-Lahav I found that helped me get acquainted with the OAuth protocol (read in sequence):

  1. Explaining OAuth
  2. Beginner’s Guide to OAuth – Part I: Overview
  3. Beginner’s Guide to OAuth – Part II : Protocol Workflow
  4. Beginner’s Guide to OAuth – Part III : Security Architecture
  5. Beginner’s Guide to OAuth – Part IV: Signing Requests

Unfortunately, I haven’t found a good C# implementation of the OAuth standard yet. I’ll update this post when I find something that I can use.

Bookmark and Share

Windows HomeServer Setup

image

I setup the HP EX485 HomeServer today. I was truly impressed by simplicity of the setup process.

First step was to add a 1TB drive into the tray. Then I powered on the machine and plugged it into the network.

I dropped the software CD-ROM into my desktop and ran through the connector setup and the server setup. About 30 minutes later, everything was ready for use.

Via the console, I updated the operating system to Power Pack 2. Then, I enabled remote access so that I could get to my server via https://rohand.homeserver.com/ and access my data. I also enabled sharing Music, Videos, Pictures etc. Still have to configure Time Machine on the Mac to use the Home Server.

Finally, I re-configured backups for my desktop. I didn’t want backups of the hidden system partition created by Windows 7 so I excluded that. I noticed the backup software is smart enough to skip Windows files like the hibernation file or the page file.

Everything looks great. The machine sits in a corner and is very quiet. I’ll add a couple more terabyte+ drives into the system when I get them and hopefully I shall finally have simple peaceful silent reliable automated backups.

Bookmark and Share

Calculate Number of Groups

Ran into this issue today where I had to calculate the number of groups, given a list of items and the maximum items allowed in a group. It took a few minutes to figure out.


public int GetTotalGroups(int totalItems, int itemsPerGroup)
{
    int totalGroups = 1;

    if (totalItems % itemsPerGroup == 0)
    {
        totalGroups = totalItems/itemsPerGroup;
    }
    else
    {
        totalGroups = (totalItems/itemsPerGroup) + 1;
    }

    return totalGroups;
}
Bookmark and Share

I’m Waiting for HP

I admit – I don’t backup any of my systems at home. I didn’t find a good backup/consolidation suite in the market that met my critieria for simplicity, Mac compatibility and future expansion. I looked at NAS devices a few months ago – I wanted at least 3TB – and the cost was prohibitive.

Enter Windows Home Server. I spent the couple weeks determining if I should build or buy a Home Server. After making many trips to the local Frys and searching NewEgg, I finally decided to buy the HP EX485 MediaSmart Home Server. I was impressed with the simplicity of the setup and management experience that the server provides. Also, the box has many USB ports and an eSATA ports that will let me expand up to 16TB, which is where I predict I shall be in the next 36 months.

I placed my order today and am expecting the box by the end of the week.

Bookmark and Share

Registered SQL Servers

Registered SQL Servers

In case you need to backup the list of SQL Server Management Studio (SSMS) Registered SQL Servers and can’t open the GUI, the list is stored in Windows Vista and Windows 7 at C:\Users\USERNAME\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\RegSrvr.xml.

The generic path is %APPDATA%\Microsoft\Microsoft SQL Server\100\Tools\Shell\RegSrvr.xml.

Bookmark and Share

Keep Your Local Copy of the Sysinternals Tools in Sync

This is my solution to keep my local copy of the wonderful Sysinternals tools synchronized with updates as they are published to the live.sysinternals.com site. Note that this is a quick-and-dirty bandwidth-intensive solution. I am not liable for any kind of disaster you may cause and the standard disclaimers apply.

On my system, I place tools and utilities in a single folder at C:\Tools\. I append this folder to the system PATH.

Step#1: Download wget from http://www.christopherlewis.com/WGet/WGetFiles.htm and extract the contents to C:\Tools\.

Step#2: Create a batch file that will download only the utilities and libraries. Save this batch file as C:\Tools\SYNC-SysinternalsTools.bat.

REM Get latest SysInternals tools from http://live.sysinternals.com/tools/
REM Tools are downloaded into C:\Tools\
REM wget script leached from http://tinyurl.com/wgetcmdline
REM added HLP/hlp to skip help files

c:\tools\wget.exe -m -nd -N -I /tools -R HLP,hlp,url,txt,scr,chm,index.html -PC:\Tools\ http://live.sysinternals.com/tools/

Step#3: Create a scheduled task to refresh your local files. The task runs on Sundays at 2:30 PM. The task is named SYNC-SysinternalsTools and invokes the batch file we created in Step#2. Open a Command Prompt and type:

SCHTASKS /CREATE /TN SYNC-SysinternalsTools /SC WEEKLY /D SUN /ST 14:30 /TR C:\Tools\SYNC-SysinternalsTools.bat

Step#4: Test the task. Open a Command Prompt and type:

SCHTASKS /RUN /TN SYNC-SysinternalsTools

You should see the following message and another window with wget downloading files.

SUCCESS: Attempted to run the scheduled task "SYNC-SysinternalsTools".

And you are done.

This post was inspired by a forum thread at 2BrightSparks.

Bookmark and Share

Welcome to the year 2009

Hello everyone. Welcome to the beautiful year 2009 A.D. It has been a grand entrance into this year with the people I respect and love and I’m excited to find out what the remaining 364 days and some hours portend for yours truly. I can only promise you goodness and happiness and joy and celebration.

Rock on!

Bookmark and Share

Set ACLs for Folder

Here is a VBScript that generates and executes a batch file to set up ACLs for the C:\Inetpub\wwwroot folder. This works on Windows 2003 Server.

Const SCRIPT_FILE = "SetupACLs.bat"
Const FLDR_WWW = "C:\Inetpub\wwwroot"

Sub Main
Call SaveScript(SCRIPT_FILE, GenerateScript)
Call RunScript(SCRIPT_FILE)
End Sub

Function GenerateScript
Dim sScript

sScript = "REM " & SCRIPT_FILE & " generated on " & Now & vbCrLf
sScript = sScript & SetupWwwRootACLs(FLDR_WWW) & vbCrLf

GenerateScript = sScript
End Function

Function SetupWwwRootACLs(sPath)
Dim sScript

sScript = "REM SetupWwwRootACLs" & vbCrLf

sScript = sScript & Perms(sPath, "Network Service", "r") & vbCrLf
sScript = sScript & Perms(sPath, "IIS_WPG", "r") & vbCrLf
sScript = sScript & Perms(sPath, "ASPNET", "r") & vbCrLf

SetupWwwRootACLs = sScript
End Function

Sub SaveScript(sPath, sScript)
Dim oFSO
Dim oFile

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile(sPath, True)

oFile.WriteLine (sScript)

oFile.Close

Set oFSO = Nothing
End Sub

Sub RunScript(sPath)
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

WshShell.Run sPath, 1, True
End Sub

Function Perms(sPath, sUser, sPermission)
Perms = "cacls """ & sPath & """ /e /g """ & sUser & """:" & sPermission
End Function
Bookmark and Share