Windows Batch

12K

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 have the following batch file now I want to add STEP 1 STEP 2 if STEP 1 FAILED then goto next step and send email or generate output in txt

powershell.exe -executionpolicy bypass -file J:\Backup\EnableTCP-IP_Named_Pipes.ps1
powershell.exe -executionpolicy bypass -file J:\Backup\Restart-SQL_Server.ps1
if errorlevel 1 echo Unsuccessful > J:\Backup\result.txt
if errorlevel 0 echo command executed successfully > J:\Backup\result.txt

Thanks
0
OWASP: Forgery and Phishing
LVL 13
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Hello experts,
I have the following script which allows me to create monthly folders and move files.

 
@echo off
setlocal EnableDelayedExpansion


rem Get current date
for /f "tokens=2 delims==" %%G in ('wmic os get localdatetime /value') do set datetime=%%G

rem get year, month, day variables
set Year=%datetime:~0,4%
set Month=%datetime:~4,2%
set Day=%datetime:~6,2%


rem Define file and folder locations
set BaseDir=%cd%
set InputFolder=D:\
set LogFolder=D:\HISTO\%Year%\%Year%-%Month%


rem Make sure needed folders and files exist
if not exist %LogFolder% md %LogFolder%
if not exist %InputFolder% exit /b
if not exist "%InputFolder%\*.csv" exit /b

rem Copy csv files to log folder
xcopy "%InputFolder%\*.csv" %LogFolder% /Y

Open in new window

I would like to take it as a reference to add the following requirements:

Check modified date of files to move. Move files older than 2 days on it respective monthly folder.
Example :
Þ      Toto.csv has a modified date equal to 2019/07/13 it should be moved to 07-2019 folder.
Þ      Titi.csv has a modified equal to 2019/08/12 it should not be moved as it hasn’t a modified date older than 2 days.
If you have questions, please contact me.
Thank you for your help.
0
Hi Experts,

How can I modify this DOS command to only look at files created after a certain date?

Thanks
0
Hello experts,
I have the following batch which allows me to count files on specific folder:
@echo off
setlocal enableextensions
set count=0
for %%x in ("C:\Temp") do set /a count+=1
echo Number of csv files: %count%
endlocal
pause

Open in new window


I was wondering how to put:
-/d option to specify files with a date modified older than 30 days
-/s option to proceed recursively

If you have questions, please contact me.
Thank you for your help.
0
I have a subtitle file (srt format) file like this :


1
00:00:00,701 --> 00:00:20,033
ffdfdfddfdf
2
00:00:20,701 --> 00:00:30,033
fdfddfdgdgdgdg
3
00:00:32,000 --> 00:00:38,074
hhhghghggh
4
00:00:42,701 --> 00:00:45,033
vvvffffgdfg

those are only the first 4 lines,but it is very long. What I want to do is to write a batch script that does the following things :

1) it removes all the sentences that are under the timings. In this particular case are : "ffdfdfddfdf" ; "fdfddfdgdgdgdg" ; "hhhghghggh" ; "vvvffffgdfg" ;

2) it changes the sentences that I mentioned above with the number with which each subtitle starts. In this particular case with : "1" ; "2" ; "3" ; "4" ;

So,at the end it should do something like this :


1
00:00:00,701 --> 00:00:20,033
1
2
00:00:20,701 --> 00:00:30,033
2
3
00:00:32,000 --> 00:00:38,074
3
4
00:00:42,701 --> 00:00:45,033
4

that's all. Really I can't do that manually because it takes a lot of time. And I don't know enough how the batch scripting works. I don't know any other language at all. I'm sorry but I can't give you a small piece of code to fix. I hope to find someone that can understand my situation and that can write the code for me. very thanks.
0
The request is fairly simple :
I have a script/batch that some of my friends would like to use (so the request can not be implemented by group policy).
Let's call my script "Batch_a.bat".
"Batch_a.bat" is to be run at user login   (it checks something).
I want another script/batch that will copy "Batch_a.bat" to "C:\zmau" and then add a shortcut into Startup or added to registry under "HKCU\Microsoft\windows\current version\run key"
I would be happy to get both options.


