Insert text into cmd prompt through .bat file. - batch-file

Any idea on, how to insert text into a new cmd prompt window to continue the script?
e.g.
runas /user:adminuser cmd
opens up new cmd window. I want to insert the below using the batch file
c:
cd\temp\file\executefile.exe
del c:\temp

Create a batch file "C:\batch.bat" and insert these commands in each line
c:
c:\temp\file\executefile.exe
del c:\temp
and start this batch file using following command
C:\> runas /user:adminuser C:\batch.bat
also you probably want to use following command to delete temp folder along with subfolder and files in temp. For that instead of del c:\temp use echo y | rmdir /s c:\temp in batch file

To print this on new windows cmd use this:
text.cmd:
#echo off
echo c:
echo.
echo cd\temp\fichier\executefile.exe
echo.
echo del c:\temp
pause
and use the command:
start text.cmd
You can use a file.cmd or file.bat it is the same.

runas /user:adminuser "cmd /C c: & cd\temp\file\executefile.exe & del c:\temp"
Previous line execute the commands and terminate the new cmd prompt window. If you want that the window remain after execute the commands, change /C by /K.

To insert manually values into your command prompt when executing a batch script, use the following:
set /p var=
echo %var%
This will gather what you entered, then display it (or wathever you need).

Related

How to hide login script (batch file) while it is running?

I have created login script using batch file. But actually I need this batch runs invisible (but still showing on the task manager).
As far that I can go is that I only able to minimize the batch file using below code:
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
#echo off
echo *Logon Script*
rem :Time_Set
rem echo Setting the system time...
rem net time \\EX001LT /set /y
rem echo.
I have tried using cmd /c "batchfile" and didn't work.
You can use vbs to hide the batch completely. Add the path to the logon script to MyScript.Run line.
Hidden.vbs
Set MyScript = CreateObject("WScript.Shell")
MyScript.Run "C:\path to batch\logonscript.cmd", 0, False
Then simply call the Hidden.vbs file instead of the batch file

Batch file to open the cmd prompt and execute

can any one help me in this.
I want to run the cmd prompt through Bat file.
#echo off
cd ..
cd ..
dir /b w:\0*.jpg >abc.csv
pause
The above code collect all .jpg from w drive and will store in C drive as abc.csv
Is it not simply?
#echo off
cd ..
cd ..
dir /b w:\0*.jpg >abc.csv
start cmd || ::This line opens a new prompt.
pause

Batch file that run jar file on cmd

Apologies if duplicate, I want to run a jar file from command prompt, So instead of going to the specific path can i create a batch file,
Simply double click on batch file will do my task,
I found something at [1]: Run a Command Prompt command from Desktop Shortcut but it do not work in my case, I want to run java -jar squirrel-sql.jar
I would like to make a batch file that:
1)Opens cmd.exe
2)Within that Command Prompt runs java -jar squirrel-sql.jar which is present on desktop
3)Leaves the window open so that I can run additional commands if I wish to
How can I do this?
Save the following as squirrel.bat:
java -jar squirrel-sql.jar
REM /P causes SET to prompt and wait for Enter.
REM The underscore is used to ensure that "sure" is not already
REM an environment variable.
set /p _sure="Do you want to exit? [press Enter]"
REM /I causes a case-insensitive comparison
if /I NOT "_sure"=="y" (
REM /B exits the batch script but not the CMD window
exit /b
) else (
REM Any other modifications
)

How to make a batch file that lets you use cmd after?

what I'm essentially trying to do is make a batch file (or shortcut if possible) to change to a directory, echo a message, and then let you use the cmd window as if you had opened it up normally after.
Example:
The batch file/shortcut opens a cmd prompt in C:\test-folder\
Echos "This is your message"
Awaits user input for commands
I've tried the following command:
start cmd /k cd /d C:\test-folder\
echo test
The folder change will work without the echo line, but if I include the echo line, it will not work at all.
Is there any way to do what I'm trying to accomplish here?
the order of the switches matters. See start /? and cmd /? for details.
start "My window" /d "d:\" cmd /k "echo Hello&echo use me"
"My window" belongs to start and gives the new window a title.
/d "c:\test-Folder\" also belongs to start and gives the startdirectory
cmd is the command to start
/k belongs to cmd and has to be cmd's (only or) last Switch
"echo Hello&echo use me" is the commandline to execute.
Your problem is the echo test is run in the parent window that issues the START command. You want the ECHO to occur in the window that START launches.
One option is to append the ECHO command to the end of the START command, remembering to escape the & so that it is included as part of the CMD /K option.
start cmd /k cd /d C:\test-folder\ ^& echo test
Or you could put quotes around the entire /K option (CMD will remove the quotes before executing the string):
start cmd /k "cd /d C:\test-folder\ & echo test"
Or you could use Stephan's suggestion to let START set your active directory, so that your CMD /K option only needs to ECHO the message.
start /d "C:\test-folder" cmd /k echo test
Or you can create a shortcut and edit the properties such that
"Target" = C:\Windows\System32\cmd.exe /k echo test
and
"Start in" = c:\test-folder
If you create a batch file that ends with cmd /k, it will run the commands before cmd /k and then leave you in a command prompt. This is useful if you're performing enough work that makes a one-liner shortcut hard to write.
To get the behaviour you described, you can create a file called "open_test_folder.cmd" with the following:
#echo off
cd C:\test-folder
echo This is your message
cmd /k

Start a CMD, then echo off of it, then clear the screen

Here are the steps I need, I am using a batch script
Open a cmd with path set to the desktop
Then set it's echo off
Then clear the screen
Then wait for me to type commands
So I can enter the commands directly without a long line blocking the view
Code I tried so far
#echo off
cd "C:\Documents and Settings\Administrator\Desktop"
cls
cmd
#echo off
cls
But when I run this I get a typical CMD window, where I have to type "echo off" & "cls" again to get a clean window.
The output I get is
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator\Desktop>
The output I want is simple
Imagine a blinking underscore
_
Thank you.
Try this line:
start /D "C:\Documents and Settings\Administrator\Desktop" cmd /k "prompt $"
/D <path> will set your working directory
Prompt $ will set your prompt to "nothing", only the blinking cursor will display
The output I want is simple
_
You can achive this with the prompt command, e.g. prompt $S or prompt $g
Here's an example batch file that would open up a new cmd window with an empty prompt:
#echo Off
start cmd /k "prompt $g"
create a VBS file using notepad
add this lines
Set cmd = CreateObject("WScript.Shell")
cmd.run"cmd"
WScript.Sleep 200
cmd.Sendkeys"echo off{Enter}"
WScript.Sleep 200
cmd.Sendkeys"cls{Enter}"
WScript.Sleep 200
This command can be very problematic (cmd /c "echo off | clip")
USE WITHOUT QUOTES:
cmd /c echo off | clip
goto off
(Save as .bat)
No more problems !!!
I just used
cls
echo off
cls
cmd|echo off
cls
in a batch file. Works for me

Resources