Jag lägger till lite nya funktioner i ett script jag skrivit. (en "Killswitch") Och har plockat ut den delen ur scriptet som inte fungerar.
Om jag kör scriptet och väljer att installera brandväggsregler för Nr:4 [4] QBITTORRENT så fungerar det ibland men oftast får jag felkoden "\qBittorrent\qbittorrent.exe was unexpected at this time"
Jag har lokaliserat felet och det är raden "echo %torrentlocation% installed." (Sista if/else-satsen)
Om jag istället lägger "echo %torrentlocation% installed" efter sista parentesen ) så fungerar det.
Detta är givetvis inget problem då det går utmärkt att lägga det efter sista parentesen, men vill gärna få ett svar på varför det inte fungerar under else.
Scriptet:
Om jag kör scriptet och väljer att installera brandväggsregler för Nr:4 [4] QBITTORRENT så fungerar det ibland men oftast får jag felkoden "\qBittorrent\qbittorrent.exe was unexpected at this time"
Jag har lokaliserat felet och det är raden "echo %torrentlocation% installed." (Sista if/else-satsen)
Om jag istället lägger "echo %torrentlocation% installed" efter sista parentesen ) så fungerar det.
Detta är givetvis inget problem då det går utmärkt att lägga det efter sista parentesen, men vill gärna få ett svar på varför det inte fungerar under else.
Scriptet:
Kod:
:: Script by Dserv
@echo off
::check if run as admin
openfiles > NUL 2>&1
if %ERRORLEVEL% EQU 1 echo You need to run this script as Administrator. & pause & exit
:KILLSWITCH
cls
echo This will set your network connection to private if it's public or domain.
echo After that install two firewall rules.
echo which prevent your torrent client to communicate as long as your vpn connection is lost.
echo.
echo Do you want to install these rules? [Y] [N]
set /P killswitchyesno=
if /I "%killswitchyesno%" EQU "Y" echo yes >nul
if /I "%killswitchyesno%" EQU "N" goto :installmenu
:killswitch_menu
cls
echo KILLSWITCH MENU:
echo [1] UTORRENT
echo [2] RTORRENT
echo [3] BITTORRENT
echo [4] QBITTORRENT
echo [5] OTHER CLIENT
echo [Q] EXIT
echo ==========================
echo Enter selection and press ENTER key:
set /P killswitch_menuchoice=
if /I "%killswitch_menuchoice%" EQU "1" goto :killswitch_utorrent
if /I "%killswitch_menuchoice%" EQU "2" goto :killswitch_rtorrent
if /I "%killswitch_menuchoice%" EQU "3" goto :killswitch_bittorrent
if /I "%killswitch_menuchoice%" EQU "4" goto :killswitch_qbittorrent
if /I "%killswitch_menuchoice%" EQU "5" goto :killswitch_other
if /I "%killswitch_menuchoice%" EQU "Q" exit
:killswitch_utorrent
cls
for /f "delims=" %%F in ('dir /b /s "%programfiles(x86)%\utorrent.exe" 2^>nul') do set torrentlocation=%%F
cls
if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%appdata%\utorrent.exe" 2^>nul') do set torrentlocation=%%F
if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%programfiles%\utorrent.exe" 2^>nul') do set torrentlocation=%%F
if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch_menu
for %%A in ("%torrentlocation%") do (set torrentlocation_ext=%%~nA) >nul
goto :killswitch_installrules
:killswitch_rtorrent
cls
for /f "delims=" %%F in ('dir /b /s "%programfiles(x86)%\rtorrent.exe" 2^>nul') do set torrentlocation=%%F
cls
if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%appdata%\rtorrent.exe" 2^>nul') do set torrentlocation=%%F
if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%programfiles%\rtorrent.exe" 2^>nul') do set torrentlocation=%%F
if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch_menu
for %%A in ("%torrentlocation%") do (set torrentlocation_ext=%%~nA) >nul
goto :killswitch_installrules
:killswitch_bittorrent
cls
for /f "delims=" %%F in ('dir /b /s "%programfiles(x86)%\bittorrent.exe" 2^>nul') do set torrentlocation=%%F
cls
if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%appdata%\bittorrent.exe" 2^>nul') do set torrentlocation=%%F
if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%programfiles%\bittorrent.exe" 2^>nul') do set torrentlocation=%%F
if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch_menu
for %%A in ("%torrentlocation%") do (set torrentlocation_ext=%%~nA) >nul
goto :killswitch_installrules
:killswitch_qbittorrent
cls
for /f "delims=" %%F in ('dir /b /s "%programfiles(x86)%\qbittorrent.exe" 2^>nul') do set torrentlocation=%%F
cls
if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%appdata%\qbittorrent.exe" 2^>nul') do set torrentlocation=%%F
if not exist "%torrentlocation%" for /f "delims=" %%F in ('dir /b /s "%programfiles%\qbittorrent.exe" 2^>nul') do set torrentlocation=%%F
if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch_menu
for %%A in ("%torrentlocation%") do (set torrentlocation_ext=%%~nA) >nul
goto :killswitch_installrules
:killswitch_other
cls
set /p torrentlocation= Input path: (example: C:\Program Files (x86)\uTorrent\uTorrent.exe)
cls
if not exist "%torrentlocation%" echo Can't find torrentclient. & pause & cls & goto :killswitch_menu
for %%A in ("%torrentlocation%") do (set torrentlocation_ext=%%~nA) >nul
goto :killswitch_installrules
:killswitch_installrules
for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa
reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\%var%" /v Category | find "0x1">nul
IF %ERRORLEVEL%== 0 (
echo network is private >nul
) else (
for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa
Reg Add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\%var%" /V Category /t REG_DWORD /d 1 /f >nul
)
cls
netsh advfirewall firewall show rule name="%torrentlocation_ext% (IN)" >nul
if %errorlevel%== 0 (
echo Rules already installed. & pause & exit
) ELSE (
netsh advfirewall firewall add rule name="%torrentlocation_ext% (IN)" dir=in action=block program="%Torrentlocation%" profile=private,domain >nul
netsh advfirewall firewall add rule name="%torrentlocation_ext% (OUT)" dir=out action=block program="%Torrentlocation%" profile=private,domain >nul
echo %torrentlocation% installed.
)
pause
exit
__________________
Senast redigerad av Dserv 2017-03-20 kl. 03:40.
Senast redigerad av Dserv 2017-03-20 kl. 03:40.