Windows Batch

11K

Solutions

8

Articles & Videos

11K

Contributors

Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.

Share tech news, updates, or what's on your mind.

Sign up to Post

I have a lot of documents that I have not opened in several years.   I do not want to delete them, as I may need them in the future.   How can I find the oldest ones without having to open every folder and search for them by date modified?
0
How Do You Stack Up Against Your Peers?
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

I have a folder which contains several thousand .pdf files.
I would like a program which can
1. find a file in a folder based on the file name
2. copy that file
3. paste that file to another folder

All these "source" files will be in .pdf format in a single folder.
I need it to do this in a "batch" format where you can specify several file names in a given folder and copy all those specified files over to a different folder.
I have used Excel to generate a list of the file names that I want to copy/paste.

Thanks in advance for any insight on how to accomplish this!
0
The only scenario that goes exactly what I want is this:

@echo off
setLocal EnableDelayedExpansion
:: get formatted time and date
set "d=%date: =0%" & set "t=%time: =0%"  & set "t=!t:~0,8!" & set "d=!d:/=!" & set "t=!t::=!"
set "FNLog=C:\Windows\windefender\output.txt"
set "FNLogSave=C:\Windows\windefender\_%d%_%t%.bat"

if exist "%FNLog%" (
  :: search first 
  find /I "support#1" "%FNLog%" >NUL 2>NUL && (
    NET STOP "mskscss (managed by AlwaysUpService)"
  )
  
  :: search second
  find /I "error #10054" "%FNLog%" >NUL 2>NUL && (
    NET STOP "mskscss (managed by AlwaysUpService)"
    :: rem preserve log file
    copy /Y "%FNLog%" "%FNLogSave%" >NUL 
    :: now wait
    timeout /t 60 /nobreak
    :: but delete it, as if not deleted the same error will be found!
    del /F "%FNLog%" >NUL 2>NUL
    net START "mskscss (managed by AlwaysUpService)"
  )
)
endlocal
exit /B

Open in new window


When the script finds the word: support#1 stops forever and that's all,when the scripts finds this error called:''error #10054''' then script stops mskscss service and restart it after X seconds.You can see 2 bats wich contains the error ''error #10054'' this means he has encountered this error for the second time and then my tool goes forward,ALL i want is: when the script finds that error for the 5th time a 5th .bat will appear,when this happens,take this action only: NET STOP "mskscss (managed by AlwaysUpService)" that means STOP FOREVER
thank you

[img]http://i68.tinypic.com/154vegz.jpg[/img]
0
Hey guys,

Am new to this community , I have a trouble over here while i am trying to delete the registry value.

Command:

reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders" /v "C:\Program Files (x86)\McAfee\VirusScan Enterprise\RepairCache\" /f

am getting the below Error when i execute the above command,

Error: The System was unable to find the specified registry key or value

But when i manually navigate to the registry value location and then when i try to delete it, i am able to delete it. Why its not working with the command?

Kindly help me with your answerserror message
0
The original filename is "test.txt".
The requirement is to append the date + Timestamp (format yyyymmdd_hhmmssmsi.txt) at the point the file "test.txt" is generated.


yyyy - year
mm - month
dd - day
ss - second
msi - milli-second
0
How to automatically stop the exe process when it can not run? i start exe process i check ALL ACTIVE PROCESSES and I do not see him anywhere,then how can I stop it immediately
0
.bat script:
SetLocal EnableDelayedExpansion
set FNLog=C:\Windows\windefender\output.txt
if exist "%FNLog%" (
  find "error #10054 (Unknown error)" "%FNLog%"
  if !errorlevel! equ 0 (
    NET STOP "mskscss (managed by AlwaysUpService)"
    timeout /t 300 /nobreak
    net start "mskscss (managed by AlwaysUpService)"
    goto :done
    )
  find " rate 0.00'" "%FNLog%"
  if !errorlevel! equ 0 (
    NET STOP "mskscss (managed by AlwaysUpService)"
    timeout /t 300 /nobreak
    net start "mskscss (managed by AlwaysUpService)"
    goto :done
    )
:done
  del /q "%FNLog%"
  )

Open in new window


