+ Reply to Thread
Results 1 to 9 of 9

Thread: Get PID from uTorrent on startup

  1. #1

    Get PID from uTorrent on startup

    Description
    This config will allow you to launch any executable and will output the PID in a text file named <directory from where the cmd is launched>-pid<pid number>.txt. The pid is also inside the text file. This is needed for multiple instances of uTorrent.
    PS And yes, the codes are mine.

    Create a .cmd file in the same folder as utorrent.exe/userenity.exe with the following content:
    Code:
    pushd %~dp0
    set execName=userenity.exe
    for %%a in ("%~dp0\.") do set parentdir=%%~nxa
    
    call pexec.cmd -exec "%cd%\%execName%" -workdir "%cd%" -commandline "/recover" >%parentdir%-pid.txt
    for /f "delims=" %%a in (%parentdir%-pid.txt) do set pid=%%a
    
    del /q _pid*.txt
    echo 2>_pid%pid%.txt
    And also create a new .cmd script in a windows PATH variable location:
    Code:
    @echo off
    setlocal enabledelayedexpansion
    
    if "%~1" NEQ "" (
    	if "%~1" NEQ "-help" (
    		call :proc %*
    		exit /b %ERRORLEVEL%
    	)
    )
    
    call :echoHelp
    exit /b
    
    :proc
    	call :argParser %*
    
    	if "%exec%" EQU "" (
    		call :err 1000
    		exit /b %ERRORLEVEL%
    	)
    
    	if "%host%" NEQ "" (
    		set host=/NODE:%host%
    		if "%user%" NEQ "" (
    			set user=/USER:%user%
    			if "%pass%" NEQ "" (
    				set pass=/PASSWORD:%pass%
    			)
    		)
    	)
    
    	if "%record%" NEQ "" (
    		set record=/RECORD:%record%
    	)
    
    	set global_params=%record% %host% %user% %pass%
    
    	for /f "usebackq tokens=*" %%G IN (`wmic  %global_params%  process call create "%exec% %commandline%"^,"%workdir%"`) do ( 
    		rem echo %%G
    		set _tmp=%%G
    		set _tmp=!_tmp:^>=^^^>!
    		echo !_tmp! | find "ProcessId" > nul && (
    			for /f  "tokens=2 delims=;= " %%H in ('echo !_tmp!') do (
    				call set /A PID=%%H
    			)
    		)
    		echo !_tmp! | find "ReturnValue" > nul && (
    			for /f  "tokens=2 delims=;= " %%I in ('echo !_tmp!') do (
    				call set /A RETCOD=%%I
    			)
    		)
    		call :concat
    	)
    	set _tmp=
    	
    	rem successful execution
    	if "%PID%" NEQ "" (
    		echo %PID%
    		exit /b
    		rem exit /B %PID%
    	) else (
    		call :err %RETCOD%
    	)
    exit /b %ERRORLEVEL%
    
    
    :concat
    
    	call set output=%output% ^& echo !_tmp:^>=^^^>!
    exit /b
    
    :argParser
    
    	set comstr=-exec-commandline-workdir-host-user-pass-record
    	:nextShift
    	set /A shifter=shifter+1
    	echo %comstr% | find "%~1" > nul && (
    		set _tmp=%~1
    		set !_tmp:-=!=%~2
    	)
    	shift &	shift
    	if %shifter% LSS 7 goto :nextShift
    	set _tmp=
    	set shifter=
    exit /b
    
    :echoHelp
    
    	echo %~n0 -exec executubale {-commandline command_line} { -workdir working_directory} 
    	echo  {-host  remote_host {-user user {-pass password}}} {-record path_to_xml_output}
    	echo\
    	echo localhost cant' be used as in -host variable
    	echo Examples:
    	echo %~n0  -exec "notepad" -workdir "c:/"  -record "test.xml" -commandline "/A startpid.txt"
    	echo %~n0  -exec "cmd" -workdir "c:/"  -record "test.xml" -host remoteHost -user User
    exit /b
    
    :err
    	if %1 EQU 2          (set errmsg=Access Denied)
    	if %1 EQU 3          (set errmsg=Insufficient Privilege)
    	if %1 EQU 8          (set errmsg=Unknown failure ^& echo Hint: Check if the executable and workdit exists or if command line parameters are correct.)
    	if %1 EQU 9          (set errmsg=Path Not Found ^& echo Hint: check if the workdir exists on the remote machine.)
    	if %1 EQU 21         (set errmsg=Invalid Parameter ^& echo Hint: Check executable path. Check if host and user are corect.)
    	if %1 EQU 1000       (set errmsg=Executable not defined.)
    	if "%errmsg:~0,1%" EQU "" (set errmsg=%output% ^& echo Hint: brackets, quotes or commas in the password may could breack the script.)
    
    	echo %errmsg%
    exit /b %1
    Last edited by Master Razor; 27.12.15 at 13:53.
    Reply With QuoteReply With Quote
    Thanks

  2. Who Said Thanks:

    mmmmm (28.12.15) , anon (28.12.15)

  3. #2
    what's the title of .cmd ?
    (i tried pid.cmd for both windows and serenity directory but no work)
    Busy , new things always comes
    Its the time for personal life ,Still here from time to time, Greeting for everybody All .

    Its easy way to capture the announces :-
    Tutorial how use SmartSniff to Capture announces for Bittorrent
    Reply With QuoteReply With Quote
    Thanks

  4. #3
    Sorry about that. The first code you can name it whatever you want. The second script is called pexec.cmd
    Reply With QuoteReply With Quote
    Thanks

  5. #4
    I named (the second as you said) and the first one uSerenity.cmd and run it --> open uSerenity auto and make two files :
    1. _pid4380.txt (empty , zero byte)
    2. uTorrent_Serenity_2.2.1_25130-pid.txt (full of something like this)

    Code:
    D:\Pro\Torrent\وTorrent\uTorrent_Serenity_2.2.1_25130>ï»؟@echo off 
    
    D:\Pro\Torrent\وTorrent\uTorrent_Serenity_2.2.1_25130>setlocal enabledelayedexpansion
    Edit:
    What that means ?
    Last edited by mmmmm; 27.12.15 at 21:37.
    Busy , new things always comes
    Its the time for personal life ,Still here from time to time, Greeting for everybody All .

    Its easy way to capture the announces :-
    Tutorial how use SmartSniff to Capture announces for Bittorrent
    Reply With QuoteReply With Quote
    Thanks

  6. #5
    Moderator anon's Avatar
    Join Date
    01.02.08
    Posts
    39,439
    Activity Longevity
    8/20 19/20
    Today Posts
    1/5 ssss39439
    mmmmm: try saving the scripts with Notepad, and make sure you pick ANSI as the character encoding.
    "I just remembered something that happened a long time ago."
    Reply With QuoteReply With Quote
    Thanks

  7. Who Said Thanks:

    mmmmm (28.12.15)

  8. #6
    @ anon
    I did and now the tow files :
    1. _pidxxxx.txt (empty , zero byte)
    2. uTorrent_Serenity_2.2.1_25130-pid.txt (got only four numbers like above xxxx)

    @ Master Razor
    where put the second file (isn't it at windows folder) ?
    Busy , new things always comes
    Its the time for personal life ,Still here from time to time, Greeting for everybody All .

    Its easy way to capture the announces :-
    Tutorial how use SmartSniff to Capture announces for Bittorrent
    Reply With QuoteReply With Quote
    Thanks

  9. #7
    Choose one of these folders: System32, SysWOW64, Windows and it will work.
    1. _pidxxxx.txt (empty , zero byte)
    2. uTorrent_Serenity_2.2.1_25130-pid.txt (got only four numbers like above xxxx)
    This is the expected behaviour. The first file is used for visual, view the pid quickly. The second is used for scripting. The process pid is the xxxx in the file name.
    Reply With QuoteReply With Quote
    Thanks

  10. Who Said Thanks:

    mmmmm (28.12.15)

  11. #8
    Quote Originally Posted by Master Razor View Post
    This is the expected behaviour. The first file is used for visual, view the pid quickly. The second is used for scripting. The process pid is the xxxx in the file name.
    Am expecting PID=peer_id ,so waiting for something else but never come .
    Busy , new things always comes
    Its the time for personal life ,Still here from time to time, Greeting for everybody All .

    Its easy way to capture the announces :-
    Tutorial how use SmartSniff to Capture announces for Bittorrent
    Reply With QuoteReply With Quote
    Thanks

  12. #9
    Never was peer_id = PID. In windows and any other os for that matter PID = Process ID. It is self-explanatory.
    Reply With QuoteReply With Quote
    Thanks

  13. Who Said Thanks:

    mmmmm (28.12.15)

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •