[Webinar] Streamline your web hosting managementRegister Today

x

Windows Batch

11K

Solutions

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 need a batch file to delete the contents of a network folder. My Network folder is located at E:\Shares\Company\Temp. I need a batch file to delete the contents of this folder. The batch file should not execute if the path is not found which will prevent something disastrous from happening.
0
The 14th Annual Expert Award Winners
LVL 7
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Hi there,

After I run a job, I need to replace this entire key in a app.config file, but I'm not sure exactly how to replace the entire key.  

<add key="ORMDBSessionFileOrConString" value="text to change" />

I need to be able to run a script (batch/VBscript/anything) that will look for this exact key entry and replace the value of it.  

Any ideas/suggestions?

Thanks in advance!
- Christian
0
VB Script is choking on the long file name format we are using. The portion "1. Awaiting Director Signature" hangs up the script, as it has too many spaces and obviously exceeds formating. How can overcome this naming issue, without renaming the folder?


arrFolders = Array( "\\company\Shares\Departments\Information_Technology\Public\Purchasing\1. Awaiting Director Signature" )

Open in new window

0
What am i doing wrong here? I can get it to map the drive but apparently the drive goes away once i end the psexec session.
when i try to copy the file over with the next psexec command it tells me the drive doesn't exist
please help
@echo off
setlocal EnableDelayedExpansion 
	set /p "ip_address=Enter IP address:"
	set /p "target=Enter computer Manager(2),Training(3):"
	for /f %%a in ("%ip_address%") do (
		for /F "tokens=1,2,3 delims=."  %%i in ("%%a") do (
			set other_ip=%%i.%%j.%%k.%target%
			)
		echo !other_ip! is the Target computer
		psexec -u administrator -p twash01 \\%%a -i cmd /s /c net use z: "\\!other_ip!\c$" "password" /user:administrator 
		psexec \\%%a -u administrator -p twash01 copy c:\source\team*.reg z:\temp -y
		psexec \\%%a -u administrator -p twash01 cmd.exe /c net use z: /delete
	)

Open in new window

im wanting to remote into one computer and share a drive on it and then copy files to the other computer all locally on the remote system . this will make file distripution faster instead of having to send to all computers. I can just send it to one computer and let it copy to the others locally.
Thanks!
0
Hi Experts,
could you help me with this error pls

Trying to execute oracle sql from windows batch file using sqlplus

I thought of trying manually first before integrating with windows batch file. I get below error

C:\Temp\scripts>SQLPLUS
Error 46 initializing SQL*Plus
HTTP proxy setting has incorrect value
SP2-1502: The HTTP proxy server specified by http_proxy is not accessible

Open in new window


However, I can connect ODBC connection pointing to the same db and able to test connect and perform other activities.

Thanks in advance
0
With the following option in robocopy, does it mean any deleted folders/files on the sources will not be deleted on destination ? Should I add additional parameters /MIR and /PURGE  ?

Is it possible to log any errors during the robcopy rather than all details ?

/copy:DATSO /E /Z /NP
0
A robocopy has run for over 24hrs and it doesn't complete. Under the Window tasks, it doesn't have any change in CPU column. Does it mean that the task is  dead ?

thx
0
I  have problem backing up folders with robocopy. It prompts the following errors . If I user the administrator account, it works.

However, for the backup account has been granted with the group which is the same as that of the administrator. Any idea ??


" You do not have the Manage Auditing user right.
*****  You need this to copy auditing information (/COPY:U or /COPYALL)."

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

  Started : Wed Feb 07 10:01:30 2018

   Source : D:\ENGINEER TECHNICAL\
     Dest : z:\FS\ENGINEER TECHNICAL\

    Files : *.*
          
  Options : *.* /NDL /NFL /TEE /S /E /COPYALL /PURGE /MIR /NP /R:0 /W:30
0
Currently, robocopy is used to backup the source to another destination with the following option :
   /NDL /NFL /TEE /S /E /COPYALL /NP /R:0 /W:30

What option should I use if any deleted folders or files on the source should also be synchronize with the destination ?

Thx
0
I need to iterate thru user folders located in C:\Users and delete Chrome cache folders.  For example, I need to delete:

C:\Users\john.smith\AppData\Local\Google\Chrome\User Data\Default\Cache\*.*

