Archive for July, 2008

Tribute to Mr. It Works On My Computer Guy

I’m in a mood. I will have something later for real. Again we all know somebody like this I bet….|_WorksOnMyMachineGuy|_01.mp3

1 Comment

Tribute to Mr. Overly Complicated Application Guy

I needed this pick me up.

I think we all know a developer like this one don’t we? 🙂|_OverlyComplicatedAppGuy.mp3

1 Comment

Write hardware information to dataset with

Good afternoon all. Once again I had a difficult evening with my 17 year old. It didn’t even take 24 hours after being told she would lose driving, job and such privileges if she failed to follow rules that had clearly been set down. We were up until 1:30AM dealing with this. Top it off with what the Cubs did to the Brewers last night and ….. YUCK!

Anyway, we want to write various hardware information to a dataset. I chose to use WMI. It isn’t perfect but it works.

Make it a great day! And here’s to a better night!

Join me on Facebook

Imports Microsoft.VisualBasic
Imports System.Management

Public Class WMIClasses
        Public Const ComputerSystemInfo As String = "Win32_ComputerSystem"
        Public Const CDRomInfo As String = "Win32_CDRomdrive"
        Public Const VideoCardInfo As String = "Win32_VideoController"
        Public Const OperatingSystem As String = "Win32_OperatingSystem"
        Public Const EventLog As String = "Win32_NTLogEvent"
        Public Const DiskDrive As String = "Win32_DiskDrive"
        Public Const Processor As String = "Win32_Processor"
        Public Const LogicalDisk As String = "Win32_LogicalDisk"
        Public Const PrinterInfo As String = "Win32_Printer"
        Public Const WindowsActivation As String = "Win32_WindowsProductActivation"
        Public Const W1394ControllerDevice As String = "Win32_1394ControllerDevice"
        Public Const AccountClass As String = "Win32_Account"
        Public Const BaseBoard As String = "Win32_BaseBoard"
        Public Const BaseService As String = "Win32_BaseService"
        Public Const Bios As String = "Win32_BIOS"
    End Class

Public Shared Function WMIComputer(ByVal ComputerName As String, ByVal SelectClass As String) As Data.DataTable
        ‘Going to return a dataTable to add to the DataSet
        Dim retTable As New Data.DataTable(SelectClass)
        ‘Section 1: This section establishes a connection to the remote computer on the network
        Dim options As New ConnectionOptions
        Dim scope As ManagementScope
        Dim queryCollection As ManagementObjectCollection
        Dim ManageObject As ManagementObject
        Dim e As PropertyDataCollection.PropertyDataEnumerator
        Dim TableInitialized As Boolean = False
            scope = New ManagementScope("\\" & ComputerName & "\root\cimv2", options)
        Catch e1 As Exception
            ‘Dont Care
        End Try
        Dim tempRow As Data.DataRow
        ‘Section 2 deals with the Query of the selected class
        Dim query As New ObjectQuery("SELECT * FROM " & SelectClass)
        Dim searcher As New ManagementObjectSearcher(scope, query)
        queryCollection = searcher.Get()
        For Each ManageObject In queryCollection

            ‘This is where the table columns get initialized for a typed dataset
            If Not TableInitialized Then
                e = ManageObject.Properties.GetEnumerator()
                While e.MoveNext
                End While
                TableInitialized = True
            End If
            tempRow = retTable.NewRow ‘Initialize a new row
            e = ManageObject.Properties.GetEnumerator()
            While e.MoveNext
                    tempRow.Item(e.Current.Name) = ManageObject(e.Current.Name)
                Catch ex As Exception
                 End Try

            End While
        Return retTable
    End Function

Private Function PageInit() As Data.DataSet
        retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.ComputerSystemInfo))
        retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.OperatingSystem))
        ‘retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.EventLog))
        retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.LogicalDisk))
        retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.Processor))
        retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.VideoCardInfo))
        retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.PrinterInfo))
        retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.WindowsActivation))
        retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.W1394ControllerDevice))
        retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.BaseBoard))
        retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.BaseService))
        retDS.Tables.Add(WMI.WMIComputer(System.Environment.MachineName, WMI.WMIClasses.BIOS))
        Return retDS
    End Function

