View Full Version : How to check & uncheck an option in a preactivated service?
searcher123
11-09-2008, 12:44 AM
I have a program that I must follow the following steps manually to run it as a service:
Step 1: I must execute myprogram.exe /install in command line to run it as a service.
Step 2: I must start myprogram in Administrative Tools' Services list, after checking its Allow service to interact with desktop checkbox.
Step 3: I must stop the service, uncheck Allow service to interact with desktop and start it again.
How should I follow this process by SF8? A code please!.
Best Regards
SF has built-in actions to start/stop/query services, so I guess the question is how to set/reset "Allow service to interact with desktop"
Make sure box is un-checked and goto
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\<service_name>
Check the value of "Type"
Now check the box "Allow service..", apply, refresh Regedit window and check the value of Type again.
If I correctly remember this is the change that has to be made to set/reset desktop interaction directly (but you may do a registry snapshot immediately before and after the change and compare). Needless to say, check this on several systems. Also I'm not sure when the change becomes effective - immediately or after a service (re)start.
searcher123
11-09-2008, 06:05 AM
Thank you very much dear PWW,
Worked great :yes :yes
(...) I'm not sure when the change becomes effective - immediately or after a service (re)start.
The change was affected immediately.
Best Regards
P.S: For future needers:
Under windows XP
1. Type is a DWORD value.
2. Set it to 16 to Allow service to interact with desktop be checked
3. Set it to 272 to Allow service to interact with desktop be unchecked
P.S: For future needers:
Under windows XP
1. Type is a DWORD value.
2. Set it to 16 to Allow service to interact with desktop be checked
3. Set it to 272 to Allow service to interact with desktop be unchecked
Actually this isn't always like that, I haven't explained it the right way in my first post, sorry.
To allow a service to interact with desktop, the 8-th bit of 'Type' value must be set to 1. Or in other words, you should OR the current value (when Desktop interaction is disabled) with 256 decimal to set the 8-th bit to 1 and enable it.
To disable Desktop interaction , you should reset the 8-th bit.
So values of 16 and 272 are valid for your particular case/service only.
searcher123
11-10-2008, 07:54 AM
Actually this isn't always like that, I haven't explained it the right way in my first post, sorry.
To allow a service to interact with desktop, the 8-th bit of 'Type' value must be set to 1. Or in other words, you should OR the current value (when Desktop interaction is disabled) with 256 decimal to set the 8-th bit to 1 and enable it.
To disable Desktop interaction , you should reset the 8-th bit.
So values of 16 and 272 are valid for your particular case/service only.
Thanks for your supplementary explanation too :)
So, the following code will set Allow service to interact with desktop checked for any service:
nType = Registry.GetValue(HKEY_LOCAL_MACHINE, "System\\CurrentcontrolSet\\Services\\<ServiceKeyName>", "Type", true);
nNewType = nType + 256
Registry.SetValue(HKEY_LOCAL_MACHINE, "System\\CurrentcontrolSet\\Services\\Alerter", "Type", SessionVar.Expand(nNewType), REG_DWORD);
and the following code will set it unchecked for the same service again:
nType = Registry.GetValue(HKEY_LOCAL_MACHINE, "System\\CurrentcontrolSet\\Services\\<ServiceKeyName>", "Type", true);
nNewType = Math.Abs(nType - 256)
Registry.SetValue(HKEY_LOCAL_MACHINE, "System\\CurrentcontrolSet\\Services\\Alerter", "Type", SessionVar.Expand(nNewType), REG_DWORD);
OK?
well the best way would be to bitwise OR the current value with 256 decimal to enable, and to bitwise AND the current value with 65279 decimal to disable.
But AFAIK Lua doesn't support bitwise operations. Maybe there is a plugin or something for the purpose.
In your case Type has known values, so you may
-to set - if current value < 256, add 256, else do nothing(already set)
-to reset - if current value >256, subtract 256, else do nothing(already reset)
Setting Type to Math.Abs(nType - 256) may cause a mess if desktop interaction is already reset
searcher123
11-11-2008, 05:40 PM
(...)But AFAIK Lua doesn't support bitwise operations.(...)
I wrote a simple utility for eliminating this leakage in SF. The attached will bitwise AND, OR and XOR two number and return the result to SF or show it on Command Com window. I hope be useful for future needers.
Best Regards
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.