Jump to content

start µtorrent with windows IF there are any incomplete downloads


Recommended Posts

Basically, what I want to do is start µtorrent automatically with windows so I cannot forget to start it, but I also don't like programs running in the background when I don't need them.

So I wrote a batch script and adapted a python (3.2) script which I use for deluge on linux.

I let µtorrent execute the batch script (C:\Users\USERNAME\Desktop\µtorrentscript2.bat %S) which then runs the python script with the appropriate argument so that a file containing the number of downloading torrents is updated.

When windows starts I let it run the python script with the start argument (a shortcut which targets C:\Users\USERNAME\Desktop\script_utorrent\utorrent_script.py -s) so that the script checks if there are active torrents and if so starts µtorrent.

I might rewrite the python script so that I only need a single script, but I'm pretty happy with this result.

However, would anyone know a smarter way to get the job done? I know µtorrent has a webui so I think it can be done more easily, but I don't know the slightest thing about it...

Batch script:

@echo off
set SCRIPTLOCATION="%USERPROFILE%\Desktop\script_utorrent\utorrent_script.py"
IF %1==6 (start python.exe %SCRIPTLOCATION%)
IF %1==3 (start python.exe %SCRIPTLOCATION% -d)
IF %1==5 (start python.exe %SCRIPTLOCATION% -d)
IF %1==11 (start python.exe %SCRIPTLOCATION% -d)
IF %1==13 (start python.exe %SCRIPTLOCATION% -d)

python script:

#!C:/Python32/python.exe -u
import pickle, subprocess, sys

path = "C:\\Users\\USERNAME\\Documents\\utorrent.txt"
path2 = "C:\\Program Files (x86)\\uTorrent\\uTorrent.exe"

try: argument = sys.argv[1]
except: argument = 'void'

def main ():
if (argument == '--start') or (argument == '-s'): #start
value = load(path) #load the value
if (value > 0):
elif (argument == '--decrease') or (argument == '-d'): #decrease
save(adjust(1)) #default
return 0

def save(value):
file = open(path, 'wb')
pickle.dump(value, file)
return 0

def adjust(value):
storedvalue = load(path) + value
if storedvalue < 0:
storedvalue = 0
return storedvalue

def load(path): #extract the value from the file
unpicklefile = open(path, 'rb')
data = pickle.load(unpicklefile)
except: #no file found; it will be created upon saving
data = 0
return data

if __name__ == "__main__":

Link to comment
Share on other sites

I realised that python isn't as popular on windows as on linux, so I wrote a bit of C++ code to replace the python script, I hope you like it ;)

#include <string>
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;

string path = "C:/Users/USERNAME/Documents/utorrent_data.txt";
string commando = "start /D \"C:\\Program Files (x86)\\uTorrent\" utorrent.exe";
void save(int);
int load();
int adjust(int);

int main(int argc, char *argv[])
if (argc > 1)
string arg = argv[1];
if ((arg == "-s") || (arg == "--start"))
{if (load() > 0)
else save(0);}
else if ((arg == "-d") || (arg == "--decrease"))
return 0;

void save(int value)
ofstream ofile(path.c_str());
ofile << value;

int load()
ifstream ifile(path.c_str());
if (ifile.is_open())
int value;
ifile >> value;
return value;
return 0;

int adjust(int value)
if ((load() + value) <= 0)
return 0;
return load() + value;

the new batch script:

@echo off
set COMMAND=START /D "%USERPROFILE%\Documents" program.exe
IF %1==6 (%COMMAND%)
IF %1==3 (%COMMAND% -d)
IF %1==5 (%COMMAND% -d)
IF %1==11 (%COMMAND% -d)
IF %1==13 (%COMMAND% -d)

Link to comment
Share on other sites

  • 3 weeks later...

srr for bumping this thread, but doesn't anyone have a better solution?

Couldn't it be possible to do something similar, but better, by making an app which does the job?

I have absolutely no idea how these apps are written, some info on this would be welcome as well.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...