[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

hello all,

I have a batchfile to check version from text file, if it matches do something for now

cmd.exe /c type \\version.txt | find /i "14.56"

if it matches to version in text file dont do anything, if it matches run following command

cscript.exe Messagebox.vbs "STOP"

if it doesnot matches run

cscript.exe Messagebox.vbs "Success"

regards
0
CompTIA Network+
LVL 12
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

For some reason, I can't get my Windows batch script to read a file.   The file exists...I've checked a million times. The path is correct...I've checked a million times.  

Yet it does not enter the "for" loop.  If I put double-quotes around the %DataElements%, it goes into the For loop just fine and prints the value of %DataElements%.  I paste that value in the CMD window and up pops the file.  It doesn't make sense.  

@echo off
setlocal enabledelayedexpansion
set DataElements=E:\myDir\Data_Elements.txt
for /f "tokens=*" %%a in (%DataElements%) do (
      set line=%%a
      echo line is !line!
)

What the heck?!
0
Need better solution for backing up data to a network drive.  Powershell or batch script is ok, just the logging is less than desired.  Needs to be able to run on Windows server OS and handle large amounts of data (2 TB - 8 TB).  

FreeFileSync and SyncToy were great applications that worked well for this simple purpose.  Make a folder pair and configure the kind of sync between the folders.  I am fine doing in a script, just do enjoy the ease of use there.
0
Using Windows Batch Scripting, I'm working to pull certain strings from an error log so I can build a SQL Statement.  

So far, I've gotten what I need into a file on one continuous line.  It should be that way each time I pull in an error.  I'm interested in pulling out only the UPDATE statements and certain elements related to each one.

The line may contain one or several INSERT, UPDATE or DELETE statements peppered throughout so it's very tough to decide what to search for.  

As I pull in the strings I want for each UPDATE statement, I'll build the SQL and call a stored procedure to do what I need to do.  Then return to the Batch Script to get the next UPDATE statement (if there is one).

I've already managed to get a Count of the number of UPDATE statements so I can use that for a loop.

The line below is an example of what I've managed to place in a file (all one continuous line).

} SQL Exception (state )(using SQL: "[UPDATE owner.tableName SET i_unwanted_column1=yyyy,i_unwanted_column2=yyy,i_unwanted_column3=yyyyy,d_unwanted_column4=to_timestamp('1900-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss.ff3') WHERE i_pkey_column = yyyyy , UPDATE owner.tableName SET i_unwanted_column1=xxxx,i_unwanted_column2=xxxx,i_unwanted_column3=xxxxx,d_unwanted_column4=to_timestamp('2018-10-29 00:00:00','yyyy-mm-dd hh24:mi:ss.ff3') WHERE i_pkey_column = xxxxxx ]"):

I need to extract the "owner", "tableName" (found after the UPDATE), the primary key column name and it's value…
0
I'd like to use a batch file to sum some specific numbers in a text file, unfortunately I do not have the skills required. In the following text file "test.txt", for all rows beginning with "622..." I need the second block of numbers summed together and put in a line after the last "622..." line. The total must retain any leading zeros so that the result will always be 15 digits long. It should also line up with the spacing of the values above it. The first number in the total line is a constant, as is the “COMPANY NAME”. At the end of this total line, the “00724…” number should maintain the chronological order of the one above it.

Original txt file:

101 123456789123456789123456789123456789BANK NAME              COMPANY NAME                   
5200COMPANY NAME                        1234567891CCDPAYMENT   123456789123   1072414250000001
62202123456789123456789      000056998811365          CHEMICAL MASTER LTD     0072414250000001
622021321321456987568        000149897016984          CHEMCO USA INC          0072414250000002
622011233214569874563211     000017285016585          GUME INC                0072414250000003
6220225411123658954212       000270139112936          DIOVIK GROUP            0072414250000004
6220432211655548541232       000000632017155          SANVED ENTERPRISES      0072414250000005
820000000500112340500000000000000000497895191123456789                         072414250000001
900000100000100000001234732205000000000000000004949519               

Open in new window

1
Hello

In order to backup properly my SQL Database I need to create 2 batch files which will run on 2 scheduled task and will do the following tasks

1)      Daily at 23h PM : STOPSQL.BAT : Stop SQL SERVER Service and Stop SQL Server Agent Service
2)      Daily at 6h AM: STARTSQL.BAT: Start SQL SERVER Service and Start SQL Server Agent Service

What is the recommended solution for the content of these 2 batch files?
Thank you
0
I want to write a batch script which does the following. Can someone please help me in this? Thank you so much in advance!!

