Monday, November 14, 2011

Run application as/under Windows service

 1. need Instsrv.exe & Srvany.exe files from MS Resource Kit


  instsrv.exe -> for install service aplication (srvany.exe), 
  srvany.exe -> service which run our application, srvany can be renamed as you wish
(in my case I rename it as msagent.exe, it will be visible in process manager)

2. Install service:


  Copy srvany.exe(msagent.exe) to place from its will start (c:\windows\)

  INSTSRV.exe "Microsoft Agent" C:\Windows\msagent.exe 
  ("Microsoft Agent" is our service name, also can be renamed as you wish)

3. registry file

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Microsoft Agent]
"Type"=dword:00000010
"Start"=dword:00000002
"ErrorControl"=dword:00000001
"DisplayName"="Microsoft Agent"
"WOW64"=dword:00000001
"ObjectName"="LocalSystem"
"Description"="Manages Windows speech recognition"


[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Microsoft .NET Framework NGEN Agent\Parameters]
"Application"="C:\\Windows\\myaplication.exe"

------------

  rename "Microsoft Agent" if you put diferent name for your service
  "Description"="You can put any text for description, it will be seen under service description"
  "Application"="C:\\Windows\\myaplication.exe" modify your path for you aplication, and dont forget to copy app at that path.

import registry file to system
regedit /c /s registrysettings.reg



4. Final: (I use srvinst.bat file from c:\SRvC where I put\precopy all files)

copy C:\SRvC\msagent.exe C:\Windows\
C:\SRvC\INSTSRV.exe "Microsoft Agent" C:\Windows\msagent.exe
copy C:\SRvC\myaplication.exe C:\Windows\
regedit /c /s C:\SRvC\registrysettings.reg



Info:

in Win7 .bat file need run as adm..

and don't try "drop" service/application in system32 dir(service or app will not start..)
but under windows(windows/subdir) or program files no problem

in XP is possible to put in system32 dir/subdir

works on 64bit OS

- need srvany.exe(msagent.exe) mod Manufacturer signature for msconfig to show as Microsoft service..

No comments:

Post a Comment