tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

Win32_Service class and the types

18 Dec 2015 1 mins Best practice or not?, Windows

This is a story about a class named Win32_Service and the types. Types we all like (or hate, doesn’t matter in this case 😃). And the WMI.

I needed to create a Windows Service from my code and I eventually ended using WMI. The Win32_Service has a method Create with appropriate parameters. Nothing to see here. Or is it?

Look at, for example, ServiceType or ErrorControl. These are of type uint8. Sounds good. Just get the values from the list in documentation and you’re done. Then you try to load Win32_Service in other part of your code and you want to check these values. Boom. The casting fails. Checking the Win32_Service again you’ll find that these parameters there are plain string. What?

Yup. Pretty confusing. I was not expecting that. I’d really like to know the reason for that…

Related story.

Profile Picture Jiří Činčura is .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at www.tabsoverspaces.com.