Next, let’s talk about service. If you want to start or stop the service, just use the net command. But if you want to add or delete a service, you need to use SC, etc. These tool systems do not come with their own (XP and 2003 come with their own SC). Although importing the registry is OK, it is not effective, and the reason will be mentioned later. It still has to rely on the inf file to make progress.
Add a service:
[Version]
Signature="$WINDOWS NT$"
[]
AddService=inetsvr,,My_AddService_Name
[My_AddService_Name]
DisplayName=Windows Internet Service
Description=Provides support for Internet information service management.
ServiceType=0x10
StartType=2
ErrorControl=0
ServiceBinary=%11%\
Save as, then:
setupapi,InstallHinfSection DefaultInstall 128 c:\path\
This example adds a service called inetsvr (Is it very similar to the system's own service, haha).
A few explanations:
1. The last four items are
Service type: 0x10 is an independent process service, and 0x20 is a shared process service (such as svchost);
Boot type: 0 Loading at system boot, 1 Loading at OS initialization, 2 Automatically start by SCM (Service Control Manager), 3 Manually start, 4 Disable.
(Note that 0 and 1 can only be used for drivers)
Error control: 0 Ignore, 1 Continue and Warn, 2 Switch to LastKnownGood settings, 3 Blue screen.
Service program location: %11% represents the system32 directory, %10% represents the system directory (WINNT or Windows), and %12% is the driver directory system32\drivers. For other values, see DDK. You can also use the full path without variables.
These four items are necessary.
2. In addition to the six projects in the example, there are LoadOrderGroup, Dependencies, etc. Not often used, so I won't introduce it.
3. There are two commas after inetsvr because an infrequently used parameter flags is omitted in the middle.
Delete a service:
[Version]
Signature="$WINDOWS NT$"
[]
DelService=inetsvr
Very simple, isn't it?
Of course, you can also express it to the purpose by importing and registering. But inf has its own advantages.
1. Export a registry key that comes with the system's own service, and you will find that its execution path is as follows:
"ImagePath"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,\
74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,74,\
00,6c,00,6e,00,74,00,73,00,76,00,72,00,2e,00,65,00,78,00,65,00,00,00
Too poor readability. In fact, it is %SystemRoot%\system32\, but the data type is REG_EXPAND_SZ. When manually importing the registry to add services, it is obviously inconvenient to define ImagePath in this way. If you use REG_SZ instead, there will be some problems - you cannot use environment variables. That is, only full paths can be used. There is no problem with inf files at all, ServiceBinary (i.e. ImagePath) automatically becomes REG_EXPAND_SZ.
2. The most important thing is that, like using SC and other tools, the effect of inf file takes effect immediately, and it must be restarted after importing reg.
3. The inf file will automatically add a Security subkey to the service's registry key, making it look more like the system's own service.
In addition, AddService and DelService, AddReg and DelReg can be used simultaneously and reused. That is, multiple service and registry entries can be added and deleted at the same time. For details, please check DDK.
Previous page123456Next pageRead the full text