Consulting Requests


Blog Front Page

Windows Live Tags:,.NET,WMI,hardware,information



Query Exchange/Active Directory for Distribution Lists with

Good Morning all. I did not have a good night. My eldest daughter who is 17 gave us considerable problems. Someday I will go into that in a future blog entry. Just so much to say about it and more than most of you want to know I am sure.

Anyway we want to query Exchange or Active Directory for Distribution Lists. My purpose was to make sure a particular report got to everyone.

Make it a great day!

Private Sub LoadUserGroupTable(Optional ByVal _SortField As String = "user_name")
            ‘ bind the data to the datagrid
            Dim clsApp As New CustomAppSettings
            Dim de As New DirectoryEntry( _
                AppSettings("ActiveDirectoryPath"), _
                clsApp.GetAppSetting("ADUsername"), _
            Dim src As New DirectorySearcher
            With src
                .Filter = "(&(objectcategory=Person)(|(objectclass=User)(cn=Network Distribution Lists)))"
                .SearchRoot = de
                .SearchScope = SearchScope.Subtree
            End With
            Dim res As SearchResult
            For Each res In src.FindAll
                    Dim topRow As DataRow = UserGroupTable.NewRow
                    topRow("user_name") = res.Properties("displayname")(0).ToString
                    topRow("username") = res.Properties("displayname")(0).ToString
                    topRow("email") = res.Properties("mail")(0).ToString
                Catch ex As Exception
                    ‘ do nothing
                    ‘Dim clsErr As New ABCNetErrors
                    ‘clsErr.NotifyABCNetAdmin("Could not bind Group to a DataRow", ex)
                End Try
            Dim dv As DataView = New DataView(UsersTable)
            dv.Sort = "user_name ASC"
            With lbGroups
                .DataSource = dv
                .DataTextField = "user_name"
                .DataValueField = "email"
            End With
        End Sub


Leave a comment

BackgroundWorker Component For .NET Framework 1.1 with

Good Morning again!

Well for the last few days, I was asked to work in 1.1 of the Framework with doesn’t have some of our helpful things that we have gotten used to in later versions of the framework. I was asked to write a backgroundworker component developers could use for SQL operations within this .NET Framework 1.1. I have changed the code considerably for security reasons (hope you don’t mind) but for those of you stuck in earlier versions of the framework you might find it useful. It’s now stable enough I think I could share it with you guys. Also, I realize the practice of using TSQL to access the database from code is not a good idea but it is what the boss wanted. So don’t yell at me too loud ok?? 🙂 Hoping my friend Frank Meffert will come along and provide a C# translation of this code. He is quite adept at translating my gibberish. So without further delay here it is. Make it a great day!

Imports System.ComponentModel

Public Class BackgroundWorker

  <EditorBrowsable(EditorBrowsableState.Advanced), Browsable(False)> _
  Delegate Sub BackgroundThreadDelegate()
  <EditorBrowsable(EditorBrowsableState.Advanced), Browsable(False)> _
  Delegate Sub BackgroundThreadDelegateSql(ByVal Sql As String)
  <EditorBrowsable(EditorBrowsableState.Advanced), Browsable(False)> _
  Delegate Sub BackgroundThreadDelegateArgs(ByVal Args() As Object)

  Public Event DoWork(ByVal Sender As Object, ByVal e As DoWorkEventArgs)
  Public Event SqlStatusChanged(ByVal Sender As Object, ByVal e As StatusEventArgs)
  Public Event SqlComplete(ByVal Sender As Object, ByVal e As EventArgs)
  Public Event SqlException(ByVal Sender As Object, ByVal e As SqlExceptionEventArgs)

  <EditorBrowsable(EditorBrowsableState.Advanced), Browsable(False)> _
  Public Enum SqlStatusEnum
  End Enum

  Private _status As SqlStatusEnum

  Public Sub Execute()

    Dim d As BackgroundThreadDelegate = AddressOf BackgroundThread

  End Sub

  Public Sub Execute(ByVal Sql As String)

    Dim d As BackgroundThreadDelegateSql = AddressOf BackgroundThread

  End Sub

  Public Sub Execute(ByVal args() As Object)

    Dim d As BackgroundThreadDelegateArgs = AddressOf BackgroundThread

  End Sub

  Public Sub Wait(ByVal Sql As String)


    Loop Until Me.SqlStatus = SqlStatusEnum.Idle

  End Sub

  Public Property SqlStatus() As SqlStatusEnum
      Return _status
    End Get
    Set(ByVal Value As SqlStatusEnum)
      If Value <> _status Then
        _status = Value
        RaiseEvent SqlStatusChanged(Me, New StatusEventArgs(_status))
      End If
    End Set
  End Property

  Private Sub BackgroundThread()
    RaiseEvent DoWork(Me, New DoWorkEventArgs)
  End Sub

  Private Sub BackgroundThread(ByVal Sql As String)

    Dim cn As SqlConnection
    Dim cmd As SqlCommand


      Me.SqlStatus = SqlStatusEnum.Active

      cn = Context.User.Connection
      cmd = New SqlCommand(Sql, cn)
      cmd.CommandTimeout = 600

      Me.SqlStatus = True
      RaiseEvent SqlComplete(Me, New EventArgs)

    Catch ex As Exception

      If Not cn Is Nothing AndAlso cn.State <> ConnectionState.Closed Then cn.Close()
      RaiseEvent SqlException(Me, New SqlExceptionEventArgs(Sql, ex))
      Me.SqlStatus = SqlStatusEnum.Idle

    End Try

  End Sub

  Private Sub BackgroundThread(ByVal Args() As Object)
    RaiseEvent DoWork(Me, New DoWorkEventArgs(Args))
  End Sub

  <EditorBrowsable(EditorBrowsableState.Advanced), Browsable(False)> _
  Public Class StatusEventArgs
    Inherits EventArgs

    Public sqlStatus As SqlStatusEnum

    Public Sub New(ByVal Status As SqlStatusEnum)
      Me.sqlStatus = Status
    End Sub

  End Class

  <EditorBrowsable(EditorBrowsableState.Advanced), Browsable(False)> _
  Public Class DoWorkEventArgs
    Inherits EventArgs

    Public Sql As String = ""
    Public Args() As Object

    Public Sub New()
    End Sub

    Public Sub New(ByVal Sql As String)
      Me.Sql = Sql
    End Sub

    Public Sub New(ByVal Args() As Object)
      Me.Args = Args
    End Sub

  End Class

  <EditorBrowsable(EditorBrowsableState.Advanced), Browsable(False)> _
  Public Class SqlExceptionEventArgs
    Inherits EventArgs

    Public Exception As Exception
    Public Sql As String

    Public Sub New(ByVal Sql As String, ByVal Exception As Exception)
      Me.Exception = Exception
    End Sub

  End Class

End Class


Technorati Tags: ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Windows Live Tags:,1.1,.NET Framework,csharp,BackgroundWorker,Component,Framework,TSQL,database,Frank,Meffert,translation,System,ComponentModel,EditorBrowsable,EditorBrowsableState,Browsable,BackgroundThreadDelegate,BackgroundThreadDelegateSql,SqlComplete,SqlException,Execute,BackgroundThread,RaiseEvent,Thread,CurrentThread,SqlConnection,SqlCommand,Context,User,Connection,CommandTimeout,ExecuteNonQuery,ConnectionState,versions,operations

Leave a comment

Get User Email Address in Active Directory in

Good morning all and hope you had a great weekend! This weekend was somewhat comical for me. First I had gotten a basketball hoop and backboard and on Saturday decided it was time to put it together. The box said "Some Assembly Required". Alrighty then shouldn’t be a problem right? I started at about 9am and finished it at……approximately 5PM. Granted I took breaks to do other stuff but it was frustrating to put together. But granted it was all worthwhile because my daughter Alyssa came out and shot "horse" with me on Sunday night. And that is always fun for me. Plus I get her off the couch, away from the computer and the TV which is a bonus!

Then on Sunday, I went to pick up my exercise machine. It didn’t fit exactly into the truck very well so I sat in back making sure it didn’t go anywhere while my wife drove us home. When we get there it was time to remove it but it wouldn’t come out! What’s worse is as it was coming out one of the handles started to poke a hole in the roof of the truck (It’s an Explorer). So I went to get a neighbor whom I have never met before and the three of us managed to get it out. Unfortunately this thing on one side weighed about 200 lbs and I was on this side going down the stairs to my basement. As I was going I felt this stretching, piercing kind of pain in my lower back. This morning which was to begin my workout routine I am pretty hunched over.

The good news is we met a neighbor, a rather nice guy I might add, which we probably would not have before. So something good came out of that effort too.

Anyway today’s topic. Nothing exciting. All I am doing is getting the users email address from Active Directory. I am writing this as part of an application to send out reports to various people. Anyway, make it a great day!

Join me on Facebook

Public Function GetCurUserEmail(ByVal DomainObj As ActiveDs.IADsContainer, ByVal TargetUserID As String) As String
            Dim User As ActiveDs.IADsUser
            Dim EmailAddress As String = ""
                If Not DomainObj Is Nothing Then
                    DomainObj.Filter = New Object() {"User"}
                    For Each User In DomainObj
                        Dim UserName As String
                        UserName = Replace(User.Name, "CN=", "")
                        If TargetUserID = UserName Then
                            EmailAddress = User.EmailAddress
                            Exit For
                        End If
                    User = Nothing
                    DomainObj = Nothing
                    Return EmailAddress
                    Return Nothing
                End If
            Catch e As Exception
                Return Nothing
            End Try
        End Function



Leave a comment

Working for a big company changes how I learn and grow

I started at GE Healthcare after years of consulting. Prior to that I worked for a small company in Sheboygan WI called JJ Koepsell Company, a plumbing distributor. It was a small company by any standard – 15-20 employees.

One thing I loved about working there was the fact that because I was "the guy" I had an opportunity to delve into many facets of technology. I learned to function in and administer Novell, Windows, Exchange and AIX servers – and get them to talk to each other. I learned different file formats, how to script for different platforms and of course I was the one called on for every computer related (and some not computer related) task. I learned different kinds of networks and database platforms such as SQL and Oracle. And of course there was the .NET and vb6 work. I HAD to do all these things because we couldn’t afford to hire a consultant for every little thing I didn’t know. I grew by leaps and bounds there professionally and had it not been for working there I would not be where I am today.

Consulting was the same way. Because I had had experience in so many facets of technology, I was called on in many different capacities and situations. Again, my skills continued to grow. It also forced me to stay current in what new technologies were coming out.

Another nice thing about picking up that experience in other fields than coding it made me a better programmer. I understand why the network admin is reluctant to give me any rights at all. (More than you know…. :))

