Retrieve The Status of a Windows Service

Here is an easy way to get the status of a Windows service. Public Function ServiceStatus(serviceName As String) As  ServiceControllerStatus Dim service As ServiceController = LoadService(serviceName) If service IsNot Nothing Then Return service.Status Else Throw New InvalidOperationException("Service not  found.") End If End Function Private Function LoadService(serviceName As String) As ServiceController      Return ServiceController.GetServices().Where(Function(p) p.ServiceName = serviceName).FirstOrDefault() End Function Here are the values for service status: ContinuePending Paused PausePending Running StartPending Stopped StopPending This and lost  more code can be found in the … Continue reading Retrieve The Status of a Windows Service

Make Your Apps Talk

Want to add speech to any of your apps running in Windows? It's pretty easy using the SpeechSynthesizer in the .NET Framework. You can see this code in action in my Visual Studio backup or cleaner apps. I use text to speach to notifiy the user what the app is up to without having to … Continue reading Make Your Apps Talk

Check To See If Process Is Already Running

Do you need to see if a process is already running? It's pretty easy with the code below. I wrote this code for my console apps .NET back utility and .NET file cleaner utility. ''' <summary> ''' Check to see if the current app is already running. ''' </summary> ''' <returns><c>true</c> if app is not running, <c>false</c>.</returns> Public … Continue reading Check To See If Process Is Already Running

Compress Files

There are a number of ways to compress things in .NET, but I found out that only the code below works for files. I wrote the code below for my console apps .NET back utility. Imports System.IO.Compression ''' <summary> ''' Compresses the file. ''' </summary> ''' <param name="sourceFileName">Name of the source file.</param> ''' <param name="destinationFileName">Name of … Continue reading Compress Files

How To Kill A Process

Do you need to kill (stop) a process running on Windows?

dotNetTips.DevBackup Utility

The dotNetTips.DevBackup is a console tool that will quickly backup your Visual Studio code files. I wrote this app to backup source files before retrieving source from source control and at the end of the day. Note: It's recommended to close all instances of Visual Studio before running this app. This app will also stop … Continue reading dotNetTips.DevBackup Utility

dotNetTips.Dev.Cleaner Utility

The dotNetTips.Dev.Cleaner is an app that will quickly remove temporary and cached files created by Visual Studio and SQL Server. The reason I created this app is because from time to time Visual Studio builds will error for some unexplained reason, especially after getting new source from source control. It's because these temporary and cached files … Continue reading dotNetTips.Dev.Cleaner Utility

Make Disposing Objects Easier

As I talked about in my What’s the Purpose of the “using” Statement? post, disposing of your objects is very important in your application to prevent issues like virtual memory leaks. Equally important is as a developer of a type (class) that use any types that implements IDisposable, then your type must also implement IDisposable. … Continue reading Make Disposing Objects Easier

Type Design: Equals and HashCode

Good type design dictates that the Equals should always be overridden. This is actually a FXCop violation but 99.99% of types that I see, never has it (or GetHashCode).  Overriding Equals is pretty easy. Public Overloads Function Equals(ByVal obj As [Object] ) As Boolean Try Dim ci = DirectCast (obj, ComputerInfo ) Return (ci.OSFullName = … Continue reading Type Design: Equals and HashCode

Checking a DataTable for Data

Whenever you retrieve a DataTable from a data source, there no guarantee that there is actual data in it. Before you start looking for rows, you should always validate that that is it's not null and also there are rows. Here is a easy way to do it using extensions. public static class DataTableExtensions   … Continue reading Checking a DataTable for Data