If I want to quickly debug the service, I just drop in a Debugger.Break()
in there. When that line is reached, it will drop me back to VS. Don't forget to remove that line when you are done.
UPDATE: As an alternative to #if DEBUG
pragmas, you can also use Conditional("DEBUG_SERVICE")
attribute.
[Conditional("DEBUG_SERVICE")]
private static void DebugMode()
{
Debugger.Break();
}
On your OnStart
, just call this method:
public override void OnStart()
{
DebugMode();
/* ... do the rest */
}
There, the code will only be enabled during Debug builds. While you're at it, it might be useful to create a separate Build Configuration for service debugging.
You have at least three options. I have presented them in order of usage preference.
Method 1 - You can use the SC tool (Sc.exe) included in the Resource Kit.
(included with Windows 7/8)
Open a Command Prompt and enter
sc delete <service-name>
Tool help snippet follows:
DESCRIPTION:
SC is a command line program used for communicating with the
NT Service Controller and services.
delete----------Deletes a service (from the registry).
Method 2 - use delserv
Download and use delserv command line utility. This is a legacy tool developed for Windows 2000. In current Window XP boxes this was superseded by sc described in method 1.
Method 3 - manually delete registry entries (Note that this backfires in Windows 7/8)
Windows services are registered under the following registry key.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
Search for the sub-key with the service name under referred key and delete it. (and you might need to restart to remove completely the service from the Services list)
Best Answer
You don't run things through the
[Icons]
section.If you want an icon to start a service, use something like:
Update after the question was clarified, but left here for posterity:
If you want Inno to start the service, you either use the SCM API called from theAfterInstall
entry of the service itself or a[Run]
entry: