How to create a "warning" in a batch file? - windows

So basically, I do a lot of mod work in my spare time. However, this can create an unnecessarily large amount of files that I want to delete.
So, I created a batch file that pretty much deletes every file (image files, model files, etc) but knowing myself, I have a gut feeling that I might one day accidentally open the batch file and screw myself over. What I'm wondering is, is it possible to create a "warning" in the batch file? Such as, "Warning! Proceeding will delete all files that haven't been backed up. Press any key to proceed." being an example? I haven't been able to find someone who has a similar request. Thanks for reading through this! I'd appreciate any help.
TL;DR: When a batch file is opened, is it possible to have a warning message that appears before any commands are run?

#echo off
set /p proceed=warning - enter x to proceed
if /i "%proceed%" neq "x" goto :eof
... now do your thing
You get prompted and must press x and enter to proceed.

Related

How to make this windows script skip existing files?

I have a windows script here that takes all files in a source folder, whether they're nested or not, and moves them to one single destination folder.
However I have some duplicates within the source folders and every time it comes across one it prompts to copy or skip it. It is quite cumbersome as some of the source folders have a lot of duplicates.
Can someone advise on how to edit this script to make it auto skip any duplicates without prompting me every time or maybe even copy both and just append the name of the duplicate? Either one would work. I am still new to the whole batch script scene and it is driving me nuts.
The script I have is:
FOR /R "C:\source folder" %i IN (*) DO MOVE "%i" "C:\destination folder"
Thank you!

Trying to wrap CALL function fails [duplicate]

I am using the tool 'HTML Match' to compare two HTML files. As I have to compare many files, I create a batch file like the followion. For example, I give only five sets of files.
cd "C:\Program Files\HTML Match"
HTMLMATCH.EXE "D:\Raj\compare1\a1.html" "D:\Raj\compare2\a1.html" "D:\Raj\compare_res\a1.html"
HTMLMATCH.EXE "D:\Raj\compare1\a2.html" "D:\Raj\compare2\a2.html" "D:\Raj\compare_res\a2.html"
HTMLMATCH.EXE "D:\Raj\compare1\a3.html" "D:\Raj\compare2\a3.html" "D:\Raj\compare_res\a3.html"
HTMLMATCH.EXE "D:\Raj\compare1\a4.html" "D:\Raj\compare2\a4.html" "D:\Raj\compare_res\a4.html"
HTMLMATCH.EXE "D:\Raj\compare1\a5.html" "D:\Raj\compare2\a5.html" "D:\Raj\compare_res\a5.html"
When I execute this batch file in a cmd prompt, only the first line, that is, only 'a1.html', gets compared and produces a result. Then execution stops.
Add call in front of the commands you're running.
You can also change this to a for loop, so:
FOR /L %%i in (1,1,5) DO CALL HTMLMATCH.EXE D:\Raj\compare%%i%%\a%%i%%.html D:\Raj\compare%%i%%\a%%i%%.html D:\Raj\compare_res\a%%i%%.html
The answer to your problem is to write CALL HTMLMATCH.EXE (and the rest of the parameters).
Just use CALL in front of every executable command in the batch file.
I was looking for something really similar and tried, I think, all the replies left here but I finally found the solution to my problem!!
In my script I want to check if one process is running, if not, start it (a .exe) and then check if another process is running, if not, start it too (but leave all the programs opened) and the problem is that the first .exe was started but then not moving to the second one because it was waiting until the process ended.
It´s finally working for me with start and the magic comes with...
/separate
it works for me as:
start "program1" /separate program1.exe
other commands
Before it stopped after starting program1 because it was waiting until it was closed, I think, but this was not going to happen because I wanted to leave it opened.
Now with the start /separate it continues with the other commands.
I found it in another forum but the thing is that it´s the manual, /separate is used to start in another memory space.
You don't have to insert quotation marks where there isn't any space mark between.
Try that:
HTMLMATCH.EXE D:\Raj\compare1\a1.html D:\Raj\compare2\a1.html D:\Raj\compare_res\a1.html
Maybe it will solve your issue.

Opening multiple calculators with a single batch file

So i essentially need to create a batch file, that opens multiple windows of an application, example a calculator here. My actual project is to make it open over a few thousand times, so that the system crashes. I've looked over for loops and learnt a little batch scripting syntax and etc. But i don't really know much, and concluded on a block of code to open a trail bat file to open 20 calculators, multiple environments without the first one exiting.
#echo off
set count=0
:loop
set /a count=%count%+1
start /MIN /DC:\Windows\System32 calc.exe
if %count% neq 20 goto loop
But i don't understand, the behavior is erratic. Sometimes, my system crashes. I've tried using the "for" syntax as well
#echo off
for /L %%a IN (1,1,20) DO start "" "C:\Windows\system32\calc.exe"
And this one crashes my system or opens only a single calculator, which might mean that the previous instances are closing and only the last one opens.
So how do i modify my code?.. or perhaps is there a better script in batch files to open multiple environments of an application?

How do I make a task run on startup through raimeter?

I want a random number to be generated every time I start my computer so I can randomly choose a background on rainmeter. Every time I try to search for an answer I keep getting pages for how to make rainmeter run on startup.
You can use the RunCommand plugin to execute a command line input.
To make it run once when the skin is loaded, you just need to set option UpdateDivider=-1.
The following opens Notepad on startup, replace it in Parameter=Notepad with the command you wish to run.
[Rainmeter]
Update=1000
[MeasureRunCmd]
Measure=Plugin
Plugin=RunCommand
Parameter=Notepad
[MeterRunCmd]
UpdateDivider=-1
Meter=String
Text=None
OnUpdateAction=[!CommandMeasure MeasureRunCmd "Run"]
If you don't need the extra flexibility of that plugin you can just use the following
[Rainmeter]
Update=1000
[MeterRunCmd]
UpdateDivider=-1
Meter=String
Text=None
OnUpdateAction=["Notepad"]
I just became acquainted with Rainmeter about 3 hours ago. But here's a thought:
Any "app" (or even a shortcut to an app) that's in "C:\Users\\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" will run at ... uhh? ... STARTUP! (that's it!). Now, since cmd.exe runs as conhost.exe before the startup folder is processed, that means we can use the "DOS" (I'm an old fart) %RANDOM% variable.
So, if Rainmeter can handle system variables in ".ini" files then you can use %Random% directly (Enter %RANDOM% at the command prompt and you'll see a different number returned everytime). Also, Google %RANDOM% (case, like size, does matter) to see the tweaks used to get any range of numbers you desire.
If Rainmeter can't handle system variables directly then write a 1 line ".bat" file that "set"s the random number to a string (or whatever you can use) and stick the batch file (or a shortcut to it) in the startup folder.
I can't think of a reason why this easy method (or your own enhanced version of it) won't work.
Good luck. Interesting idea. Let me know how you make out.

Minimizing and Maximizing Windows With VBscript or Batch files

I'm trying to find a way to maximize & minimize a certain application using vbscript or a batch file. I've seen multiple attempts at doing this but none of them seem to work. Does anybody have any suggestions, without having to download any third party software.
I think that /MIN and /MAX switches of START command should work, that is:
START "Window Title" /MAX YourApplication Parameters ...
Type START /? for further details.
If you are trying to maximize the batch window, you can use the code
Mode Con Cols=500 Lines=500
what this does is determine how many text blocks up and down there are, for example, if you changed cols to 20, you could fit twenty letters in that window. And Lines are the same way, but going up and down.
:edit
sorry, I read your question wrong. either way, my answer was wrong. I think the only way is to maximize it from startup.

Resources