Thanks
zmau
0
Hello experts,
I have a bunch of log files to analyse. They are located in the same folder.
They don't contain common header and they can contain multiple lines.
I would like to append them into a single CSV file with it file name.
The idea is to have the following:
File name; contain; Date modified (related to file)
If a file contains multiple lines. File name should be dupplicated.
Example:
File 1; line 1; Date modified
File 1; line2; Date modified
If possible have a header with the following:
File name; content; Date modified
If you have questions, please contact me.
0
Hello experts,

I have a root in which I have multiple folders and files.
I am looking for a procedure that allows me to:

1)Based on a config-csv-replacement in which I am going to report as of line one Current_Value;New_Value replace literally Current_Value by New_Value
2)Example: toto;tata. toto value should be replaced in all the files located in Root folder and subfolders
3)Log file should be generated to report files in which the replacement took place
4)config-csv-replacement should support multiple lines entries. If config-csv-replacement is complicated to set up, I am in to report Current_Value;New_Value lines in the script

If you have questions, please contact me.
Thank you for your help.
0
Running MySql version 5.7 on Windows 7 Pro.  I am learning MySql .
My goal is to put the MySql password into a file so I don’t have to put the plain text password into batch files I want to invoke .There is much I do not understand about the relationship between MySql and Windows permissions.

Before executing mysql_config_editor, I would manually navigate to the
cd “Program Files\Mysql\Mysql Server 5.7\bin    folder
   and then type             mysql
  I would get a prompt for password.  I enter the password and the MySql command prompt appears.

I read about mysql_config_editor.  So I typed:
  mysql_config-editor  set –user=root –password
  The   mysql_config-editor prompted me for a password .  I entered the password.

  Then I navigated to the bin folder as above.
  I typed          mysql and this time the mysql command prompt immediately appears, no prompt for password.
  The mysql 5.7 manual says the   mysql_config-editor  will create a file called mylogin.cnf  .  I have searched all the drives on my Windows 7 computer and cannot find this file.  Yes, I am logged in as administrator, I have full rights.

So I thought now, when I execute a Windows batch file,  I just need to enter the –user=root command in the batch file  and MySql will log in as user root without any need for me to provide a password.  And this works as long as I am logged in as administrator.

Questions:
Q1.)  I cannot find any file called mylogin.cnf .  I cannot find any file …
0
Hello experts,
I am trying to create copy 100 times specific file however I just got one file copied
for /l %A in (1,1,100) do copy /y ^
"C:\temp\file.txt" ^
"C:\temp\file.txt%A.txt

Open in new window

Could you please advice on this?
Thank you for your help.
0
Why Diversity in Tech Matters
LVL 13
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Hello experts,
I have the following procedures reported at: https://www.experts-exchange.com/questions/29153639/
Batch approach
@echo off
setlocal

set BaseDir=B:\EE\EE29153505\Base
set DestLog=B:\EE\EE29153505\DestLog
set DestCsv=B:\EE\EE29153505\DestCsv

for /f "tokens=*" %%A in ('findstr /m /b /v /c:"0;" "%BaseDir%\*.log"') do (
    move "%BaseDir%\%%~nxA" "%DestLog%"
    move "%BaseDir%\%%~nA.csv" "%DestCsv%"
)

Open in new window


Powershell approach
$sourceFolder = 'C:\Temp\input'
$targetFolderLog = 'C:\Temp\output'
$targetFolderCsv = 'C:\Temp\output2'
Get-ChildItem -Path $sourceFolder -Filter *.log |
	Select-String -Pattern '^[^0]' -List |
	ForEach-Object {
		Move-Item -Path $_.Path -Destination $targetFolderLog
		Move-Item -Path $($_.Path -replace '\.log$', '.csv') -Destination $targetFolderCsv
	}

Open in new window

