Running PeerGuardian 2 as a system service

From Phoenix Labs Wiki

Jump to: navigation, search

Contents

Legal notice

EXCEPTION LIST

  • Anyone can use these document(s)/file(s) and edit them in any way and use all resources here to make PG2 run as a system service and distribute it, but you must give credit to the author(s).
  • No one can be excluded from using this guide, period.
  • Phoenix Labs or anyone associated with Phoenix Labs dotorg cannot be held liable for using/creating this guide.
  • This agreement must be used in conjunction with this guide if you use, distribute, or edit the guide.
  • Only fox can edit/update this exception list, unless you have fox's permission.
  • If you have a complaint about this, please e-mail [email]foxatphoenixlabs@gmail.com[/email].
  • This EXCEPTION LIST can be updated without notice and thereby void the previous exceptions.


Just give credit to Zepman for creating this as he so claims that he created this.

under his first exceptions only can ones be excluded from these rulse and guidelines/copyright agreement was and i quote "The license does not apply to the people who aided William Erwin with the Methlabs.org split-up in august 2005."

and since I aided William Erwin aka Cerberius, I am excluded from his copyright agreement and so I edit away for all to use.

You can read the details about the license here


Update: (18-dec-2005): Included instsrv.exe and srvany.exe in an attachment since Windows 2000 users can't install the Windows 2003 Resource Kit Tools. Also updated the FAQ for a bit and added a Credits-section.

Update: (27-sep-2005): The guide is back on-line and fully works with PeerGuardian 2 Beta 6b.

Summary: This step-by-step guide will tell you how to run PeerGuardian 2 as a system service without expensive software like Firedaemon or other shareware. We are going to use the official tools from Microsoft to get this going. This method was last tested with Beta 5b, but should also work with newer versions. srvany.exe from Microsoft is used as the 'service wrapper' for this.

Requirements

  1. Windows 2000/XP/2003
  2. Administrator priviliges on the machine
  3. PeerGuardian 2 (latest version from HERE)
  4. The Windows 2003 Resource Kit Tools (available HERE)

Step-by-step installation

Step 1

First things first: download and install PeerGuardian 2. This guide will assume you installed PeerGuardian 2 in the default location (C:\Program Files\PeerGuardian2\). [b]Do not choose the option 'start when Windows starts' during installation![/b] Make sure the program runs like it would normally run (that is: without any errors). Also make sure that within PeerGuardian 2 the option 'Always start minimized' is turned on and that the option 'Show splash' is turned off. This will free a small amount of memory when run as a service.

New beta 6 options: make sure that these options are also set. Turn off notification (the option called 'Notify on' should be turned off). Lastly, turn on the function called 'Auto-close update window after X seconds' is turned on. I choose 3 seconds and that seems to work fine. You can configure the rest of the options (especially the ones having to do something with logging), but stay away from the three startup options (they should all be turned off) and the options we just set.

To check that PeerGuardian 2 works, simply open a command-prompt and type 'ping www.anti-piracy.de' while PeerGuardian 2 is running. If you get 'Request timed out.', everything works like it is supposed to be. However, if you get get a ping, PeerGuardian 2 isn't blocking any internet-traffic. This is bad and before you continue, you should get it working. If Peerguardian 2 works normally (the log shows that traffic is being blocked, the auto-update works and closes when you click on 'Check Updates', etc.), move on.

Step 2

Download srvtools.zip (see the end of this post). This ZIP contains two command-line tools that are needed: [b]instsrv.exe[/b] and [b]srvany.exe[/b]. You can also download and install the Windows 2003 Resource Kit Tools from Microsoft website, which also includes these tools (the Resource Kit Tools will only install when Windows XP or 2003 is used). Don't worry, the tools included in the ZIP-file (the same tools that are included in the Resource Kit Tools) work with Windows 2000, XP and 2003.

Step 3

Copy instrv.exe and srvany.exe to your PeerGuardian 2-folder, C:\Program Files\PeerGuardian2\ . You can also put them anywhere else, but for the sake of simplicity I put them in the PeerGuardian 2-folder for this guide.

Step 4

Now, open a command-prompt (Start -> Run -> 'cmd' -> OK) and type the following commands: [code]cd "C:\Program Files\PeerGuardian2" instsrv PeerGuardian2 "C:\Program Files\PeerGuardian2\srvany.exe"[/code]Now we made a service of srvany.

Step 5

Now, we are going to do a little registry-editing. I have two choices:

