I have created a BAT file to uninstall any version of skype. It works fine. I am wanting to set it up to also check the event viewer to see that it uninstalled successfully. I was wondering if there was anyone that has done something to this nature. So far, this is what I have:
#echo off
echo Closing skype...
taskkill /F /IM Skype.exe
echo Removing previous versions...
wmic product where "Name like 'Skype%%'" call uninstall
New Code:
#ECHO off
IF EXSIST "C:\Program Files (x86)\Skype" GOTO INSTALLED
ELSE IF EXSIST "C:\Program Files\Skype" GOTO INSTALLED
ELSE GOTO NOTINSTALLED
:Installed
taskkill /F /IM skype.exe
wmic product where "name like 'Skype%%'" call uninstall
shutdown /r /f
:NOTINSTALLED
EXIT
You can check the %errorlevel% variable to get the last error code.
If it's 0, then it worked!
if %errorlevel%==0 echo Uninstall successful
EDIT:
An update for your new code, (you can't do an else if in batch, only use them individually)
#ECHO off
IF EXIST "C:\Program Files (x86)\Skype" GOTO INSTALLED
IF EXIST "C:\Program Files\Skype" GOTO INSTALLED
EXIT
:INSTALLED
taskkill /F /IM skype.exe
wmic product where "name like 'Skype%%'" call uninstall
shutdown /r /f
You can try:
(
echo.Exit code was %errorlevel%
echo.
echo.Uninstall application terminated on %date% - %time%
) > ".\uninstall_log.txt"
If you want to output to console then use this:
echo.
echo.
echo.Exit code was %errorlevel%
echo.
echo.Uninstall application terminated on %date% - %time%
echo.
echo.
echo.
echo.Press any key to exit Skype uninstaller.
pause>nul
exit
Related
the below code checks the python version and calls the other python script to excute. I want to take all the logs of the below bat file, including the output of the python script into another log file. doing some test, I am able to put the logs into the file but the output still prints command print window. i thought it will redirect the output.
setlocal
SET "parent=%~dp0"
set LOGFILE=%parent%\run.log
call :LOG > %LOGFILE% 2>&1
:LOG
set "$py=0"
set "$ms=0"
call:construct
for /f "delims=" %%a in ('python dele.py ^| findstr "2"') do set "$py=2"
for /f "delims=" %%a in ('python dele.py ^| findstr "3"') do set "$py=3"
del %parent%\dele.py
if %%py%% == 0 echo "python is not installed" & goto :EOF
echo running with python %py%
for /f "delims=" %%V in ('pip -V') do #set ver=%%V
echo %ver%
pip install --user -r %parent%\requirements.txt
[output on command prompt][1]
echo connectivity script is running...
python %parent%\ConnChk.py
echo connectivity check is completed
goto :EOF
:construct
echo import sys; print('{0[0]}.{0[1]}'.format(sys.version_info^)^)>dele.py
I dont want to print anything on cmd. is there a way? any help would be great!!
[output on cmd][1]
[1]: https://i.stack.imgur.com/qC4pZ.png
I got it worked.
using this link : https://superuser.com/questions/620865/dump-batch-script-output-into-a-text-file-without-specifing-batchfile-location-b
#echo off
REM setlocal enabledelayedexpansion
(
content...
) > "%~dpn0.txt"
enclosing the code with open brackets got it worked!
I want to upload a patch to Jenkins but if there is a conflict so the run will abort.
I tried using this code:
REM SETUP: Apply the patch if there is one
"C:\Program Files\TortoiseSVN\bin\svn.exe" patch %WORKSPACE%\%UPLOADED_PATCH_FILE%
IF %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER
echo.
echo PATCH UPLOADED SUCCESSFULLY!!
GOTO QUIT
:ERROR_HANDLER
echo.
echo ERROR occurred while uploading the patch!!!
exit 1
:QUIT
REM SETUP: Delete the patch file
cd %WORKSPACE%
del /Q /F %UPLOADED_PATCH_FILE%
But the conflict don't throw any error just this message:
00:00:01.738 Summary of conflicts:
00:00:01.738 Skipped paths: 1
Anyone have an idea how to catch this message?
Thanks!
I found the solution for it:
REM SETUP: Apply the patch if there is one
#echo off
set pattern=Summary of conflicts:
FOR /F "tokens=* USEBACKQ" %%F IN (`"C:\Program Files\TortoiseSVN\bin\svn.exe" patch %WORKSPACE%\%UPLOADED_PATCH_FILE%`) DO (
if "%pattern%"=="%%F" (
#echo on
ECHO "***************************************************************************"
ECHO "***************************************************************************"
ECHO "*********ERROR: Conflict found in the patch. Try try again......***********"
ECHO "***************************************************************************"
ECHO "***************************************************************************"
EXIT 1
)
)
#echo on
I have a simple solution which contains next to class projects also setup projects (extension installed in VS: vdproj).
Facing strange behaviour doing the following:
Open solution in VS2013 -> kick off rebuild -> no errors.
Create a small batch file:
CALL "%VS120COMNTOOLS%vsvars32.bat"
DEVENV "D:\Source\Solution.sln" /Rebuild "Debug|Any CPU" 1>NUL 2>&1
IF ERRORLEVEL 1 GOTO Error
IF ERRORLEVEL 0 GOTO Yeah
:Error
COLOR c
Echo.
Echo end %date% - %time%
Echo Failed!
PAUSE
:Yeah
Echo.
PAUSE
Run this batch file and the errorlevel is not zero
Changed now inside the batch file the devenv action to the following:
DEVENV "D:\Source\Solution.sln" /Clean "Debug|Any CPU" 1>NUL 2>&1
DEVENV "D:\Source\Solution.sln" /Build "Debug|Any CPU" 1>NUL 2>&1
Run this batch file and the errorlevel is zero
The strange thing is that without output redirection I do also not get any errors while running the batch with the rebuild action active.
Any suggestions why I do get a different behaviour?
In the first case you are doing a Rebuild. In the second case you are doing a Clean and Build. Temporarily remove the 1>NUL 2>&1 and you should be able to see what the error is all about.
You might simplify things a bit and save the results like this. Then you can view the log file before you 'Press any key to continue' if you want.
CALL "%VS120COMNTOOLS%vsvars32.bat"
SET "LogFile=%Temp%\BuildLog.txt"
IF EXIST "%LogFile%" DEL /F /Q "%LogFile%"
DEVENV "D:\Source\Solution.sln" /Rebuild "Debug|Any CPU" 1>"%LogFile%" 2>&1
IF ERRORLEVEL 1 (
COLOR c
Echo.
Echo end %date% - %time%
Echo Failed! View log file %LogFile% if you prefer. Then
)
PAUSE
IF EXIST "%LogFile%" DEL /F /Q "%LogFile%"
The problem is with the script that if the process is running as admin the same as the batch script it wont work. It just doesn't find the process. Any help?
http://pastebin.com/qUrhxYrT
#echo off
title Unturned Server Restarter
echo Server Batch by :: Mage ::
:loop
echo (%time%) Loot Resetting...
start Unturned.exe -nographics -pei -normal -nosync -pvp -port:25444 -players:12 -sv -batchmode
for /f "tokens=2" %%x in ('tasklist ^| findstr Unturned.exe') do set PIDTOKILL=%%x
echo (%time%) Loot Reset.
echo (%time%) Server is online.
echo (%time%) Server Loot Resetting in 2 Hours.
timeout /t 10 >null
echo (%time%) Server Loot now resetting . . .
taskkill /F /PID %PIDTOKILL%
goto loop
When you launch a batch file with elevated permissions then the working directory is set to the system32 folder.
Presumably your script cannot find the Unturned.exe file, so using a cd command to set the working directory before the loop is one way to resolve an issue like that.
See your code below with full paths to all executables.
#echo off
title Unturned Server Restarter
echo Server Batch by :: Mage ::
:loop
echo (%time%) Loot Resetting...
start "Unturned" "%ProgramFiles%\team\steamapps\common\Unturned\Unturned.exe" -nographics -pei -normal -nosync -pvp -port:25444 -players:12 -sv -batchmode
for /f "tokens=2" %%x in ('%SystemRoot%\System32\tasklist.exe ^| %SystemRoot%\System32\findstr.exe Unturned.exe') do set PIDTOKILL=%%x
echo (%time%) Loot Reset.
echo (%time%) Server is online.
echo (%time%) Server Loot Resetting in 2 Hours.
timeout /t 10 >null
echo (%time%) Server Loot now resetting . . .
%SystemRoot%\System32\taskkill.exe /F /PID %PIDTOKILL%
goto loop
As I don't know where Unturned.exe is installed on your computer, you may need to adapt the string "%ProgramFiles%\team\steamapps\common\Unturned\Unturned.exe".
%ProgramFiles% is a reference to string value of environment variable ProgramFiles which contains usually C:\Program Files.
On 64-bit Windows there is also the environment variable ProgramFiles(x86) which needs to be used with %ProgramFiles(x86)% in batch code if Unturned.exe is installed somewhere below C:\Program Files (x86).
i have been trying to write a batch script in windows 7 sp1. After i start my batch script i try to type an option into the input and then i get "goto unexpected at this time" then the command prompt closes. Please help i need this for a personal project.
#echo off
:start
echo Is this the first time you ran this program on this computer
set input=
set /p intput= "y/n"
if%input%==yes goto Yes
if%input%==no goto No
:No
pause
echo Okay skipping the installation process
cd Minecraft_Server
java -Xmx1024M -Xms1024M -jar minecraft_server*.jar
goto serverrestart
:serverrestart
echo Would you like to restart the server?
set input=
set /p intput= y or n
if%input%==y
pause
goto restart
if%input%==n
pause
goto norestart
:restart
echo To restart the server press any key.
java -Xmx1024M -Xms1024M -jar minecraft_server*.jar
goto serverrestart
:norestart
exit
:Yes
pause
echo I will now install the Minecraft Serevr files, please make sure you
echo have me in the "Parent Directory" of the Minecraft_Server folder
echo --If you don't know what a parent directory is GOOGLE it!--
pause
mkdir Minecraft_Server
move files.exe Minecraft_Server
cd Minecraft_Server
start files.exe
timeout /t 3
java -Xmx1024M -Xms1024M -jar minecraft_server*.jar
goto :serverrestart
You misspelled input in the set /p line and you should use quotes. I used /i to make the compare case insensitive and shortened to one key required. Do as you wish with that. Try this:
#echo off
:start
echo Is this the first time you ran this program on this computer
set "input="
set /p input= "y/n"
if /i "%input%"=="y" goto :Yes
if /i "%input%"=="n" goto :No
echo.Enter a valid choice
pause
goto :start