I've got a very simple batch file that deletes all files within a specified folder. It's only a single line so it executes very quickly.
To prevent users from saying its not working or clicking a dozen times, I'd like it to pop up with a simple "done" message for a few seconds before vanishing.
I've done a bit of looking around, and it seems there are/were some easy solutions, but I'm a little confused by which are still valid (some are for previous versions of Windows - we're using W10) - I also wasn't sure if the existing solutions could be dumped into the same .bat file.
If you couldn't tell, I've never written a .bat file before and I'm entirely unfamiliar with it.
Try using powershell MessageBox:
%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& {Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show('Done.', 'Message', 'OK', [System.Windows.Forms.MessageBoxIcon]::Information);}"
%windir%\System32\timeout.exe /T 2 /NOBREAK >nul
exit
Paste this code to the end of your batch file.
Related
I have a batch file that runs a simple "burst" (a.k.a. split) multi-page PDF into single pages scripts, then moves them to a mapped network drive (Z:\). This batch file is triggered by the user and has been working without a hitch for at least two years. Last week, there was a flurry of Windows 10 (x64) updates and it stopped working. Now, instead of looping over every PDF in the source dir, the batch file will generate single pages for the first PDF in the iteration, then stops (although not showing any errors in output). I have tried a multitude of fixes, including using a full timestamp in the target file names to prevent overwriting, though I don't think that's the problem. It seems too coincidental that it just stopped working shortly after the updates (per my User). I'm not very experienced with batch files, and just drew this up based on a PDFTK example I saw. Here it is (not sure why line 2 is being split in the markup, but in the batch file lines 2 & 3 here represent a single line; PS the last line is also being weird, should read: del "C:\Users\My User\Desktop\PHYS_SRCDIR'BACKSLASH''STAR''DOT''STAR'" /F /Q):
cd C:\Users\My User\Desktop\PHYS_SRCDIR
for /r %%i in (*.pdf) do (pdftk "%%i" burst output "Z:\PHYSICALS_IN\%date:~10,4%%date:~4,2%%date:~7,2%_%%~ni_%%03d.pdf")
del Z:\PHYSICALS_IN\doc_data.txt /F /Q
del "C:\Users\My User\Desktop\PHYS_SRCDIR\*.*" /F /Q
I haven't seen any new responses lately, and have to divert my attention elsewhere, so my solution was simply to move the batch file to the server w/ "Z:" on it (allowing a limited login to the User), reverse it so it copies from User's PC mapped drive to the Server, and move on to the bigger fish I have to fry. I know, it's not really a solution but that is my circumstance. I'll check in from time to time to see if there are any other suggestions. Since the batch file works perfectly from a WS2012R2 box my only thoughts are that something in Windows 10 "broke" either PDFTK Server or batch files/command-line in general. Since it works singly and only breaks when trying to loop over several multi-page PDFs, I'm leaning toward batch files/CLI. Thanks for the suggestions, keep 'em coming!
The following command works just great as the only line in a batch file:
start "Google Sync" /belownormal "C:\Program Files\Google\Drive\googledrivesync.exe" /autostart
When I drop that line into msconfig startup tab, however, nothing happens.
So I thought maybe I needed to put in the full path to start.exe. Assuming it was an exe, that is.
So I tried both DIR and WHERE to locate start.* but nothing came up.
So, two 2uestions.
Is start a separate START.EXE executable in W7Pro and if so where is it?
How can I get this line to work inside msconfig?
Before you ask, my underlying purpose is to start Google Backup and Sync in the same way it usually does, but with /BELOWNORMAL priority. I already tried adding /BELOWNORMAL to the line Google was originally using in msconfig, without success. But START does what I want from a batch file and so I assume it would, or should, work via msconfig.
Thanks.
If you want to use commands implemented by Cmd.exe you must invoke Cmd.exe:
cmd /c start "Google Sync" /belownormal "C:\Program Files\Google\Drive\googledrivesync.exe" /autostart
Disclaimer: I read this and this before, but it doesn't work as I want.
Description: I decided to create set of batch files for convenient way to run different projects in VSCode from desktop in one click(double-click). I want close cmd terminal after running a batch file, but terminal remains. I tried:
start code "C:\Users\MyUserName\path\to\my\project\directory"
and
cmd /c start code "C:\Users\MyUserName\path\to\my\project\directory"
It quickly runs command, runs code and opens my project, then, it seems to me, closes terminal and runs a new one in desktop directory.
I found solution with help of DavidPostill. This works fine for me:
start "" cmd /b /c code "C:\Users\MyUserName\path\to\my\project\directory" && exit 0
UPDATE:
There is a more simple way to run VSCode using command line interface:
cd path/to/my/project
code .
If anyone else comes across this in 2022, I found a solution that works great for me.
code "" "C:\path\to\folder\with\project" | exit
Also, below is my batch I made for a quick workspace that:
asks for a folder name, this will also be used as the project name
makes the vscode project
makes 2 text files, one for things I had to look up, and another for answers to my question
makes a png file called work.png that opens with paint for diagrams I might need for thinking through things
Lastly (the part I love the most) it CLOSES the command window once everything is opened!
Hope this helps someone like me who doesn't know everything about batch files!
#echo off &setlocal
set /p "folder=Enter the folder name to be created: "
md "%folder%" ||(pause &goto :eof)
cd %folder%
echo. > Things_I_had_to_look_up.txt
echo. > Answers.txt
dotnet new console
xcopy /s "C:\xPaintFileTemplate" "C:\Users\TBD\Documents\Program Work\%folder%"
start mspaint.exe Work.png
code "" "C:\Users\TBD\Documents\Program Work\%folder%" | exit
Rem not needed but to be safe
exit
The C:\xPaintFileTemplate is a folder in my C drive that contains only a png file named Work.png. The png file is blank, and sized to what I want mspaint to open with. If there are more files in that folder, it will copy all of them, so be careful with xcopy!
The Rem is a comment, saying the exit command doesn't seem to be required but I added it in anyways as I believe it is good practice.
Try using: start cmd /C code . :0 It should be able to close the cmd terminal. At least that worked for me on my Windows 10.
Another version:
start cmd /C code "C:\Users\MyUserName\path\to\my\project\directory" :0
Based on Blake Daugherty's answer, I found the first pair of double quotes seems unnecessary:
code "D:\proj\directory-1" | exit
code "D:\proj\directory-2" | exit
exit
None of the above worked for me; at worst one of the left-over CMD's needed its close button clicking three times before it would go away.
I tried the URL method and this worked just as I wanted: VSCode opened, and the cmd window went away; my batch file ("VSCode on project.bat") contains just one line:
start vscode://file/C:/path/to/project
or:
start "" "vscode://file/C:/path/to/project"
One line code:
code C:\Users\MyUserName\path\to\my\project\directory pause
Solved
thank you so much for helping me Jean-François Fabre, haveing someone who was thinking along with me kept me motivated to keep figuring things out myself!
what i ended up doing is using a timer script, that first boots up the scanning script, after 900 seconds of pauze the timer proceeds to open a vbs script that closes cmd and opens the timer again to do another 15 minute loop.
how to close a batch file with another batch file
C:\pokemongo-api-demo-maps>taskkill timedlocator
ERROR: Invalid argument/option - 'timedlocator'.
Type "TASKKILL /?" for usage.
currently using a runner script that boots up the batch file every 15 Sec (testing)
it wont close the batch script however
ive tried
taskkill/im cmd.exe
and
taskkill/im timedlocator.bat
the timedlocator gives the error, and the cmd closes the runner script aswell
that needs to reboot it, i cant seem to shutdown a specific cmd window without closing the other one, one solution ive tried is to make this timer shutdown script VBS and use this to shutdown CMD all together before rebooting it, but i dont know anything about what commands to use in VBS
original post
so basically i have a script that scans a area in pokemon go, unfortunately its about as unstable as it gets, so to fix this i need to reboot it about every 15 minutes, ive already tried a few things but got stuck in the end because im not very familiar with coding,
the original boot script script:
#echo off
set /p UserInputPath= Set Location-
C:\Python27\python main.py -u name -p pass -l "%UserInputPath%"
this calls the actual program that does all the work, after some research i found this How do I create a batch file timer to execute / call another batch throughout the day
and added this into the start of the script
start timer.bat
this opens a 2nd script to close and reboot after a timer
TIMEOUT /T 15 /NOBREAK
taskkill timedlocator
start timedlocator.bat
this leaves me with 2 problems i have not been able to figure out
how do i close the first batch without closing the timer CMD? ive tried messing around with taskkill and closing cmd alltogether, but this makes it impossible to boot it again
how do i automatically input a fixed streetname into the first file?
i have tried to replace the userinputpath with the streetname but that didnt seem to work.
setlocation-
at which point you enter a streetname, it sends this to the locator and it starts working,
what im trying to achieve is bypassing this first step and always send the same name.
any help with this would be much appreciated, ive been messing around w this for about 2 hours now and i have made some progress but ive seemed hit a dead end here with my limited computerskills
not sure of you're asking, but I'll try to answer anyway:
how do i close the first batch without closing the timer CMD? ive tried messing around with taskkill and closing cmd alltogether, but this makes it impossible to boot it again
You're taking it the wrong way round: create a script called runner.bat for instance and put this (untested)
:loop
start timerlocator.bat
timeout /T 900 /NOBREAK
taskkill /F /IM "python.exe"
goto loop
Your main script is started in background, and is killed and relaunched every 15 minutes (your 15 value is wrong timeout needs seconds).
how do i automatically input a fixed streetname into the first file? i have tried to replace the userinputpath with the streetname but that didnt seem to work.
=> remove the /P option and set the real value.
set /p UserInputPath=type_your_value_here
I have got a batch script that ends with the following:
TITLE ALL DONE. You can close this window
ECHO.
ECHO ALL DONE. You can close this window
ECHO.
Pause
EXIT
it works fine when i run just the bat file (see below)
All Done! You can close this window.
Press any key to continue . . .
But when i create a self extracting exe out of the same bat script it wouldn't show this window after the execution and would just exit without any proper message.
Since the script works fine by itself, i am a bit lost on what could be causing this? How could i make the self extracting exe to show that window and prompt the user to close it like above.
It depends on the content of the executable, if your including other files to your archive be sure the program you run after extraction is your batch file.
If your only including that file i suggest you use BatToExe Converter
much more efficient way to build it, also it supports commandline, including other files, product info, admin manifest etc