1.We get files with naming convention similar to 2604230_VIJAY_TAX_02-NOV-2018.xls in C:\temp\
2. I want to extract the strings before the Underscore("_") from the filename and save it to variables
3. For example from 2604230_VIJAY_TAX_02-NOV-2018.xls filename, I want to extract 2604230, VIJAY, TAX and 02-NOV-2018.xls and save them to variables.
0
I would like to create a batch file to change a record in a text file that contains about 800 records but have no clue how to do it. Here is there current record I am looking to change. The name of the file is TEMPL2.txt (if that matters).

2,0000501,1,2018-08-13,,0000176,Test,,,,Y,Test@Test.com,0501,Business Development Manager,2080,999,,1.01.90.966,2080,,,,2018-08-13

Notice after the email address the number 0501. I would like to change this to 1501 so the final result:

2,0000501,1,2018-08-13,,0000176,Test,,,,Y,Test@Test.com,1501,Business Development Manager,2080,999,,1.01.90.966,2080,,,,2018-08-13
0
Hi there..

I would like to change the following X01 and ABC lines in a text
file from this format:

X01*00010*48*CA***TS*54589652358745*XA*589856562354*UR*000000054585789656~
ABC**PXP*20.1~

to this format:

X01**48*CA*20.1**TS*54589652358745~
ABC**PXP*20.1~

Every time it sees an X01 line I would like to modify it and every time it sees
an ABC line I would like to modify it to the format above.

There could be multiple X01 and ABC lines in any given text file so it's the format of the line changes that would be important and the movement of the data etc..

Is this possible in Powershell or Batch?

Thanks so much in advance.
0
Hi,

I have a source file named 'Get_SubVar_Yr.log' that has these three lines:

Processing...
 ALL.Act_Yr=FY18
getsubstvar completed successfully

I'm trying to set a variable equal to the value after the = on the 2nd line.  So my variable named 'theyear' would equal 'FY18'.

for /f "tokens=1,2 skip=1 delims==," %%A IN ("D:\Get_SubVar_Yr.log") DO @echo %%B

Open in new window


I'm not sure how to resolve the 'delims==' part to start.  Is that possible?
Also do/should I need to skip the first line and did I get that correct?
Will the 3rd line hose anything up?
Is For /f   the correct method in the first place?
1
HTML5 and CSS3 Fundamentals
LVL 12
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Task Scheduler has stopped running custom reboot batch files. We've got two of them were the first is scheduled to run every Monday morning. The other is set when we need to run a reboot out of hours for that night.

It has in the past run, but we have discovered it has stopped.

It running on Windows Small Business Server 2011

We've created a test batch file that opens a cmd window that says test and awaits for someone to press a button to continue but that doesn't appear when using task Scheduler.

Any help is appreciated
0
I created a batch file with the following command for test (before I set in production):

TestMe.bat
REM echo off
for /L %%A IN (1,1,10000) do echo %%A 2>&1 | wtee -a outputv2.log & for %%F in ("outputv2.log") do if %%~zF GTR 500 del %%F | echo %date% %time%  File %%F with size %%~zF >> deleted.log

Open in new window


Question:
Why is the date and time not changing after deleting "outputv2.log" and logging in "deleted.log"? Where is the bug or how can I correct it?

For me it seems that on every delete it logs the starting  date and time of the batch file.

deleted.log:
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
09.11.2018 21:23:45,17  File "outputv2.log" with size 504
1
The zip file is a folder containing 6 files.

Three originals and three examples of the required result.

In each of the original files:
la_162.csv
la_163.csv
la_164.csv

column A contains a heading in A1  and a list of numbers from A2

The requirement is to be able to highlight all original files in the folder and run a script that
1. includes the number from the file name in column B as per the example for each file and
2. renames the amended file to include the heading from Column A in that file name.
EE-folder.rar
0
Is it any example to write a shutdown script such that it will randomly shutdown the Window after 0:00, close the Outlook if it is opened and copy the ost file to the server ?

Thx
0
I am having trouble with my batch files .bat.  The folder names have spaces in them and the commands do not like it.

Powershell also has this problem.

There are many files to process so renaming them manually is not an option.

How can I get around this?
1
Hello experts,

I have the following layout

Root Folder —- with files and subfolders

I need to use robocopy to only copy the files in the root folder and skip any subfolders. Just going after the files at the root level folder but not the subfolders.

Ie

Root folder — has subfolders 1,2,3 and files a,b,c, etc

I only want to copy files a,b,c and any other files but not the subfolders.

