Archive for July, 2008
Tribute to Mr. It Works On My Computer Guy
Posted by Kelly's Chronicles in Uncategorized on July 31, 2008
I’m in a mood. I will have something later for real. Again we all know somebody like this I bet….
http://cid-a0d71e1614e8dbf8.skydrive.live.com/embedrowdetail.aspx/Public/RTH|_WorksOnMyMachineGuy|_01.mp3
Tribute to Mr. Overly Complicated Application Guy
Posted by Kelly's Chronicles in .NET on July 30, 2008
I needed this pick me up.
I think we all know a developer like this one don’t we? 🙂
http://cid-a0d71e1614e8dbf8.skydrive.live.com/embedrowdetail.aspx/Public/RTH|_OverlyComplicatedAppGuy.mp3
Write hardware information to dataset with vb.net
Posted by Kelly's Chronicles in .NET on July 30, 2008
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!
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
       Try
           scope = New ManagementScope("\\" & ComputerName & "\root\cimv2", options)
           scope.Connect()
       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
                   retTable.Columns.Add(e.Current.Name)
               End While
               TableInitialized = True
           End If
           tempRow = retTable.NewRow ‘Initialize a new row
           e = ManageObject.Properties.GetEnumerator()
           While e.MoveNext
               Try
                   tempRow.Item(e.Current.Name) = ManageObject(e.Current.Name)
               Catch ex As Exception
                End Try
           End While
           retTable.Rows.Add(tempRow)
       Next
       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
Â
Query Exchange/Active Directory for Distribution Lists with vb.net
Posted by Kelly's Chronicles in Uncategorized on July 29, 2008
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"), _
               clsApp.GetAppSetting("ADPassword"))
           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
           CreateUserGroupTable()
           For Each res In src.FindAll
               Try
                   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
                   UserGroupTable.Rows.Add(topRow)
               Catch ex As Exception
                   ‘ do nothing
                   ‘Dim clsErr As New ABCNetErrors
                   ‘clsErr.NotifyABCNetAdmin("Could not bind Group to a DataRow", ex)
               End Try
           Next
           Dim dv As DataView = New DataView(UsersTable)
           dv.Sort = "user_name ASC"
           With lbGroups
               .DataSource = dv
               .DataTextField = "user_name"
               .DataValueField = "email"
               .DataBind()
           End With
       End Sub
Â
BackgroundWorker Component For .NET Framework 1.1 with vb.net
Posted by Kelly's Chronicles in .NET on July 28, 2008
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
   Idle
   Active
 End Enum
 Private _status As SqlStatusEnum
 Public Sub Execute()
   Dim d As BackgroundThreadDelegate = AddressOf BackgroundThread
   d.Invoke()
 End Sub
 Public Sub Execute(ByVal Sql As String)
   Dim d As BackgroundThreadDelegateSql = AddressOf BackgroundThread
   d.Invoke(Sql)
 End Sub
 Public Sub Execute(ByVal args() As Object)
   Dim d As BackgroundThreadDelegateArgs = AddressOf BackgroundThread
   d.Invoke(args)
 End Sub
 Public Sub Wait(ByVal Sql As String)
   Me.Execute(Sql)
   Do
     Application.DoEvents()
   Loop Until Me.SqlStatus = SqlStatusEnum.Idle
 End Sub
 Public Property SqlStatus() As SqlStatusEnum
   Get
     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()
   Threading.Thread.CurrentThread.Sleep(10)
   RaiseEvent DoWork(Me, New DoWorkEventArgs)
 End Sub
 Private Sub BackgroundThread(ByVal Sql As String)
   Dim cn As SqlConnection
   Dim cmd As SqlCommand
   Try
     Me.SqlStatus = SqlStatusEnum.Active
     cn = Context.User.Connection
     cn.Open()
     cmd = New SqlCommand(Sql, cn)
     cmd.CommandTimeout = 600
     cmd.ExecuteNonQuery()
     cn.Close()
     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: vb.net,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
Windows Live Tags: vb.net,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
Get User Email Address in Active Directory in vb.net
Posted by Kelly's Chronicles in Uncategorized on July 28, 2008
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!
Public Function GetCurUserEmail(ByVal DomainObj As ActiveDs.IADsContainer, ByVal TargetUserID As String) As String
           Dim User As ActiveDs.IADsUser
           Dim EmailAddress As String = ""
           Try
               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
                   Next
                   User = Nothing
                   DomainObj = Nothing
                   Return EmailAddress
               Else
                   Return Nothing
               End If
           Catch e As Exception
               ShowMsgBox(e.Message)
               Return Nothing
           End Try
       End Function