Which allows me to move log files and it csv equivalent to specific folder if at least one line of log file start with a value different that 0.
I would like to cover additional needs:
-Execute the procedure during 10 hours. As a result I need a WaitingTime of 10 hours (time that procedure will be active) and a LoopRecurrency variables of every 30 second (time that procedure need to check in reference folder)
-Copy (instead of moving) csv file to csv-error folder and log file to log-error
-Generate and append csv files and log files in listing Csv-error.csv & Log-error.csv files involved by the copy reported in previous step.
If you have questions, please contact me.
Thank you for your help.
1
I need to use the SOX utility to loop through and merge a bunch of audio files. I have 81 unique audio files and need to merge each one with an intro audio tag that is a single file. For instance, I have audio files File1.mp3-File81.mp3 and need to merge the intro audio file Intro. mp3 with each one. The intro.mp3 needs to be placed at the beginning so likely needs to be listed first in the sox command. I think the basic sox command is "sox -m file1.wav file2.wav output_file.wav".  All 81 unique audio files and the intro file are combined into a single folder. So I am looking for a batch statement to loop each one with sox. I also need the batch to rename the output file as EPR5007.mp3, sequencing each merged file in increments of 1, so EPR5008, EPR5009, etc.
0
Hello experts,

I would like to cover an additional need related to question https://www.experts-exchange.com/questions/29153505
Solution proposed move log files from input to output if one file contains at least one line which doesn't start with 0.

Powershell approach:

$sourceFolder = 'C:\Temp\input'
$targetFolder = 'C:\Temp\output'
Get-ChildItem -Path $sourceFolder -Filter *.log |
	Select-String -Pattern '^[^0]' -List |
	ForEach-Object {Move-Item -Path $_.Path -Destination $targetFolder}

Open in new window


Batch approach:
for /f "tokens=*" %%A in ('findstr /m /b /v /c:"0;" "C:\TEMP\BASEDIR\*.log"') do move "%%A" "C:\TEMP\DESTDIR"

Open in new window


Additional need:

In input folder I have .log file and also it .csv file equivalent example : ReqXXXX.log and ReqXXXX.csv,

I would like:
-move log file in output (as is)  
-move csv file equivalent into an output2 folder

Assumption:
-Every log file has it csv equivalent.

If you have questions, please contact me.
Thank you for your help.
2
Hello,
I have a temp folder which contains multiple files.
I am looking for a procedure to launch every 1h to move from C:\temp to C:\Output the 50 newest files.
Example:
I have 700 files in C:\temp.
I execute the procedure and I move the 50 newest files.
One hour after I execute the procedure and I have the 50 newest.
The idea is to move the various files progressively.
If you have questions or another approach, please lest me know.
Thank you for your help.
1
I have the following script that executes a program as follows:

@echo off
start /d "c:\Program Files\Hyena" stexport.exe /CONFIG=C:\EP\Export_Services\HYENA_EXPORT_SERVICES.INI

The batch and the installed program it starts both operate on the c drive of the same windows server with network admin rights. I want to create a shortcut on a workstation desktop of a standard user who can execute the script; however, the program must ultimately execute with the authority of a domain admin account (not a standard user who initially executes it).

In other words, if a standard user executes this batch script (as it is written now) it will only execute with the permissions of the user who initiates it and I need additional script to add to it that will execute the program as a domain admin.
0
Hello experts,
I have in a root folder multiple .log file success file contains 0 as start string.
I am looking for a procedure to move all log files which have at 0 as start string at least for one line (Header line 1 should be excluded).
Possible to have a a windows batch & Powershell or VBS?
Thank you for your help.
0
Hello experts,
I have in a specific folder multiple csv files.
I am looking for a procedure to add specific string at the end based on header reported.
The idea is to have
Header=Header1,Header2
EndString = v2

The procedure should allows me to add end string in multiple fields reported.


I attached dummy file.

In dummy file I expect to have adding “_v2” for Field ID and NewID
Header=ID;NewID
EndString = _v2

If you have questions, please contact me.

Thank you for your help.
Dummy-file.csv
0
Running MySql version 5.7 on Windows 7 pro.  I am not a MySql expert.

Before I posted this question I searched Experts-Exchange for mysql_config_editor.  No results were found.

I am trying to use mysql_config_editor .  I have read the information in the v5.7 manual .  The commands shown  in the manual do not work.

First, the manual shows mysql_config_editor running from a shell command.  I have found I have to manually start the mysql command line to get mysql_config_editor to run.  

The manual says to print the information in mylogin.cnf I should type:
  print –all