But for each user.  What would be the best way to accomplish this?  I'm thinking either a batch file, VBScript or VB program.
0
Free Tool: Subnet Calculator
LVL 11
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

I need to create a batch file, in Windows, that will ping an IP address, and if the host is alive, do nothing, but if the host is not responding, execute a DNS command using the dnscmd.exe file.

I have the dnscmd.exe syntax worked out and that works fine when I execute it manually or in a simple batch.

Where I need help is coming up with the right syntax to execute a ping, and depending on the result, either do nothing, or execute the dnscmd command string.

I think I've figure out the best way to determine success or failure of the ping. If you key in on checking for the appearance of "TTL=" that will tell you success or failure. I just can't come up with a way to execute the ping, look for TTL= and then perform either an exit or run my dnscmd command.

Thanks.
0
Need help with this script. I am trying to get the os, version and patches installed on a server. When i run the script the loop is not stopping and it seems to be running forever until i intervene and stop the script. Please help me in understanding where i am going wrong.

@echo off
setlocal

rem Define output file location
set outputfile=%computername%.csv

rem Overwrite output file and add header line
echo Caption,Version,Node,Description,Type,HotFixID,InstalledBy,InstalledOn>>%outputfile%

rem Gather all data desired
for /f "skip=2 tokens=2 delims=," %%a in ('wmic os get caption /format:csv') do (
  for /f "skip=2 tokens=2 delims=," %%b in ('wmic os get version /format:csv') do (
    for /f "skip=2 tokens=2 delims=," %%c in ('wmic qfe get csname /format:csv') do (
      for /f "skip=2 tokens=2 delims=," %%d in ('wmic qfe get caption /format:csv') do (
        for /f "skip=2 tokens=2 delims=," %%e in ('wmic qfe get description /format:csv') do (
          for /f "skip=2 tokens=2 delims=," %%f in ('wmic qfe get hotfixid /format:csv') do (
            for /f "skip=2 tokens=2 delims=," %%g in ('wmic qfe get installedby /format:csv') do (
              for /f "skip=2 tokens=2 delims=," %%h in ('wmic qfe get installedon /format:csv') do (
              rem Write merged results to output file
                  echo "%%~a","%%~b","%%~c","%%~d","%%~e","%%~f","%%~g","%%~h">>%outputfile%
            )
          )
        )
      )
    )
   )
 )
)
0
I had this question after viewing batch findtext match 2 criteria.

related to this, i have no problem working with the output i need to clean up my text file now
I have 3 csv files in the folder Z:\OP\CSV

one is SUBDATA.CSV
AccountID,AcctLineCode,AcctNum,AcctNumArea,RadioAcctLineCode,RadioAcctNum,Name,Address,City,State,Zip,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1,DR1,14,,,,MALCOM X,12640 SOUTH HWY 63,MISSISSIPPI,TX,88888,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
2,DC1,2346,,,,DC 9-17-2015 FAIR PLAY GRADE SCHOOL,301 NORTH WALNUT,POTATO,MO,99988,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
4,DSA,3382,,,,"WUBBLU, DON & TOM",17699 MARBEL ROAD 519,WITCHY,WC,78899,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Open in new window


My output file looks like
02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXX 
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234 XXXXXXXXXX 
02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382 WUBBLU, DO

Open in new window

is there a way to remove the end text and replace it with the text from the 8th - 12th valeu in the csv

So it would look more like this
02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXXXXX 56789 REAL STREET NAME NOTOWN QL 12345 
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXXXXXXXXXXXXXX 11135 ANOTHER STREET NAME SOMETOWN HI 12345
02/01/18 10:12:38 ( 0) Fire Alarm      4          DS-3234 XXXXXXXXXXXXX 1 REAL STREET NAME ATOWN CA 12345 
02/01/18 10:14:16 ( 0) Panic Alarm     2          DSA-3382 WUBBLU, DON & TOM 17699 MARBEL ROAD 519 WITCHY WC 78899

Open in new window

0
I had this question after viewing batch findtext match 2 criteria.
simple question can i reverse the output so the 1st line is last

My output file looks like
02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      4          DSA-3234 XXXXXXXXXX
02/01/18 10:14:16 ( 0) Panic Alarm     2          DS-3382 WUBBLU, DO

