开发者

Configure Service Settings in Windows 7 programmatically using VB.NET

开发者 https://www.devze.com 2023-02-01 16:41 出处:网络
If you edit a service in Windows 7 and go to the Log On Tab, there is an option to \"Allow service to interact with desktop\". I开发者_JAVA技巧\'m trying to ensure that it is set for a certain service

If you edit a service in Windows 7 and go to the Log On Tab, there is an option to "Allow service to interact with desktop". I开发者_JAVA技巧'm trying to ensure that it is set for a certain service using VB.NET. Does anyone know of a way to do this? Note: Doing this during the install of a program is not an option. It has to be done at run time.


Call ChangeServiceConfig with SERVICE_INTERACTIVE_PROCESS. The benefit of using Windows API is that it should takes care of the notification and consurrency part and invalidate the cache in other programs that uses service controller, and when something goes wrong, you get an error code back. Generally speaking you should not access the registry if you can use API to get/set a setting.


Service configuration is stored in the registry, under

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\

With a key for each service.

It appears that the third to last flag within the Type value corresponds to the 'interact with desktop' value.

For example, a service set to NOT interact with the desktop has a value of:

Type    REG_DWORD   0x0000010 (16)

whereas that same service, when set to be allowed to interact with the desktop has a value of:

Type    REG_DWORD   0x0000110 (272)

I can't say that this is guaranteed as I've not done any testing, but it may be a good place to start. You'd need to restart the service before the changes to this value take effect.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号