Cách chuyển từ 1 file chạy EXE sang dạng Windows Service

Converting lhwsrv.exe to a Windows Service

You can convert lhwsrv.exe to a Windows Service by following the following steps. However this involves

  • using a Command Prompt (aka DOS box)
  • changing you PATH
  • editing your registry
  • fooling with Services

These are not for the faint of heart nor for those not familiar with Registry hacking and DOS boxes. Of course you should back up your system and your Registry before beginning – if you don’t know how to do these, click your Back button now. Also this probably only works for Win/XP and Win/Vista – if you have an older operating system, click your Back button now.


  1. Download and install the Windows Server 2003 Toolkit. You may have to search microsoft.com for it, but when I wrote this page, it resided at http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en. Of course the best way to search microsoft.com is via Google – try this: Google Windows Server 2003 Toolkit.
  2. Win/Vista will complain about compatibility issues – ignore that and go ahead with the install – the 2 programs you need work fine on Vista (if you have sufficient privileges).
  3. Open a DOS box: Click Start > Run (or maybe Search for Vista) and enter cmd & click the OK button. SC_VCE Testing System1
  4. Change to the directory when you installed the Windows Server 2003 Toolkit. If you took the defaults during installation, use the following:
  5. C:\Windows>cd C:\Program Files (x86)\Windows Resource Kits\Tools
  6. Run the following command where “C:\Program Files\Windows Resource Kits\Tools” should be replaced with the directory where you installed the Windows Server 2003 Toolkit:
  7. C:\Program Files\Windows Resource Kits\Tools>instsrv.exe lhwsrv “C:\Program Files (x86)\Windows Resource Kits\Tools\srvany.exe”
  8. The Toolkit install with have added C:\Program Files (x86)\Windows Resource Kits\Tools to your Path as the first directory. You will want to remove it (or at least move it). Bring up the Control Panel (Start > Settings > Control Pannel) and double-click the System applet. Find the “Advanced” Tab or “Advanced System Settings” link and click it; then click the Environment Variables button. Scroll down the Environment Variables list in the lower path of the dialog until you find the Path variable. Click Edit, press the Home key, and remove the Toolkit path from the beginning of the value. Click OK all the way out. You must remove the Toolkit from your PATH for Windows/Vista since many of the programs don’t work on Vista; you might want to keep it for Win/XP, but do so only if you are sure of what you are doing.
  9. Fire up RegEdit. You can do so by trying the regedit at the DOS box command prompt:
      C:\Program Files (x86)\Windows Resource Kits\Tools>regedit
  10. Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lhwsrv
  11. Right click on lhwsrv and click select ‘new‘ then ‘key.’ Name the new key ‘Parameters‘.
  12. Now double click the Parameters key and right click on the empty space in the right hand pane. Choose ‘new‘ then ‘string value‘. Name the new value ‘Application‘.
  13. Now repeat the last step, this time naming the string value ‘AppDirectory‘.
  14. Double click on ‘Application‘ and give it the location of lhwsrv.exe. For example, if you placed lhwsrv.exe in the c:\bin\ directory, you would type ‘c:\bin\lhwsrv.exe‘.
  15. Double click on ‘AppDirectory‘ and give it the location of the directory where your lhwsrv.exe can be found. Using the above example, the value here would be ‘c:\bin\’
  16. Your Registry should now look something like this (don’t worry if the Enum key is not present):

    Your Data will of course be where you have placed lhwsrv.exe rather than c:\l-drive\bin.

  17. You can now close RegEdit.
  18. Fire up the Services applet. You can get to this via Start > Settings > Control Panel. Then look for a Services Applet either in the main window or perhaps in Administrative Tools. You can even try running services.msc or services.exe at your command prompt.
  19. Find lhwsrv in the list and double-click it.
  20. It should look like this (Note that the Path to executable value is listed as C:\Program Files (x86)\Windows Resource Kits\Tools\srvany.exe. This is because the srvany file is acting as a carrier for the executable file of the program you chose.):

    Set the Startup Type to Automatic and click Start if necessary and you are done.


About thangletoan

Hallo Aloha

Posted on 09/09/2013, in Chính sách CNTT, Converting file EXE to Windows Service, Microsoft, Windows 2003, Windows Server 2008 R2, Windows Service and tagged , . Bookmark the permalink. Bạn nghĩ gì về bài viết này?.

Trả lời

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Đăng xuất / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Đăng xuất / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Đăng xuất / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Đăng xuất / Thay đổi )

Connecting to %s

%d bloggers like this: