HamSvc allows Hamster Classic to be run as a system service, which means, that it's not necessary to log in for starting Hamster - it's immediately started when the system is started.
The service itself is "HamSvc.exe" - it starts, stops and (partly) controls "Hamster.exe" in the background.
hamsvc.zip (40 KB, source code included)
Copy "HamSvc.exe" into the directory of "Hamster.exe" and start it with parameter "/install":
D:\Hamster\> hamsvc /install HamSvc, Running Hamster as NT-service, Vr. 1.0 Copyright 2000 by Juergen Haible Settings: Service file: D:\Hamster\srcsvc\HamSvc.exe Config. file: D:\Hamster\srcsvc\HamSvc.ini Service name: HamsterService Display name: HamsterService Dependencies: RPCSS App. file : D:\Hamster\Hamster.exe App. params.: Installing service ... Service installed.
If you want to start a script when Hamster starts, create a plain text file named "HamSvc.ini" in the same directory and add the following lines (just replace "MyStartScript.hsc" with the filename of your script):
For additional settings see the description of the configuration file HamSvc.ini below.
HamSvc was developed and tested under Windows NT 4.0 (Workstation and Server), but reports show, that it runs under Windows 2000, XP (Home+Pro) and 2003 as well.
It was repeatedly reported, that problems may arise when (different) users login and logoff on the computer running the service, especially on computers running under the server versions of Windows (e. g. Windows 2000 Server), or if fast user switching of XP is used. In this case, Hamster may stop working or may even die with an error message.
If you encounter this problem, there is no other reliable way than to hide the running Hamster by deactivating the "Interactive" option in the service settings. Such a hidden Hamster can partly be controlled by HamRC, a client for Hamster Classic's remote control server.
Hamster's OLE-interface can't be used if Hamster is started as a service, so you have to use Hamster scripts instead. Nevertheless, programs started by Hamster scripts ("execute" command) can still make use of OLE calls.
If the Windows user logs off, "Hamster.exe" is terminated by default. See notes for "[Application] Pars="-setting under HamSvc.ini for a solution with current Hamster versions.
Hamster's tray icon is missing after logging in (again), because there was no "tray" yet when Hamster was started. To work around this, create a script named "TrayRefresh.hsc" with the following lines:
#!hs2 HamMessage( 7, 0 ) HamMessage( 7, 1 )
Then create an icon for Hamster.exe in system's "StartUp" group ("AutoStart" group for german Windows versions) and add the filename of the script to the command line of the icon, e.g.:
Each time a user logs in, this script is then executed automatically and restores the icon.
HamSvc is configured by a plain text file named "HamSvc.ini", which has to be located in the same directory as "HamSvc.exe".
Most settings have default values, so you only have to add settings, which should change HamSvc's default behaviour.
Entries under [Service] control the service itself:
[Service] Name=HamsterService DisplayName=HamsterService Dependencies=RPCSS
Name-key determines the name of the service and defaults to
"HamsterService". This name may for example be used to control the service with
"net.exe" (e.g.: "net start HamsterService"). The service's name has to be
unique in the system, so if you want to start more Hamsters concurrently (not tested), you have to
change this name for the additional ones.
DisplayName-key determines the name, which is shown for the service. It
defaults to the name given under
Dependencies-key may contain a comma separated list of services, which
have to be started prior to HamSvc. It defaults to "RPCSS" (Remote Procedure Call
Service), which Hamster needs for its OLE-initialization.
The [Application]-section contains the settings for the application, which is controlled by the service (i.e. Hamster.exe):
[Application] File=D:\Hamster\Hamster.exe Pars=/svc MyStartScript.hsc init
File-key gives drive, directory and filename of the Hamster.exe to start.
If this setting is missing, Hamster.exe is expected in the same directory as HamSvc.exe.
Pars-key may contain additional parameters for starting Hamster, e.g. the
filename of a Hamster script to start.
Starting with Hamster Classic versions above 18.104.22.168, Hamster supports a "/svc" parameter, which prevents it from being terminated if current Windows user just logs off. If used and supported by your Hamster version, it has to be the first parameter like in the example above.
If "HamSvc.exe" is started without parameters or with "/run", the service's code is executed.
It does not hurt if HamSvc is started manually this way, but it makes no sense and is of no use, as Windows does this automatically when needed.
If "HamSvc.exe" is started with "/install", the service is installed.
The default service settings are always:
Use Windows' service control program, if you want to change any of these settings.
If "HamSvc.exe" is started with "/uninstall", the service is uninstalled - all registry settings regarding HamSvc are removed.
If "HamSvc.exe" is started with "/start", the service itself and the Hamster it controls are started. This is mostly useful for testing purposes, as the service is normally started automatically by Windows on system startup.
Note: Always, when the HamSvc service is started, it immediately tries to start Hamster.exe in the background, too. If something goes wrong here, you won't get one of these read-me-and-then-klick-me-away windows, as most of the time there's no user logged in when the service starts. You have to take a look in NT's event log to see, what really has happend.
If "HamSvc.exe" is started with "/stop", the service itself and the Hamster started by it are stopped.
If "HamSvc.exe" is started with "/pause", all local servers of the controlled Hamster are stopped.
If "HamSvc.exe" is started with "/continue", all local servers of the controlled Hamster are started again.
HamSvc uses NT's application event logfile to report information and errors.
Always check this log if something seems to go wrong - it may contain useful information for finding the problem.
============================================================================ HamSvc - Running Hamster as NT service. Copyright (c) 2000, Juergen Haible. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ============================================================================
Copyright © 2003 by Jürgen Haible - Impressum