Working for GE, first let me say, I love my job. If you ever get the chance to work for this company DO IT. You have unparalleled freedom to think outside the box in what you code, and they treat you well in pay and benefits. I am not saying that just because I know someone from there may be reading this. I actually mean it :).

The only downside is that i do miss the varied things I used to be able to do. The bigger the company gets, the more specialized the jobs become. I code in .NET there – that is what I do. It is what I always wanted to do and of all work it is my favorite. I never thought I would say this but yes I actually miss those days when my Novell Server would not load its modules properly and I had to go in there and start them all manually one at a time. (AIEEEEEEEEEEEEEEE yes that was me you heard years ago screaming!) Here I am a cog in the machine. Prior to this I WAS the machine. So it is a bit of an adjustment for me.

One thing I can already tell. Because I don’t have the pressures I used to I am going to have to force myself to keep learning on my own. Working in a small company I was forced to learn by every day events so at home work wasn’t as important. I bought a server for home study a couple years ago and have been administering a web server, Windows Server 2003, Exchange and all that stuff. If I put my hands on it I will learn. I will have to stay motivated to keep learning the new technologies. Otherwise I fear my skills will become outdated. There is nothing sadder than to see a guy let go in an IT position that he has had for years because he didn’t keep pace with the times. I’ve seen it happen before. I must resist the urge to "get comfortable" with where I am at. It’s not what got me here and it certainly won’t keep me here. This is part of the reason this blog exists. Every day I post something new I am doing and if I don’t I get upset with myself. I see way too many developers relying on code they have written for the past number of years and then never doing anything new to push themselves.

Well thanks for listening to me ramble. I hope you have a great weekend! Me I got to ask the wife and find out what is going to happen in mine. She knows better than I do. 🙂