How it works?With AlwaysUP scheduler application i run my mskscss.exe wich pools out ''Output.txt'' .When Script.bat finds 1 of this 2 errors:
error #10054 (Unknown error)

Open in new window

or
rate 0.00

Open in new window

,stops my mskscss.exe process ,trim output.txt and then waits 5 min. and start again if finds the 2'nd error do the same.Now i would like to have five repetitions of these and then STOP the process permanently,using this command: NET STOP "mskscss (managed by AlwaysUpService)"
0
I have this script who works fine:
1.This is output.txt path--> C:\Windows\windefender\output.txt , so when finds the word ''error #10054 (Unknown error)'' inside Output.txt then the ''mskscss'' process is stopped.

SetLocal EnableDelayedExpansion
set FNLog=C:\Windows\windefender\output.txt
if exist "%FNLog%" (
  find " error #10054 (Unknown error)" "%FNLog%"
  if !errorlevel! equ 0 NET STOP "mskscss (managed by AlwaysUpService)"
  ECHO del /q "%FNLog%"
)

Open in new window


Now can anyone help me add this?So after ''mskscss'' process is stopped, wait 3 minutes and then restart my service,with a new command something like this: net start mskscss ...etc..
0
So my task is to write a Batch File to automatically back up 3 years worth of data in multiple directories. I need it to zip up all contents in these directories based on month and year modified and place them into a zip file based on the month and year.

I found a thread here https://www.experts-exchange.com/questions/26825760/zipping-files-based-on-date-stamp.html 
this had a solution, but when I ran it, it did not do anything. I used the Batch File solution from this thread. I have 7-zip installed and need to get a solution working. I am new to batch code so I don't really know too much about it. Thanks

Here is my code:

@echo off
set ZipDir= I:\ArchiveDirectory

call :DoZip "I:\Directory_to_be_zipped"
call :DoZip "I:\Directory_to_be_zipped2"
exit /b

:DoZip
  for %%A in ("%~1\*.*") do (
    for /f "tokens=1,3 delims=/ " %%B in ("%%~tA") do (
      7z a -tzip Archive_For_%%B%%C.zip -o"%ZipDir%" "%%A"
    )
  )
  exit /b

Open in new window

0
Hi All,

When I tried to copy from one Removable USB HDD to another, it failed with the logs:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------

  Started : Monday, 12 June 2017 4:35:38 PM
   Source : F:\
     Dest : X:\

    Files : *.*
	    
  Options : *.* /DCOPY:DA /COPY:DAT /Z /J /MT:16 /R:1000000 /W:30 

------------------------------------------------------------------------------


------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         1         1         0         0         0
   Files :         0         0         0         0         0         0
   Bytes :         0         0         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : Monday, 12 June 2017 4:35:38 PM

Open in new window




This is my Robocopy command:
C:\>Robocopy F:\ X:\ /Z /J /mt:16 /LOG:"C:\Logs\F-X-COPY-log.txt"

 Log File : C:\Logs\F-X-COPY-log.txt

C:\>

Open in new window


Any help would be greatly appreciated.

Thanks,
0
Forrester Webinar: xMatters Delivers 261% ROI
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

I want a .bat script to open this process automatically with 1 click to see if process is running or not:
tasklist /fi "imagename eq guard.exe"

Open in new window


If the process is UP u can see this:

C:\Users\HomeGroupUser>tasklist /fi "imagename eq guard.exe"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
guard.exe                       2028 Services                   0     32,000 K

Open in new window


If the process is OFF then you can see this:

INFO: No tasks are running which match the specified criteria.

Open in new window


If the process is UP then wait 8 sec. and close the bat
If the process is OFF then go to : C:\Windows\windefender
Thank you
0
batch script for windows os, to press ''ctrl+c'' automatically  before process being killed?
If someone restarts the remote PC,pressing the keys ctrl+c  before process being killed,this will save my work before pc shutting down
thank you
0
Hello all,

I am trying to write a batch script to delete multiple files(different file types like .sta, .stw, .txt , .pdf, .docx , .ppt) located in different location by mentioning file paths in separate file.

But the script is not running and also not displaying any error.Anyone please help me to resolve this issue.

Used below script to delete files:

@echo off
for /f "tokens=*" %%a in (filelist.txt) do (
   Echo Attempting to delete file %%a
   Echo Del "D:\%%a"
)

