Tutorial: Automatically mine when computer is locked on Windows

From Bitcoin Wiki
Revision as of 23:51, 30 May 2013 by Flarn2006 (talk | contribs)
Jump to: navigation, search

Note: This tutorial is created with Windows 7 in mind. The exact steps are likely different for other versions of Windows.

If you want to mine Bitcoins, but also need to use your computer for other GPU-intensive tasks like gaming, it can be annoying to start mining each time you stop using your computer. On Microsoft Windows, there is a little-known way to automate tasks like this. For this tutorial, we will be using cgminer. If you don't already have it, download it from here, and extract it to a folder somewhere on your hard drive.

Configuring the security auditing settings

Configuring Windows to log when the computer is locked and unlocked.

Windows keeps a log of various types of events that occur on your computer. These events include software crashes and system service notifications, among other things. This event log is closely tied to another feature of Windows known as security auditing. Basically, every time certain tasks are performed that require user authentication, such as logging on to your computer, it creates a log entry. This feature is designed mainly for professionals who need to monitor corporate networks, but it can be useful for this purpose too. How? It is possible to program Windows to run programs whenever specific types of events occur.

Locking and unlocking your computer are two things that Windows can log, but by default it is not configured to do so. To enable this:

  1. Open the Run dialog (Windows+R) and type "secpol.msc".
  2. On the left, expand "Advanced Audit Policy Configuration", "System Audit Policies - Local Group Policy Object", and select "Logon/Logoff".
  3. On the right, double-click "Audit Other Logon/Logoff Events".
  4. In the dialog that appears, make sure "Configure the following audit events" and "Success" are checked.
  5. Click OK, and close the Local Security Policy window.

Using the Task Scheduler

Next, we need to tell Windows to respond to these events. There are two tasks we need to program: one to start mining when the computer is locked, and one to stop mining when the computer is unlocked.

Start mining when the computer is locked

  1. Open the Run dialog (Windows+R) and type "taskschd.msc".
  2. On the very right, select "Create Basic Task..." from the menu.
  3. Give it a name, such as "Start Bitcoin Mining". What exactly you type here doesn't matter, as long as you remember what it is in case you need to change something later. Click Next.
  4. Select "When a specific event is logged" from the list, and click Next.
  5. For "Log", select "Security". For "Source", select "Microsoft Windows security auditing." For "Event ID", type 4800. Click Next.
  6. Select "Start a program" from the list, and click Next.
  7. For "Program/script", click "Browse..." and select cgminer.exe. (You do remember where you extracted it, right?)
  8. For "Add arguments (optional)", type in the command line parameters. Make sure to add --api-listen --api-allow W: to the end.
    If you're unfamiliar with cgminer, you can use the following template: -o [pool server] -u [user/worker name] -p [password] --api-listen --api-allow W:
  9. Click Next, and then Finish.