i would like it to look like
02/01/18 10:14:16 ( 0) Panic Alarm     2          DS-3382 WUBBLU, DO
02/01/18 10:12:38 ( 0) Fire Alarm      4          DSA-3234 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXX
02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXX
0
I had this question after viewing batch findtext.

Thanks to Bill i now have this

@echo off

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-2%
echo year=%year%
set month=%date:~4,-8%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~7,-5%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

set datef=%hour%-%day%-%month%-%year%
set dayf=%month%-%day%-%year%
set dayil=%month%/%day%/%year%

echo datetimef=%datef%
echo %dayf%
echo %dayil%

pause

set findtext=/c:" DS-" /c:" DSA-"
set findfile="Z:\OP\exa\02-04-18 - Copy.P02"

findstr %findtext% %findfile%

for /f "delims=" %%a in ('findstr %findtext% %findfile%') do echo %%a >> "Z:\OP\test-%month%-%year%.txt

pause

I however now have another requirement, is it possible to only return lines that start with %dayil% ? Like an AND clause?
0
I have the following batch file.

@echo off

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-4%
echo year=%year%
set month=%date:~4,-8%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~7,-5%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

set datef=%hour%-%day%-%month%-%year%
set dayf=%day%-%month%-%year%

echo datetimef=%datef%
echo %dayf%

pause

set findtext=" DS-"
set findfile="Z:\OP\exa\02-04-18 - Copy.P02"

findstr %findtext% %findfile%

for /f "delims=" %%a in ('findstr %findtext% %findfile%') do echo %%a >> "Z:\OP\test-%month%-%year%.txt

pause

Open in new window

I however need to search for multiple criteria i need to find all instances of " DS-" and " DSA-" how do i search for both?
0
I'd like to  remove files and subdirectories that go 4 levels down after X days.

If the parent directory is X days old, then remove the subdirs. But if the parent directory is not X days old, don't taverse the files inside, which can have older files in that directory.

I have tried this which I found on another site. But it errors;
Error: No files found with the specified search criteria.


:: set folder path
set dump_path=D:\BUPS\ThirtyMinAll

:: set min age of files and folders to delete
set max_days=3

:: remove files from %dump_path%
forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd  /c del /q @path"

:: remove sub directories from %dump_path%
forfiles -p %dump_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path"

How can I do this please?

thanks!
0
RDiff.exe is supposed to Return %ERRORLEVEL% if it does not prepare a signature properly.
What I noticed is that if the Basis file changes in between creation of Signature it just aborts operation and produces an incomplete signature file.
Problem is that there is no Error indicator to catch this. How to trap this ?
0
Does anyone know how to start LDB_Viewer (LDBView.exe) from a batch file so it automatically loads a particular Database?

I tried the .bat below and it doesn't do the job.

D:\Access10\LDBView.exe  D:\Access10\Develop\My_MDB.mdb

Thanks in advance for any help.
LJG
0
Take Control of Web Hosting For Your Clients
LVL 11
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

I have added the following lines in a robocpy batch file. However, the folder "Personal" is still copied to backup G: drive. Any idea ?

Thx

ROBOCOPY "C:\Users\john\Documents" g:\Documents /XD "C\Users\john\Documents\Personal" /MIR /Z /XA:H /W:5
0
We have a fileshare where CAD data (pdf, dxf, stp) is written on release.
I would like to make a CMD script that keeps only the last (released partnumber) in the folder and moves the other indexes to a subfolder (\_achrive).
After that for every partnumber a zip should be created.

Here an example on how the filnames look like before the script runs:
800374_.dxf
800374_.pdf
800374_.stp
800374_A.dxf
800374_A.pdf
800374_A.stp
800374_B.dxf
800374_B.pdf
800374_B.stp
800263_A_Sheet__1.dxf
800263_A_Sheet__2.dxf
800263_A.pdf
800263_A.stp
800263_B_Sheet__1.dxf
800263_B_Sheet__2.dxf
800263_B.pdf
800263_B.stp
800263_C_Sheet__1.dxf
800263_C_Sheet__2.dxf
800263_C.pdf
800263_C.stp