The easy road:

Save the following text in a .reg-file with Notepad and run it. It will configure your registry so srvany will start PeerGuardian 2.

REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PeerGuardian2\Parameters] "Application"="\"C:\\Program Files\\PeerGuardian2\\pg2.exe\""

The hard road:

Start regedit. Go to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PeerGuardian2\ Create a new key called 'Parameters'. Put a String-value called 'Application' in it. Make the value the path to PeerGuardian 2 ("C:\Program Files\PeerGuardian2\pg2.exe") [b]with[/b] quotes.

Explanation: The 'Parameters'-key you just created isn't used by Windows, but by srvany. It tells srvany that when it is started as a service, under the name 'PeerGuardian2', that it should use the information contained in that key. Here are all usable strings that I know off:

Application: tells srvany which executable to run. Use quotes when you are using long-path-names (with spaces or other special characters). AppParameters: any parameters you want to give to the application. This is not used in this guide. AppDirectory: the directory you want the application to run in. This is not used in this guide.

Step 6

Now we are going to test if it works. Make sure PeerGuardian 2 isn't running, since we are going to start it as a service! Open a command-prompt and type: [code]net start PeerGuardian2

Windows should now report that 'The PeerGuardian2 service was started successfully.'. Now we should test if PeerGuardian 2 blocks anything. In the command-prompt, type:

ping www.anti-piracy.deIf you get 'Request timed out.', congratulations! PeerGuardian 2 is fully running as a service now!

Step 7

Restart your computer, log into Windows and ping [url]www.anti-piracy.de[/url] again. If you get 'Request timed out.' again, it works!

Stopping/restarting the service

(credits to D3F for pointing out how to stop the driver of PeerGuardian 2 so that there is no need to use the recovery-tool)

To stop the service, type the following commands in your console:

net stop PeerGuardian2
net stop pgfilter
This will both stop PeerGuardian and it's filter-driver.

To restart the service (stop, start), type the following commands:

net stop PeerGuardian2
net stop pgfilter
net start PeerGuardian2

Uninstalling the service

You can uninstall the service by first stopping the service and driver. After this, type the following commands in a command-prompt to remove the service:

cd "\Program Files\PeerGuardian2"
instsrv PeerGuardian2 REMOVE

Upgrading PeerGuardian 2

Upgrading is pretty easy. You don't have to uninstall everything that makes it a service. Simply stop the service and use Start -> Settings -> Control Panel -> Add/Remove Programs to remove the old version of PeerGuardian 2. After you are done, delete pg2.conf from the PeerGuardian 2-folder (C:\Program Files\PeerGuardian2) and the list-files (in the Lists-folder). Don't delete anything else.

Now, download the new version of PeerGuardian 2 and install it in the old folder (most probably it still is the default installation path). Configure PeerGuardian 2 again after installation (load the lists you want, configure auto-update, start minimized, disable splash screen, [b]don't[/b] start when Windows starts, don't notify, enable 'Auto-close update window after X seconds') and check that it blocks with normal usage. If it works without problems, close PeerGuardian 2 and start it as a service again by using 'net start PeerGuardian2'. Again, check that it blocks traffic. You succesfully upgraded PeerGuardian 2 if it does.

Frequently Asked Questions

What is a system service?