Any help?
1
is there a way to add to the windows credential manager via the command prompt
I'm not referring to cmdkey but the actual windows credential manager apparently they are not the same thing.
When I use cmdkey /generic:TERMSRV/server /user:username /pass:password
it works fine it I run mstsc /v:server  
but if I run it from the desktop by clicking on a shortcut it prompts me for the password; however, if I put the credentials in windows credential manager I do not get the prompt

so, is there a a command to add a username and password to windows credential manager ?
I don't want any user interaction I want to run it through a bat script or psexec or something.
Thanks!
0
Batch scripting

Experts,

I have run across an old dos batch script that utilizes something I have never seen.

The script is used to copy a file, but the reasons behind and the uses for the [ ] is what I am looking for.

copy h:filename.txt i:[Spreadsheet]\folder1\folder2

Open in new window

1
Is there any way to list all the folders and files under a particular directory ?

Thx
0
Bootstrap 4: Exploring New Features
LVL 12
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

I would like a simple script in .bat, .vbs, or powershell, which will look into a .txt fle and do one of the following, whichever is easier to do:

1.  Whenever it sees specific text such as AD, or DE, or BOG, or STOW..  that it will insert a tilde character (~) just before the text and then save the file with a new name.

OR

2.  Whenever it sees the specific text such as AD, DE, BOG, or STOW, that it would start a new line which starts with those characters, and only start another line when it finds the next set of specific text.

The file resides at:  
C:\Users\user\Desktop\folder\file.txt
And the output should be in the same folder but renamed to:
C:\Users\user\Desktop\folder\fileR.txt
2
Hello experts,

I use the following script the script reported at:
https://www.experts-exchange.com/questions/29123510

which allows me to ping based on multiple loops

I would like add in the script traceroute operation in order to generate ping logs and traceroute based on IP’s reported in config txt file.

Adaptations to include :
-Include traceroute operation in the script
-Change log output name in order to include log-ping_IP_YYYYMMDDMMHHSS, log-traceroute_IP_YYYYMMDDMMHHSS
-Loop parameter will cover ping operation and traceroute operation.

If you have questions, please contact me.
0
Hello experts,

I am looking for a script in order to get the process view of task manager in a csv file.

2018-10-30_11h04_42.png
The various values should be displayed as they are displayed in taskmanager: CPU %, Memory MB etc;;.

If you have already a script that output automatically this type of information could you please share with me?

Thank you again for your help.
0
Hello experts,

I have use the following command to get system information and process list
Processlist
Systeminfo
I would like to extract information from a user, as a result I was wondering if you can help to set up a bat file to output both informations in differents files.
Both output files should generated in the same location as the bat file.

If you have questions, please contact me.
0
Windows Batch file to count a set "N" number of files from a single source folder,merged multiple files together into a single output file that contains <= N number of records, and move processed files to a save directory folder.

Request for a window bat file that can be run from command/CMD prompt.  Windows 7 environment.

Windows Batch file to copy a set "N" number of files from a single source folder to an output file, move processed records to a single save folder.  The single source directory may contain 1 up to a million files.  
Need to copy 200 files at a time to a newfile_N+ that should contain <= 200 files per newfile_N+ until all records have been read and processed.

Input file extension: *.hl7
Output file newfile_N+ extension: *.txt

Source directory - C:\temp\source
Destination directory - C:\temp\output\newfile_N+.txt
Destination directory - C:\temp\processed

For the purpose of demonstration I have attached (5) sample hl7 files.
Each newfile_N+.txt file should contain <= 2 records per file.

Prior to kicking off the batch file.  All (5) source files would be all be in the (C:\temp\source) directory.
Upon completion of the batch program running.  The expected output once the bat file has run would result in the following:

C:\temp\source
      dir: contains no files *.hl7 files
      
C:\temp\output
 dir: newfile.txt, newfile1.txt, newfile2.txt
      Note: Each of these files contains <=2 records each, max is 2 records per file
      ==> newfile.txt …
1
Hello experts,

I have the following batch file, reported at:
https://superuser.com/questions/309403/batch-file-to-write-ping-results-to-a-text-file
@echo off

set/p host=host Address: 
set logfile=Log_%host%.log

echo Target Host = %host% >%logfile%
for /f "tokens=*" %%A in ('ping %host% -n 1 ') do (echo %%A>>%logfile% && GOTO Ping)
:Ping
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do (
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>%logfile%
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A
    timeout 1 >NUL 
    GOTO Ping)

Open in new window


I would like to add some enhancement
-Be able to report the various ip in a config-file.txt
-Be able to output multiple files related to ip reported.
-Parse the time of ping for example I would just to ping during 2 minutes and then exit.


If you have questions, please contact me.

Regards,
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.