The follwoing files would be moved the the \archive folder:
800374_.dxf
800374_.pdf
800374_.stp
800374_A.dxf
800374_A.pdf
800374_A.stp
800263_A_Sheet__1.dxf
800263_A_Sheet__2.dxf
800263_A.pdf
800263_A.stp
800263_B_Sheet__1.dxf
800263_B_Sheet__2.dxf
800263_B.pdf
800263_B.stp

After that the following zip Files will remain:
800374_B.zip
800263_C.zip



Thanks for your help
0
I'm trying to make a batch script for some friends to study basic french from (just a few easy questions) but for some reason when it gets to a section at the end it closes the tab very quickly, before i can read what it says. I have a pause at the end of the script, so I don't know why it would close without performing the pause first.
@echo off
setlocal enabledelayedexpansion
title French Quiz
:start
echo French Study Quiz
echo  --------------
echo (if a question looks unfinished, the answer is D for testing reasons)
pause
goto Q1

:Q1
cls
echo Question 1: What does "COI" mean?
echo ----------------------
echo A. A type of fish
echo B. Compl‚ments d'Objet Indirect
echo C. Clicks On Impact
echo D. Connosieur d'Oranges Imparfait
set/p input1=
if %input1% EQU B goto correct1
if %input1% EQU b goto correct1
goto wrong1

:Correct1
set /a score=%score%+1
goto Q2

:wrong1
set /p q1wrong=1

:Q2
cls
echo Question 2: In Pass‚ Compos‚, what is the past participle of "manger"?
echo ----------------------------------------------------------
echo A. Manger
echo B. Mangeons
echo C. Mangera
echo D. Mang‚
set/p input2=
if %input2% EQU D goto correct2
if %input2% EQU d goto correct2
goto wrong2

:Correct2
set /a score=%score%+1
goto Q3

:wrong2
set /p q2wrong=1
goto q3

:Q3
cls
echo Question 3: If a verb is conjugated with "avoir" in pass‚ compos‚, do you accord it with the pronoun?
echo ----------------------------------------------------------
echo A. No
echo B. Yes
echo C. 

Open in new window

0
Is it possible to check service under services.msc is started using Powershell, batch?

If yes can i automatic start using the Powershell or batch.
0
I am writing a batch file(Say, Primary.bat) that generates a text file(actually .bat, say  Generator.bat) which collects all the text file names from a particular directory(folder) and writes in generator.bat.

The contains of Primary.bat is now -

@echo off
SETLOCAL=ENABLEDELAYEDEXPANSION
Rem Following command will write the names of all files in a text file
dir /b "C:\InputOutput\SourceFiles" > "C:\InputOutput\Generator.bat"

Open in new window



So, the contents of Generator.bat looks like -

input1.txt
input2.txt.
input3.txt
unitedstates1.txt
unitedkingdomsales.txt
...
...
majorregion100.txt

Open in new window



(1) Now I need to  add code in the script(Primary.bat) so that all the above lines in Generator.bat can be changed to the following commands -
 
converter.java    C:\InputOutput\SourceFiles\input1.txt     C:\InputOutput\OutFiles\input1.rtg
converter.java    C:\InputOutput\SourceFiles\input2.txt     C:\InputOutput\OutFiles\input2.rtg
converter.java    C:\InputOutput\SourceFiles\input3.txt     C:\InputOutput\OutFiles\input3.rtg
converter.java    C:\InputOutput\SourceFiles\unitedstates1.txt   C:\InputOutput\OutFiles\unitedstates1.rtg
converter.java    C:\InputOutput\SourceFiles\unitedkingdomsales.txt   C:\InputOutput\OutFiles\unitedkingdomsales.rtg
...                              ...
...                              ...
converter.java    C:\InputOutput\SourceFiles\majorregion100.txt   C:\InputOutput\OutFiles\majorregion100.rtg

Open in new window


(2) After having task 1 done I want to have Generator.bat some code so that on clicking on Generator.bat it executes all the command lines.

Please help with simple code and simple logic. It would be really good if you test code before before replying. Thanks in advance
0
hello all

I am trying to create a batch file to add registry key.
its should run on both 32bit and 64 bit
there are 2 different registry keys for 32bit and 64bit.
so if it is 32-bit, it adds the 32-bit registry key and vice versa

Any ideas?

Thanks in advance
0

Windows Batch

11K

Solutions

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.