A system service is a process which runs on your computer. It is used for vital parts of Windows (like the Remote Procedure Call-service) which must always run, regardless whether a user is logged in or not. Think of a system service as a program that is started by the computer, not a program started by a user. Off course, many more interesting things can be run as a service (for example: server-software like MySQL or Microsoft's own Internet Information Services).

Why run PeerGuardian 2 as a system service?

  • When other people log into your computer and/or make use of it's facilities (P2P, mail, whatever) you don't want them to close PeerGuardian 2 by accident.
  • Because you use other P2P-software in the background (as a service, for example) and you can't always be logged in.
  • Because you don't trust the internet, even if you are not logged into your computer and are not running any P2P-software.
  • Because you have a rented a computer running Windows 2000/XP/2003 on the web with only Termininal Services-access to it and don't want to keep your session open when you close the connection.

It doesn't work! How do I make it work?

Post your question in this topic and maybe we can fix things. Be sure to describe as much as possible: which version of PeerGuardian 2 are you using, are you using any other firewall-software, does PeerGuardian 2 work at all, etc. Note that this topic is NOT for general Peerguardian 2-questions! It only helps people running PeerGuardian 2 as a system service. Nothing more, nothing less.

[b][i]When I try 'net stop PeerGuardian2', followed with 'net start PeerGuardian2'[/i][/b] (to make the service restart) [b][i]PeerGuardian 2 doesn't work anymore![/i][/b] This is a known 'problem' with PeerGuardian 2. Use 'net stop PeerGuardian2' in the command-prompt to stop the service. Now, type 'net stop pgfilter' in the command prompt (or use 'Recover PeerGuardian' in your Start Menu) to recover the driver of PeerGuardian 2. When it say's the driver can't be stopped, try it again after a few seconds. After it says that the driver is stopped/removed, use 'net start PeerGuardian2' to start PeerGuardian 2 as a service again.

[b][i]I can't see any user-interface once I'm logged in. Why is that?[/i][/b] In general, people want services to be hidden. That's their primary usage.

[b][i]How can I do some more diagnostics when I can't see the user-interface? Ya know, further checking that it works. I don't trust it to ping to [url]www.anti-piracy.de[/url]...[/i][/b] Very easily! Just go to Start -> Settings -> Control Panel -> Administrative Tools -> Services and double-click on the Peerguardian2-service. Enable 'Allow service to interact with desktop'. And click OK. Now, stop PeerGuardian 2 by clicking on 'stop' on the 'General'-tab. Use 'net stop pgfilter' in a command-prompt to remove the driver. Now, start PeerGuardian 2 as a service again (use the 'start' button on the general tab of the settings of the service, or simply use 'net start PeerGuardian2' again from the command-prompt). There you go! Now you have PeerGuardian 2 running as a service and you can modify it's settings, check the logs whether things get blocked or not, enable/disable 'block HTTP', etc. Disable 'Allow service to interact with desktop' in the settings of the service and make sure to close Peerguardian 2 again by stopping the service, stopping/recovering the filter, and starting it to hide PeerGuardian 2 again.

[b][i]When I ping to [url]www.antipiracy.de[/url][/b][/i] (or some other blocked site)[b][i], I don't get 'Request timed out'. Instead it gives me 'Destination Host Unreachable' or some other reply that indicates that a ping failed. Is PeerGuardian 2 working or not?[/b][/i] Don't worry, PeerGuardian 2 is doing fine. In the past, r00ted, bbb_uk and myself found out that this is caused by the 'Windows Firewall/Internet Connection Sharing (ICS)'-[b]service[/b]. If the Windows Firewall, Internet Connection Sharing [b]and[/b] the service are disabled then you will get the normal 'Request timed out'. This will only change the output of 'ping', however. PeerGuardian 2 will work with or without Windows Firewall and/or Internet Connection Sharing.

Does PeerGuardian 2 auto-update when it's run as a service?

Yes, but only for the lists. When configured correctly (it auto-updates when used as an application), PeerGuardian 2 will auto-update the lists as a service. PeerGuardian 2 can only update the lists on it's own. Upgrading PeerGuardian 2 itself needs to be done manually. This is also explained in this guide.

What is this whole 'srvany'-deal? Isn't it possible to run PG2 as a service directly?

A program needs a couple of 'hooks' to run as a system service. As far as I know, PeerGuardian 2 hasn't got these. srvany is a wrapper which provides these 'hooks' for any application it tries to use.

Pro's/Con's of this 'solution'?

Pro's:

  • PeerGuardian 2 is always started, whether you are logged into your computer or not!
  • When other people log into the computer, they can hardly 'see' PeerGuardian 2 (only as a process/service). This is ideal for your little brother/sister/parents/dog who log in with their own account(s).
  • It saves another icon on the precious space of your overcrowded taskbar.

Con's:

  • It is a bit hard to make the user-interface visible and to view the logs (stop service, recover driver, start as application).
  • srvany.exe is loaded into memory as long as PeerGuardian 2 is running. It takes ~1MB, but doesn't take any CPU-resources (doesn't go any higher than 00%).

Credits

These people helped me with this guide and I thank them for the support they have given.

  • bbb_uk (for the help and support he gave me during the Methlabs split-up in August 2005 and for all the testing)
  • D3F (for pointing out that the driver from PG2 can simply be stopped by using the command-line)
  • lister (for noticing that the Windows 2003 Resource Kit Tools don't want to install with Windows 2000)
  • r00ted (together with bbb_uk, they were the first to notice as to why ping gave different outputs on different systems)

Files

ADD SOMETHING HERE

Personal tools