This does nothing.  So I am confused and the MySql manual is not helping me.

Questions:  
 -  I want to start mysql from a Windows batch file .  I do not want to put the password in plain text in the batch file.  The 5.7 manual says the password can be put into the mylogin.cnf file.  May be this is the wrong thing to do.   Where should I put the password ?

- I searched all of my drives.  I cannot find a mylogin.cnf file.  May be I’m trying to edit a nonexistent file. What is the name of this file in a Windows installation?

- In what file would you put the password?
0
Hello experts,

I am looking for a procedure in order to remove folders located in a RootFolder
and exclude from the removal folders reported in a txt file.
Values to report in txt file: folder name and not folder path.

To keep in mind:
-Windows or Powershell approach are welcome
-Drill down mode not necessary
-RootFolder should be a variable to declare
-Log file to generate with folders removed

If you have questions, please contact me.
Thank you.
0
Starting with Angular 5
LVL 13
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Hello experts,
I am looking for a powershell or windows batch script to Rename items located in a folder based on a string declared as variable.
Thank you in advance for your help.
0
hi,
is there any method to remote check the type of lan cable plugging,  from network card device properties / other windows log?
0
I am attempting to run powershell.exe from within a batch file to add registry entries to the logged on HKCU using the Administrator account.  The following works from the command prompt:

PowerShell.exe -File "%cd%\WriteToHkcuFromSystem.ps1" -RegFile "%cd%\PhishHookLocalUser.reg" –CurrentUser
PowerShell.exe -File "%cd%\WriteToHkcuFromSystem.ps1" -RegFile "%cd%\PhishHookLocalUserOrgInfo.reg" –CurrentUser

When I run the exact same commands using a batch file I get the following error messages:

D:\PhishHook\PhishHook_2.0.0.0\WriteToHkcuFromSystem.ps1 : A positional parameter cannot be found that accepts argument
'ΓÇôCurrentUser'.
    + CategoryInfo          : InvalidArgument: (:) [WriteToHkcuFromSystem.ps1], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : PositionalParameterNotFound,WriteToHkcuFromSystem.ps1

D:\PhishHook\PhishHook_2.0.0.0\WriteToHkcuFromSystem.ps1 : A positional parameter cannot be found that accepts argument
'ΓÇôCurrentUser'.
    + CategoryInfo          : InvalidArgument: (:) [WriteToHkcuFromSystem.ps1], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : PositionalParameterNotFound,WriteToHkcuFromSystem.ps1

I've been Googling all day and I have found nothing but over complicated code that is messy and confusing.  It would be a great help if someone can tell me how to run powershell.exe and give it a variable that means current directory without making any changes to the .ps1 files.

Any help would be …
0
I have a windows batch script that I would like to run as a Windows Service
(non-interactively ie it's running even before user login to Windows) &
this Service should check if it's down/not running & then auto-start
(auto-start when Windows boots up but also auto-start when the
 service is down/not running).

User must not be able to set this service to shut down or Disabled or
Manual;  only local administrator or domain admin can be allowed to
do this.  I'm running on Win 7 & Win 10.

Appreciate a step by step instruction, thanks.
0
We currently use Checkpoint VPN client on our Win7 & Win10 laptops
for about 300 laptops to connect back to office:

this client will auto pops up when it detected Internet, prompting for
2FA.  Is there any way to prevent our users from accessing Internet
unless :

a) they're on our corporate network   OR
b) if they are connected to outside (or their home Internet/Wifi),
    they can't access Internet till they've connected to this Checkpoint
    VPN (which connects to our Checkpoint blade).

Don't plan to use "Always-On VPN" yet as some of our laptops will
still be on Win 7 till end of 2020 (yes, it's beyond the MS EoSL date
but we're applying virtual patches in place of MS patches).

A batch script that detects which network is connected (if it's
Corporate network) that would alter the routing table etc will
be good.

No Powershell script as we've removed PowerShell from users'
laptops
0
I currently use an fping command in a batch file that writes all output to a text file. I want to tweak it to write only errors such as no responses or request time outs. Here is my current batch command.

fping 8.8.8.8 -T -c -L ping_google.txt
0

Windows Batch

12K

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.