Â
Â
Working for a big company changes how I learn and grow
Posted by Kelly's Chronicles in Uncategorized on July 25, 2008
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. 🙂
Â
Getting all groups that an Active Directory user is a member of in vb.net
Posted by Kelly's Chronicles in .NET on July 25, 2008
Hello all. This is an extremely late post today. I was extremely busy with work issues last night and this morning. I am extremely tired and so ready to go to bed and not think about coding today.
Anyway for my topic today we want to find out all groups a given user belongs to. This was written some time ago at a time when we were trying to reorganize an active directory structure.
Make it a great day!
Dim userName As String = "your user name"
       Dim root As DirectoryEntry = New DirectoryEntry("LDAP://your domain name")
       Dim _objDirSearcher As DirectorySearcher = New DirectorySearcher(root)
       _objDirSearcher.Filter = "(&(objectCategory=user)(name=" + userName.ToString() + "))"
       _objDirSearcher.PropertiesToLoad.Add("memberOf")
       Dim arr As Object = Nothing
       Dim arrcol As Object() = Nothing
       Try
           ‘get all the user objects matching with the search pattern given
           Dim _objResults As SearchResultCollection = _objDirSearcher.FindAll()
           ‘loop with in each object
           Dim _objResult As SearchResult
           For Each _objResult In _objResults
               ‘Check for properties available
               If (Not _objResult Is Nothing) And _objResult.GetDirectoryEntry().Properties.Count > 0 Then
                   ‘verify for the mobile property not null
                   If Not _objResult.GetDirectoryEntry().Properties("memberOf").Value Is Nothing Then
                       If TypeOf _objResult.GetDirectoryEntry().Properties("memberOf").Value Is Object() Then
                           arr = CType(_objResult.GetDirectoryEntry().Properties("memberOf").Value, Object())
                       ElseIf TypeOf _objResult.GetDirectoryEntry().Properties("memberOf").Value Is Object Then
                           arr = CType(_objResult.GetDirectoryEntry().Properties("memberOf").Value, Object)
                       End If
                       Exit For
                   End If
               End If
           Next
       Catch e As Exception
           Return col
       End Try
Â
Zune Reboot Troubles – What I Have Discovered
Posted by Kelly's Chronicles in Zune on July 24, 2008
This is in reference to yesterday’s post concerning my Zune reboot issues (http://kellychronicles.spaces.live.com/blog/cns!A0D71E1614E8DBF8!324.entry ). It seems the only time it reboots without warning is if the Zune is running solely on the battery with the headphones connected. If I run it while connected to my PC or to my car player (has a cigarette lighter that powers it) this problem does not occur even if the headphones are attached. If I run it without the battery with no headphones (for testing purposes) it occasionally reboots without warning. MY biggest concern is I want this thing to work when I start my workout routine as if I don’t have music I know I will be bored.
I am suppose to be sending it in to the service center and they will send me a replacement. I shudder how thatprocess is going to go.
Anyway if anyone has any input on this I would be interested. John Kavanagh (http://jkavanagh58.spaces.live.com/default.aspx) was kind enough to correspond with me and let me know this appears to have been an issue that has affected Zune issues, but ipod users as well for some time. I guess I was just lucky enough to avoid this problem for the year since I bought it.
Replace and/or Translate Legacy File Characters in vb.net
Posted by Kelly's Chronicles in Uncategorized on July 24, 2008
Good Morning! It was an easy night. My wife had band practice and the kids were gone (my oldest to work and the youngest to camp) so I had a lot of time to myself. Which sometimes can be nice too. :). Anyway, yes my youngest called again from camp and the nurse ended up taking the phone away because she was acting somewhat hysterical when she found out her mom wasn’t coming to get her. It also appears my dad, who is at the same camp as the nature guide, told them not to allow her to leave camp. I am going to have to address that with him. I don’t disagree with not letting her leave but I didn’t like him stepping in like that. Oh well. So she will be coming home Friday and not a moment too soon from her opinion I am sure.
So today’s topic. This code was actually written years ago. Those of you who are involved with reading files from legacy systems such as AIX, UNIX will want to pay attention in particular. Also those of you who use the Dart Telnet components will find this interesting. Those of you who use IBM 3151 emulation (or other similar) on your systems, I found a way to translate the upper function keys. That could be the subject of a future post or if you want let me know you want that information and i will correspond with you directly.
Anyway, I had to find a way to translate what those systems do in a file to make a line break happen, a tab and etc. Usually though those files when brought to the Windows side would represent these markers as a simple square. It would do that because to Windows these characters had no meaning. But the actual information was there. It was just a matter of determining what was in it and what it meant. So here is what I came up with. This is assumes you are reading a single line of text from a flat file. If you need to, do a loop and and run this function. Or read the whole thing for all I care. 🙂
Public Sub TelnetDisplayData(ByVal showme As String)
           ‘Convert any \n\r to \r\n
           showme = showme.Replace(Chr(13) + Chr(10), vbCrLf)
           ‘Convert all naked \n to \r\n (2-step process)
           showme = showme.Replace(vbCrLf, Chr(10))
           showme = showme.Replace(Chr(10), vbCrLf)
           ‘Replace all Tabs with spaces
           showme = showme.Replace(Chr(9), "    ")
           ‘Remove <esc>[0m (all attributes off)
           showme = showme.Replace(Chr(27) + "[0m", "")
           ‘Remove <esc>[m (all attributes off)
           showme = showme.Replace(Chr(27) + "[m", "")
           TextBox1.Text = TextBox1.Text & showme ‘
       End Sub
Â
Recent Comments