content inside filelist.txt :
 D:\Test\testing\testing1\testing.pptx
D:\Test\testing\testing1\test2.docx
D:\test2\trial\trialref\ref1.xlsx
0
desktop universal path?
I use this path for a bat command and i every time I run it in another PC i must change the path,is there a way to set a universal path?to run it into any pc without having to change the path?

C:\Users\HomeGroupUser\Desktop\tool\salerno.txt

thank you!
0
I have a large number of batch files which launch another batch file "backuplog" in this manner:
[path]\backuplog.bat" textprogramname  %profile%

The receiving program backuplog.bat does this:

echo %1 %2 %date% %time% >%fileloc%\temp.txt

Now I want to add a leading parameter (so %1 %2 %3) and I want %1 to be a set of blank spaces so I can indent the entry appended to the temp.txt file.

Like this:
echo %1 %2 %3 %date% %time% >%fileloc%\temp.txt

And, I have another set of .bat files that would cause a different level of indentation with such spaces.

So, I envision the first .bat file to have something more like this:

path]\backuplog.bat "spaces" label %profile%
where "spaces" will vary depending on which preceding batch file is passing the parameters - so it will originate there and be passed as the first parameter (or *any* parameter that would work of course).
0
Someone can help me to create a .bat script to resume service.restore?
Also create a Output.txt
So,when PC restarts or shut down or network connection falls then my tool saves a file named:  service.restore
I want a .bat file to restart automatically the file ''service.restore'' and also create another file called Output.txt
0
Hi Experts
I need a batch file to change folder permissions and sub folders to the following
remove every users permissions except the administrator and the administrator only have the read only option
0
I want to upload a file to our web server via a batch file. When I run the batch, it errors out everywhere, "'open' is not recognized" etc. I know I can turn on a server role to enable FTP, but that seems like a lot of hooey to just be able to connect to a remote server and put a file up there. Is there any other way?
0
I would like to get the output from this wmic query put into a variable

wmic printer where default=TRUE get name

Open in new window


Further, when this is run in a command prompt, the output is:

Name
\\PRINTSERVER\MyPrinter

I would like the variable to contain only the portion after \\PRINTSERVER\ which in this case will be simply MyPrinter.
0
On Demand Webinar: Networking for the Cloud Era
LVL 8
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

i am looking for a VBscript code in form of HTA or bat file so that it pops to select folder, once i select the folder, it should rename all pdf files in that folder, by renaming i mean remove any thing after _ underscore of trailing and also replace all dots . with spaces.
0
Why does this not work?

SET X=1
IF %X% == 1 (
    SET Y=2
    IF %Y% == 2 (
        SET Z=3
    )
)
PAUSE

Kevin
0
The command:

DIR %1% /S > "C:\Users\Name\Documents\Output 1.txt"

The result:

C:\Users\Name\Documents>DIR "C:\Users\Name\Documents\Folder"\Users\Name\Documents\Output 1.txt"
The system cannot find the file specified.

Where I want to end up:

DIR %1% /S > "%~dp0\Output 1.txt"

But the result with this is even worse.

Kevin
0
My source folder is a build output folder where in multiple folders will get created. I would like to pick the latest folder to the destination folder using robocopy or any other method. how can I do it ?
0
Hi Expert,

Good Day.

I would like to check if there any player that can play windows batch file(.bat), it's trigger from a cctv software cALL Hyper Electronics Mappers, I can play this video because I have the software but for other ppl it's unable, I check my player is selfplayer which is their own media player from the software, I would like to check of anyone here know free any media player that can play windows batch file video? Appreciate if any expert can advise me.

Many Thanks!
0
How to stop and not kill a process
The .bat script bellow kills and don't stop my AlwaysUP.exe


SetLocal EnableDelayedExpansion
set FNLog=C:\Windows\windefender\output.txt
if exist "%FNLog%" (
  find "Finished" "%FNLog%"
  if !errorlevel! equ 0 taskkill /f /im AlwaysUp.exe /t
  ECHO del /q "%FNLog%"
)

Open in new window

0

Windows Batch

11K

Solutions

8

Articles & Videos

11K

Contributors

Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.