Creating Windows Services

Creating a windows service in .net turns out to be a really simple thing. Instead of me doing a write up on it i will give you a like to a walkthrough on msdn and you can check it out.

But what i will say is that i wanted to be able to edit the service configuration once it was started through a desktop interface. This was accomplished by saving the data to the registry and letting the service get its configuration from there. My Service itself runs a timer and checks periodically for new settings from the registry. I played around with a thread in a wait state but this took up too much cpu. A timer works very well with very consistent results.

The desktop app that was created to modify the settings was a simple .net app and it basically just formats data and modifies the appropriate registry values. here is a small snippet of getting and adding data to the registry.

Getting Data

        Dim regKey As RegistryKey
        regKey = Registry.LocalMachine.OpenSubKey("Software\PPSPlus\MigrationApp\Data", False)
        If regKey Is Nothing Then
            regKey = Registry.LocalMachine.OpenSubKey("Software\PPSPlus\MigrationApp\Data", False)
        End If
        Dim lr As String = regKey.GetValue("LastRun", "")
        Dim db As String = regKey.GetValue("Debug", "")
        Dim pk As String = regKey.GetValue("PPSImportKey", "")
        RegImportData = regKey.GetValue("ImportData", "")
        RegImportType = regKey.GetValue("ImportType", "")
        Dim df As String = regKey.GetValue("ForceRun", "")

Adding Data .

      Dim regKey As RegistryKey
        regKey = Registry.LocalMachine.OpenSubKey("Software\PPSPlus\MigrationApp\Data", True)

        regKey.SetValue("LastRun", DateTimePicker1.Value.ToString)
        regKey.SetValue("Debug", ComboBox1.SelectedItem.ToString)
        regKey.SetValue("PPSImportKey", TextBox3.Text)
        regKey.SetValue("ImportData", TextBox4.Text)
        regKey.SetValue("ImportType", ComboBox2.SelectedItem.ToString)
        regKey.SetValue("ForceRun", ComboBox3.Text)

And that’s all he wrote.

This entry was posted in Uncategorized. Bookmark the permalink.

4 Responses to Creating Windows Services

  1. Ebony says:

    That’s a smart way of lokoing at the world.

    • Auth says:

      actually it was just that one call that was trying to pass two vars. The other readElement calls were fine, so I just reemvod the $SCOInstanceID from the call in getValue.php. I also modified the javascript in api.php so the function LMSInitialize returns a reference to itself (return this) instead of true.With those two modifications, all seems to be working well enough for me to begin integrating it with our LMS.Thanks,Mike

      • Eric says:

        Hey thanks for this. I nedeed a script to run in our mixed 2007/2010 dev environment. This worked like a charm.I made a couple of simple changes to the script to make it more useful to us:1. removed the -Append option when writing the header so that it overwrites the output from any previous runs (don’t need to see those results)2. added last line to display the results back to the screen: get-content .\results.csv

  2. 01mobile says:

    Hello just wanted to give you a quick heads up and let you know a
    few of the images aren’t loading properly. I’m not sure why but I think its a
    linking issue. I’ve tried it in two different internet browsers
    and both show the same outcome.

Leave a Reply to 01mobile Cancel reply

Your email address will not be published. Required fields are marked *