views:

617

answers:

2

I was searching for ways to change the start-up type of a Windows service and I found 2 ways to do this...

By editing the Registry Or By using the WMI classes

I want to know which one is the best... I want my application to run properly on both Windows and Vista.

+1  A: 

You can also use the win32 API directly. I'd definitely recommend the WMI class; it makes it most likely that if there are changes in future versions of windows that your code still works.

Jeremy
WMI also has the advantage that in theory it could potentially someday maybe be cross flatform. There isn't much chance that the registry or Win32 API calls ever would be.
EBGreen
+1  A: 

I you want to be safe for future versions of Windows, better use WMI.

If you are not thinking beyond Windows 7, I recommend the WinAPI functions (OpenSCManager and ChangeServiceConfig come to mind). I find them easier to understand, and there are tons of code examples on how to use them. WMI on the other hand is still new, and not as well documented.

Just never, ever, edit the registry directly. The WinAPI or WMI interfaces exist to abstract the task from the way Windows handles the data internally. Bypassing them brings the biggest risk of breaking in the future.

Treb