Showing posts with label Windows Service. Show all posts
Showing posts with label Windows Service. Show all posts

Monday, August 10, 2009

Windows NT Service configuration

To debug current Windows Service configuration, try 'sc' on a command console.

For example 'sc query' pretty much shows the same configuration information as the registry tree which defines Windows services:

My Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

There's an interesting Windows Resource Kist that includes service configuration tools.

For example instsrv.exe to run ANY other .exe application as Windows service

C:\Program Files\Windows Resource Kits\Tools>instsrv.exe AAA "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"

The service was successfuly added!

C:\Program Files\Windows Resource Kits\Tools>instsrv.exe AA REMOVE

How to spawn a command shell under windows 'system' user

This trick can be useful if you want to debug user permission issues with a Windows NT service that logs on under "Local System account" (the default).

First, figure out your current system time:

C:\>time

The current time is: 6:15:18.57

Second, use the 'at' command to start an interactive command shell when the next minute starts:

C:\>at 6:16 /interactive cmd

Now inside this new command shell, try your command which is run under this new user.

Wednesday, July 15, 2009

InstallShield and Windows Services: ServiceExistsService doesn't work

So for me, ServiceExistsService didn't work at all.
There are some permission issues apparently (see http://community.acresso.com/archive/index.php?t-169135.html)
but the solution proposed there is a tad too heavy-weight for me.
Here's an alternative, use the Registry entry of a service to figure out if the service is installed or not:
// Indicates if the service with this key (e.g. myNewService) has been installed
function BOOL windowsServiceExists(serviceKey)
string szKey,szServiceName;
number nRootKey;
begin
nRootKey = HKEY_LOCAL_MACHINE;
if (RegDBSetDefaultRoot (nRootKey) <>
MessageBox ("Unable to set HKEY_LOCAL_MACHINE.", SEVERE);
return FALSE;
endif;
szKey = "SYSTEM\\CurrentControlSet\\Services\\" + serviceKey;
//MessageBox("Testing for service: " + serviceKey, INFORMATION);
if (RegDBKeyExist (szKey) = 1 )
then
//MessageBox("found service:" + szServiceName, INFORMATION);
return TRUE;
endif;
return FALSE;
end;