I am having trouble with my code. If I run the file and follow the prompt, enter a workstation name then select site 1, it continues to open up the cmd window to execute the psexec command, it does not do the "IF NOT EXIST" for site 1, but for other sites it comes back fine. If no file exists it will output to the prompt, if it does it continues to psexec. Any idea what I am doing wrong? Thank you.
:MAN
SET /P S=Please enter a workstation name or IP:
ECHO.
ECHO 1 - Site 1
ECHO 2 - Site 2
ECHO 3 - Site 3
ECHO 4 - Site 4
SET /P D=Select which Site you want to deploy from:
IF %D%==1 SET D="\\site1\Operations\Sofware\Packages\file.msi"
IF %D%==2 SET D="\\site2\Operations\Sofware\Packages\file.msi"
IF %D%==3 SET D="\\site3\Operations\Sofware\Packages\file.msi"
IF %D%==4 SET D="\\site4\Operations\Sofware\Packages\file.msi"
IF NOT EXIST %D% GOTO MSG
START CMD /K PsExec.exe #%S% -s -h cmd /c msiexec.exe /i "%D%" /qn
PAUSE
GOTO EOF
:MSG
CALL :color 1a "ERROR: MSI PACKAGE DOES NOT EXIST"
Note the possibility of doing:
goto label%D%
You can also almost do:
set D=\\10.%D%.2.1\Operations\Sofware\Packages\quest.msi
instead of the 4 IF-statements.
Here is my working code, there was an issue with PsExec as well not taking the %s% variable, I instead outputted the user input to a text file and had Psexec read from that file. I also edited with everyone's suggestions. Thank you all.
:MAN
#ECHO OFF
SET /P S=Please enter a workstation name or IP:
ECHO %S% >> man.txt
ECHO.
ECHO 1 - Site 1
ECHO 2 - Site 2
ECHO 3 - Site 3
ECHO 4 - Site 4
SET /P D=Select which Branch you want to deploy from:
IF %D%==1 SET "R=\\site1\Operations\Sofware\Packages\file.msi"
IF %D%==2 SET "R=\\site2\Operations\Sofware\Packages\file.msi"
IF %D%==3 SET "R=\\site3\Operations\Sofware\Packages\file.msi"
IF %D%==4 SET "R=\\site4\Operations\Sofware\Packages\file.msi"
IF NOT EXIST %R% GOTO MSG
START CMD /k "PsExec.exe #man.txt -s -h cmd /c msiexec.exe /i %R% /qn & DEL man.txt"
PAUSE
GOTO MENU
:MSG
CALL :color 1a "ERROR: MSI PACKAGE DOES NOT EXIST"
== is not advised in a .bat, .cmd file; I'd use EQU
Related
I want to change the serial number and product number of about 250 servers (they are not correct at the moment). I know the command that I need to use, but I need to be able to input certain options in to that command and then run it.
The options I need are:
A prompt for selecting the update of the serial or the product number
Multiple prompts for actual serial number, an IP address, a user name and password on having selected before the update of the serial number
Multiple prompts for actual product number, an IP address, a user name and password on having selected before the update of the product number
The command I wish to run via the batch file is:
asu64 set SYSTEM_PROD_DATA.SysInfoSerialNum XXXXXXX --host XXX.XXX.XXX.XXX --user XXXX --password XXXX
The XXX is a user defined input. I'd also like for completion and then go back to the initial selection menu.
Here is what I have done so far. (Please excuse the simplicity of it. I am very new to this stuff.)
#ECHO OFF
ECHO Test Code
ECHO.
ECHO 1.Serial Number
ECHO 2.Product Name
ECHO.
CHOICE /C 12 /M "Enter your choice:"
ECHO.
IF CHOICE 1 GOTO SerialNumber
IF CHOICE 2 GOTO ProductName
:SerialNumber
ECHO Serial Number
GOTO End
:ProductNumber
ECHO Product Number
GOTO End
PAUSE
Many thanks for any help you can offer.
There could be used for this task:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "IpAddress="
set "NameUser="
set "Password="
:MainMenu
cls
echo/
echo 1 ... Serial number
echo 2 ... Product number
echo E ... Exit
echo/
%SystemRoot%\System32\choice.exe /C 12E /N /M "Enter your choice:"
if errorlevel 3 exit /B
if not errorlevel 1 goto MainMenu
echo/
if errorlevel 2 goto ProductNumber
set "NumberText=serial"
set "NumberOption=SYSTEM_PROD_DATA.SysInfoSerialNum"
goto NumberPrompt
:ProductNumber
set "NumberText=product"
set "NumberOption=SYSTEM_PROD_DATA.SysInfoProductNum"
:NumberPrompt
set "NumberValue="
set /P "NumberValue=Please enter %NumberText% number: " || goto NumberPrompt
set "NumberValue=%NumberValue:"=%"
if not defined NumberValue goto NumberPrompt
echo/
if defined IpAddress (set "Default= [%IpAddress%]") else set "Default="
:IpPrompt
set /P "IpAddress=Please enter IP address%Default%: "
if not defined IpAddress goto IpPrompt
set "IpAddress=%IpAddress:"=%"
if not defined IpAddress goto IpPrompt
echo/
if defined NameUser (set "Default= [%NameUser%]") else set "Default="
:NamePrompt
set /P "NameUser=Please enter user name%Default%: "
if not defined NameUser goto NamePrompt
set "NameUser=%NameUser:"=%"
if not defined NameUser goto NamePrompt
echo/
if defined Password (set "Default= [%Password%]") else set "Default="
:PasswordPrompt
set /P "Password=Please enter password%Default%: "
if not defined Password goto PasswordPrompt
set "Password=%Password:"=%"
if not defined Password goto PasswordPrompt
echo/
"%~dp0ASU64.exe" set %NumberOption% "%NumberValue%" --host "%IpAddress%" --user "%NameUser%" --password "%Password%"
echo/
if not errorlevel 1 (
echo The update of the %NumberText% number "%NumberValue%" was successful.
) else echo ERROR: The update of the %NumberText% number "%NumberValue%" failed!
echo/
%SystemRoot%\System32\choice.exe /C CE /N /T 10 /D C /M "Press C to continue or E to exit ..."
if not errorlevel 2 goto MainMenu
endlocal
The executable ASU64.exe is referenced with full path of the batch file which means the executable must be always in the same directory as the batch file. The current directory of cmd.exe processing the batch file does not matter in this case.
Please read the following answers for the explanation of the code:
How does the Windows Command Interpreter (CMD.EXE) parse scripts?
How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?
Why is no string output with 'echo %var%' after using 'set var = text' on command line?
Single line with multiple commands using Windows batch file
DosTips forum topic: ECHO. FAILS to give text or blank line - Instead use ECHO/
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /? ... explains %~dp0 ... drive and path of argument 0 which is the batch file path.
choice /?
echo /?
endlocal /?
exit /?
goto /?
if /?
set /?
setlocal /?
I am trying to make a quick program in Batch that asks for user input, but when i get to the input part, the script exits with error:
The syntax of the command is incorrect.
This is my code:
#echo off
color 0a
title WinDoS/PoD- 0.1
echo Automatic DoS/PoD Tool
echo Select what you want to do.
echo 1. Attack
echo 2. Instructions
echo 3. IP Getter
echo 4. IP Searcher
echo 5. Exit
set /p userchoice=
if %userchoice% == 1
goto attack
if %userchoice% == 2
goto instructions
if %userchoice% == 3
goto getter
if %userchoice% == 4
goto searcher
if %userchoice% == 5
exit
:searcher
arp -a
pause
:attack
echo Enter IP adress to attack
set /p address=
goto sequence
:sequence
ping %address% -l 65500 -w 1 -n 1
goto sequence
:instructions
echo WinDoS/PoD Instructions
echo WinDoS/PoD is a program that allows you to perform Denial Of Service (DoS) attacks using a method known as Ping Of Death (PoD)
echo Press 1 on the home menu to enter the attacker program.
echo Input an ip address to DoS
echo If you don't know the IP address to a site, use the built in getter.
echo If you want to view all available network targets, use the built in searcher.
pause
:getter
echo Website (full link):
set /p %website%=
tracert %website%
pause
What is wrong with the syntax?
You're using the wrong command for choosing a known list item, you should be using choice, not set.
Here's an example using your provided information as its basis:
#Echo Off
Color 0A
Title WinDoS/PoD- 0.1
:Menu
Echo(
Echo Automatic DoS/PoD Tool
Echo(
Echo Home Menu
Echo(
Echo 1. Attack
Echo 2. Instructions
Echo 3. IP Getter
Echo 4. IP Searcher
Echo 5. Exit
Echo(
%__AppDir__%choice.exe /C 12345 /N /M "Select a Home Menu item number>"
If ErrorLevel 5 GoTo :EOF
If ErrorLevel 4 GoTo Searcher
If ErrorLevel 3 GoTo Getter
If ErrorLevel 2 GoTo Instructions
:Attack
ClS
Set /P "address=Enter IP address to attack> "
:Sequence
%__AppDir__%ping.exe %address% -l 65500 -w 1 -n 1
GoTo Sequence
:Instructions
ClS
Echo WinDoS/PoD Instructions
Echo(
Echo This program allows you to perform Denial Of Service (DoS) attacks,
Echo using a method known as Ping Of Death (PoD).
Echo(
Echo Press 1 on the Home Menu to begin the Attack program.
Echo Input an IP address to DoS
Echo If you don't know the IP address for a site, use the built-in Getter.
Echo If you want to view all available network targets, use the built-in Searcher.
Echo(
Pause
GoTo Menu
:Getter
ClS
Set /P "website=Website (full link)> "
%__AppDir__%tracert.exe %website%
Pause
GoTo Menu
:Searcher
ClS
%__AppDir__%arp.exe -a
Pause
GoTo Menu
Please note, that I have not looked at the usage of any of your commands, I have offered only improvements to the layout and functionality.
I looked for quite a while and couldn't find a good solution to my problem. I want a batch program to "look" in a .txt file for the command "" and if that word is in it, then to execute a different command. If the command existed, I would want to do something like set %textfile%=text.txt and if that worked I would then do if %textfile%==update goto update which would be an easy way to start an automatic update if this was in a loop. So basically, is there a command that sets a text file in %text%? This is the code that I am trying to add this into:
#echo off
color 0f
:start
echo Welcome to Master control pannel
ping 127.1 -n 4 >nul
cls
:options
cls
echo What would you like to do first? (Type the number of the operation you want to start)
echo.
ping 127.1 -n 2 >nul
echo 1. Run a command off of all computers
::(I want to run a command by sending a message to a text file but want recieving computor to be able to read it and execute it, how could I read the command and then do what it say, for example, if the command says "echo Hello" I would want recieving computor to say "Hello" )
echo 2. Stops the current command
echo 3. List all computers
echo 4. Open remote shutdown program
echo 5. Delete a computor (in progress)
echo 6. (Unfinished)
echo 7. (Unfinished)
echo 8. (Unfinished)
echo 9. (Unfinished)
echo 10. Exit
set /p choose=(1-9):
if %choose%==1 goto o1
if %choose%==2 goto o2
if %choose%==3 goto o3
if %choose%==4 goto o4
if %choose%==5 goto o5
if %choose%==6 goto close
if %choose%==7 goto close
if %choose%==8 goto close
if %choose%==9 goto close
if %choose%==10 goto o10
goto options
:close
cls
goto start
:o1
echo Stopping current command
del command.txt
echo. 2>command.txt
echo Command stopped!
pause
cls
goto start
I would greatly appreciate some help or comments to what I could do or add to this. Thanks!
Not an answer but several hints.
a variable can hold only single lines not a whole file.
if you want to get the first line of a file into a var use `Set /P "var="
set %textfile%=text.txt would store test.txt literally into a var whose name is the content of the var textfile.
you are mixing goto o1 and :01 with the label
`
Hi guys i would like to make a batch (register-login) programm,
What i have so far there are two files called clientdata.bat and data.txt.
What i want is a code that reads the data.txt file, looks for a password and procceds to the login. My code is this.
:register
set /p regname= Name:
echo.
set /p regpass= Password:
cls
echo %regname% %regpass% >> data.txt
This works perfectly, when it comes to saving data to data.txt file.
But my problem is in the login sector
:login
cls
set /p logname= Name:
echo.
set /p logpass= Password:
This is what i have so far in the login section. PLease help!!
Use for /f to parse data.txt:
:login
cls
set /p logname= Name:
echo.
set /p logpass= Password:
call :authenticate
if %errorlevel% equ 1 echo Wrong password & goto error
if %errorlevel% equ 2 echo No such user & goto error
echo Authenticated successfully
pause
exit
:error
echo format c:
pause
exit
:authenticate
for /f "tokens=1,2" %%u in (data.txt) do (
if "%%u"=="%logname%" (
if "%%v"=="%logpass%" exit /b 0
exit /b 1
)
)
exit /b 2
I made a system that uses an online PHP mysql database. The php codes would check passwords and add users and stuff. I based it all on this little powershell script you can call using this command: Powershell "& ""%cd%\RespondURL.ps1""" after putting the url you want to load and get a text response from in a text file urls.txt. The response is stored in out.txt and you can use Find and errorlevel handling to read it, or just use set /p response=<out.txt. Its over the top but its great if you want to update it and manage it online.
Note that it requires your Powershell execution policy to be unrestricted. Here is the script:
$cur="C:\users\Public"
$contents = Get-Content $cur\urls.txt
$num=1
foreach($content in $contents){
$stat=(Invoke-WebRequest -Uri "$content").Content
echo $stat$num |Out-File -FilePath $cur\out.txt -Append
$num=$num + 1
}
echo $error.count |Out-File -FilePath $cur\Errors.txt
If the script encounters errors, it will put a number over 0 in the file Errors.txt
I'd like to be run this file and see
"1 for example_x
2 for example_y
3 for example_z
Enter number for apk to install:"
Then I press 1, 2, or 3 and enter and the script installs the corresponding .apk via adb (Android Debug Bridge).
When I run this now, I get the message "can't find '1' to install".
#echo off
set newline=^& echo.
set 1=example_x.apk
set 2=example_y.apk
set 3=example_z.apk
echo 1 for example_x %newline% 2 for example_y% 3 for example_z %newline%
set /p UserInput= Enter number for apk to install:
adb install %UserInput%
pause
exit
Ok, for your situation the choice command is what you are lookign for (use it in everycase possible). Here is what you need to do to your code:
(Also the problem is not with your command, it is when you use adb install %UserInput% look at the soloution)
Code :
#echo off
setlocal enabledelayedexpansion
set newline=^& echo.
set 1=example_x.apk
set 2=example_y.apk
set 3=example_z.apk
echo 1 for example_x %newline% 2 for example_y% 3 for example_z %newline%
choice /c 123 /n /m "Enter number for apk to install: "
set UserInput=%errorlevel%
adb install !%UserInput%!
pause
exit
Explanation of choice and !%UserInput%! :
Choice:
/n specify's not to display "[1,2,3}" (which you have already done)
/c Specify Opitions
/m "" Text to display
!%UserInput%!:
set UserInput=%errorlevel% where %errorlevel% is the ouput of the choice command
!%UserInput%! this only works if you setlocal enabledelayedexpansion and means, whatever result you get from %UserInput% is then treated as a variable itself. (! is treated the same as a %)
Hope this helped, to learn more, type the command followed by /?
Yours Mona