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

We have an external Hard Drive (Drive E:) that is shared by 4 end users, i.e., all end users save documents to this device.   This device is never taken off the network.  Although Carbonite is being used for offsite storage of all content on this drive, we'd like to have a local backup solution also.
Our intention is to have 2 USB hard drives that would be plugged in to an end users computer in late afternoon just before our end users leave work.  Device USB1 and Device USB2 would be used on Monday for an initial copy of the Folders / Files from Drive E:.   Then, the devices would be used on alternative nights from that time on.
I need a batch file that would:
   1) On Monday, copy all files from Drive E: to USB1 and USB2
        a) Folder and File Structure would have to be duplicated exactly
 I need a different batch file that would:
   1) On Tuesday late afternoon, only APPEND to Device USB1 those files that had been changed since the files were last saved on Device USB1.
   2) On Wednesday morning, Device USB1 would be unplugged and stored in a safe place.
       a) Device USB2 would be plugged in and be ready for use late afternoon.
   3) On Wednesday late afternoon, only APPEND to Device USB2 those files that had been changed since the files were last saved on Device USB2
   4) On Thursday morning, Device USB2 would be unplugged and stored in a safe place
       a) Device USB1 would be plugged in and be ready for use late afternoon.
   5) Process would …
0
I created a SSIS package and executing it in a Batch File. My SSIS package updates an excel spreadsheet but when i run my batch file a pop up window comes up asking me if I want to replace it since the file already exists.  This option doesn't occur when i run it in Visual Studio, Since my SSIS package code saves the file alreaady. how do i get around this with my batch file.

Batch File pop up.
0
Need a batch script to delete multiple folders and files from user desktop in an environment of 1000 computers which i will be pushing it from group policy . However my requirement would be to delete all the folders and files except one particular folder ( Folder name X ) in the desktop.

Kindly advise on the same.
0
I require a batch file/PS script to sort thousands of .txt files into specific folders.  i have some production machines that create reports in the form of .txt files and these are all put into 1 folder.  Ideally it would create any sub folders required automatically so i don't need to manage them.
I need to sort these in a number of ways.

firstly i need to check the content of the file to look for specific text. and then sort into a number of sub folders using the contents of the file name.

an example would be files named
BR20190127T104207.txt  
PR20190127T104208.txt
BR20190127T102850.txt
PR20190127T102851.txt
BR20190127T102827.txt

the content will contain a specific string  in this case LINE 2

the folder structure is as follows:#

Line 1
      -> Year
           -> Month
                 -> Day
Line 2
      -> Year
           -> Month
                 -> Day
Line 3
      -> Year
           -> Month
                 -> Day

and so on.

i have 8 lines in total and each of these reports come off anywhere from several times a day to several times an hour.  

i plan to run a script overnight to sort any new files created.  the problem is i cannot alter the file structure for a few reasons and currently i am having to sort these manually which is very time consuming.
1
Hello Experts, I have almost zero knowledge of batch file syntax. I have a batch file that works. It is executed via a Windows Scheduled task which is called from SSIS. The syntax has date parameters that are currently hard-coded. How can I pass those two parameters to the batch file.

The parameters in the stript below are: -beg-obs 2017-01-01     and -end-obs 2017-12-31

grpr -new-amf-file "E:\Risk Grouper\Output\20190123Medicaid.amd" -patient "E:\Risk Grouper\Extracts\PatientExportMHACO.txt" -patient-format "E:\Risk Grouper\AMF\PATIENT.amf" -medical "E:\Risk Grouper\Extracts\MedicalExportMHACO.txt" -medical-format "E:\RISK Grouper\ACGF\MEDICAL.amf" -pharmacy "E:\RISK Grouper\Extracts\PharmacyExportMHACO.txt" -pharmacy-format "E:\Risk Grouper\AMF\PHARMACY.amf" -RAV US-ALLAGE -all-models -beg-obs 2017-01-01 -end-obs 2017-12-31 -filter-obs -calc-cost-obs

SSIS is running off of one server and the application that the above code is executing is on another server. Both are Windows Server 2012

Any insight is appreciated.
Thank you
0
I have a text file in 2 columns where column 1 is date in dd/mm/yyyy while column 2 is a user's name.

11/12/2018         aaron
28/12/2018         amber
5/1/2019              ben
2/11/2018            barney
2/1/2019              carl
. . .

Need a Windows batch script (not PowerShell) that when I run today (say it's 18 Jan 2019 today), would lik eto
extract out a list of users where the date in the file is more than 31 days from today's date.  So output will be:

11/12/2018         aaron
2/11/2018            barney
0
need a script to deploy multiple windows updates using a group policy.

1. I will place the following updates on a file share for example: \\192.168.1.100\updates\. I need a script or a batch file that I will publish using a group policy to deploy the updates on my windows 7 client computers. these updates are for windows 7 64 bit clients only.

2. the updates I want to install are like below located in the \\192.168.1.100\updates\ folder.

Windows6.1-KB2729094-v2-x64.msu
Windows6.1-KB2731771-x64.msu
Windows6.1-KB2533623-x64.msu
Windows6.1-KB2670838-x64.msu
Windows6.1-KB2786081-x64.msu
Windows6.1-KB2834140-v2-x64.msu
Windows6.1-KB2888049-x64.msu
Windows6.1-KB2882822-x64.msu
Windows6.1-KB2726535-x64.msu

3. I need a batch file that can trigger the deployment in sequence one after the other.
4. if the update is already installed it should skip and move to the next update.

there are some scripts I found but not working. appreciate any help
0
Hi All,

I am running into problem where I need to open a folder using a batch file.  I have tried start option but due to spaces, I am not able to open the folder.  There are 2 folders one with 2 spaces and one with 3 spaces.

Start C:\Folder1\Folder2\Test Name\ Final test name\test.txt

Once the batch file is complete, I need to write the file name into a text file. Please advice.
1
I have a PowerShell script which checks to ensure certain backups have taken place. The script checks the date of certain flag / semaphore files and shows a message if the files are too old (which one is in this test)

This works fine when manually run from the following batch file
Powershell.exe -executionpolicy Bypass -File  "Check-If-Backup-Failed.ps1"

Open in new window

but not when the same command line is added to the 'logon.bat' logon script.

What am I doing wrong (I presume it is permissions somehow) ?

NOTE: I don't get an error when I login - it just does nothing.
0
Hello Expert's,
Need a batch scripts:-

We have an application which is generated a log file in txt format (d:/OF Top/logs.txt), once application generate new log that happen added to that txt file. It happens so often, txt file have info in the term's of user identity number.
e. g.
11345, TOP, BLACK, TOPIC11, 110067145, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, TOPIC81, 110067155, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, LOGIC00, 110067145, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, MAGIC99, 110067105, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, TOPIC89, 110067110, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, ARPIT67, 110067100, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, MANIS56, 110067110, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, WHITE00, 110067145, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, ACERP23, 110067155, DBEN, EXCEL, 11:33:54, LOCK
11345, TOP, BLACK, TOPIC89, 110067105, DBEN, EXCEL, 11:33:54, LOCK

Column number 5 have user Identification numbers.

There are many such lines store in this file.

Now i want a batch when I run the batch file then batch ask me to place user identity number to grep that particular user identity number and generate a txt file in a prefix location (c:/out. txt)

after that once new entry came to this file it will automatically grep that entry & store (add) in to out.txt file.
0
I have a text file which has duplicate lines... I need to remove any dupes and leave just one of them. The file also needs  2 different strings of words replaced with different strings of words IF either of the 2 original strings exist.

Is this even possible via Windows batch?
0
This is an intention to run a batch file from the usb thumb drive when this thumb drive plug into the desktop or laptop. Targeting MS WIndows  7/10/2008/201. Please see the contents of the autorun.inf as follows,

[Autorun}
ShellExecute=PCChecking.bat
UseAutoPlay=1

The "autorun" didn't seem to fire up.  How to get this automatic function works?

thanks in advance.
0
Hi Folks,

I'm creating a batch script here to allow RDP on Windows
powershell "Set-ItemProperty ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\‘ -Name “fDenyTSConnections” -Value 0"

Open in new window


If I run this script will get me an error :
set-itemproperty: a positional parameter cannot be found that accepts argument

But if I was to copy paste the line above to the DOS console they it would work like a charmed.

Have anybody experienced similar or same issue?
0
.bat file:

:: Get FTP files
ECHO OFF
CLS
rem ECHO Getting FTP files...

rem "C:\Program Files (x86)\coreftp\coreftp.exe" -s -O -site ISI -d /*.zip -p "F:\TeamDB\New backups"

ECHO Extracting zips...
fastzip -x -overwrite=always "F:\TeamDB\New backups\db.zip" .
fastzip -x -overwrite=always "F:\TeamDB\New backups\files.zip" "F:\TeamDB\New backups\ISIFiles"

::SET VARIABLES

set DBNAME=ISP-MIS
set DBDIRECTORY=F:\ISI Databases
::rem set DBDIRECTORY=D:\Databases

ECHO Restoring %DBNAME% Database

ECHO PUT DATABASE IN SINGLE USER MODE TO ALLOW RESTORE
osql -S ISI-SQL\ISIDB -E -d master -Q "alter database [%DBNAME%] set single_user with rollback immediate"

ECHO RESTORE DATABASE
:: rem osql -S ISI-SQL\ISIDB -E -d master -Q "restore FILELISTONLY from disk='%~dp0\%DBNAME%.bak' "

sqlcmd -S ISI-SQL\ISIDB -E -d master -Q "restore database [ISP-MIS] from disk='%~dp0\ISP-MIS.bak' WITH MOVE 'R%DBNAME%_Data' TO '%DBDIRECTORY%\%DBNAME%.MDF',  MOVE 'R%DBNAME%_Log' TO '%DBDIRECTORY%\%DBNAME%_Log.LDF', REPLACE "

::GRANT PERMISSION TO ASPNET USER
::rem osql -S ISI-SQL\ISIDB -E -d %DBNAME% -Q "sp_grantdbaccess '%COMPUTERNAME%\ASPNET'"
::rem osql -S ISI-SQL\ISIDB -E -d %DBNAME% -Q "sp_addrolemember 'db_owner', '%COMPUTERNAME%\ASPNET'"

ECHO RESTORE TO MULTI USER
osql -S ISI-SQL\ISIDB -E -d master -Q "alter database [%DBNAME%] set multi_user"

Open in new window


The above is a .bat which works perfectly when actioned manually and it updates my SQL database
If I set up a scheduled task, the task runs but the file does not work through all of the scripts and the sql database is NOT updated
I have tried many different ways of setting up the scheduled task but no result
Suggestions please
0
Hi,

We are trying to push a login script using the GPO. The script is to copy the default folder of Google from the roaming profile to the local AppData. It is an Xcopy command. I have converted it into a batch file and copied the batch file to the netlogon and sysvol folder. The GPO is applied but does not run the batch file.

The batch file works by itself and also when we copy the batch file to the startup folder in roaming profile it works. All the other policies are working except this.

We use windows 10 and Server 2012 r2

Please provide any advise.

Regards,

Ajoy
0
In IPSwitch ftp professional 12.6

I have a scheduled task that transfers files from a customer FTP to my local folder
Works fine
I have delete access on the customer folder

What I need is Post transfer... after that task has run

Sometime later

I need to delete the files in the customer FTP

I don;t care if I need to include it in the current scheduled activity

Or create a new one that runs an hour later

This runs only once a day
0
I have a text file being created nightly in a network shared folder. That file has many lines including 3 duplicates. The line duplicated 3 times is:

ACCNT	Accounts Receivable - MU	OCASSET

Open in new window


What I need to do is, from within an Access function, delete the 2nd and 3rd dupe, leaving the first one intact.

Why the dupes exist is a rabbit hole that I don't right now have time to fix even though yes, that is the correct way to really fix this problem. But, if I can just have Access code which will delete the 2nd and 3rd entry of that line, it will suffice as a solution for now.

Thank you very much for any input.
0
Rundll32 command runs fine at the command prompt but does not execute in a batch file. Any idea why?

this is the command:

rundll32 printui.dll,PrintUIEntry /in /n\\printers\105-XE-ECOM-BW1

\\printers                      is the print server name
105-XE-ECOM-BW1     is the name of the printer
0
Good afternoon,
I'm need some help with a script I'm using to clean up the profiles on the public pc's. I need to add some code to remove .bak files from the profile list. particularly this one, S-1-5-21-3822824043-2368925748-477173625-1177.bak For that matter, I could use a totally different script but I would prefer to just add it to this one.



@ECHO OFF

FOR /F "tokens=*" %%a IN ('REG QUERY "HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"^|FIND /I "S-1-5-21"') DO CALL :REGDELETE "%%a"
GOTO CLEAN

:REGDELETE
FOR /F %%b IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "internet"') DO REG DELETE "%%b" /F
FOR /F %%c IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "TEMP"') DO REG DELETE "%%c" /F
FOR /F %%d IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "short"') DO REG DELETE "%%d" /F
FOR /F %%e IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "jobseeker"') DO REG DELETE "%%e" /F
FOR /F %%f IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "catalog"') DO REG DELETE "%%f" /F
GOTO CLEAN

:CLEAN
FOR /F %%b IN ('DIR C:\Users /B^|FIND /I "internet"') DO RMDIR /S /Q "C:\Users\%%b"
FOR /F %%c IN ('DIR C:\Users /B^|FIND /I "TEMP"') DO RMDIR /S /Q "C:\Users\%%c"
FOR /F %%d IN ('DIR C:\Users /B^|FIND /I "short"') DO RMDIR /S /Q "C:\Users\%%d"
FOR /F %%e IN ('DIR C:\Users /B^|FIND /I "jobseeker"') DO RMDIR /S /Q "C:\Users\%%e"
FOR /F %%f IN ('DIR C:\Users /B^|FIND /I "public"') DO RMDIR /S /Q "C:\Users\%%f"
FOR /F %%g IN ('DIR C:\Users /B^|FIND /I …
0
Hello experts,

i am in need of a script that can copy a file on a daily basis from one directory to another based upon a changing filename. The filename's base stays the same, however the current date is appended to the end of the file.

For Example:
StaticFileName<Today's date in MM-DD-YYYY format>
or
StaticFileName12-17-2018    <-----This is the filename that needs to be copied on 12-17-2018

I am not a scripting expert so suggestion on best method (powershell, batch etc) is also appreciated.

Thanks in advance.
0
Hi

I'm trying to run a batch file from a SQL Script but error occurs.

Script:
EXEC xp_CMDShell 'C:\Users\Simon\Desktop\Stadium\Stadium Insert\Integration Services Project7\refresh.bat'

Error:
output
'C:\Users\Simon\Desktop\Stadium\Stadium' is not recognized as an internal or external command,
operable program or batch file.
NULL
0
Hello experts,

I have the following bat file which allows me to open automatically multiple tabs.
I would like to add the following requirement:

@echo off

SET BROWSER=chrome.exe
SET WAIT_TIME=2
START %BROWSER% -new-tab "url"
START %BROWSER% -new-tab "url2”"

Open in new window


Instead of reporting url I would like to loop a url.txt which contains the various urls.
Error checking:
If url.txt file doesn’t exists
0
I had this question after viewing List folders and sub-folders of a path with its size.

I need to take this a step further.  I need to be able to search for file types like .mdb, and ,accdb..
Then output data to a text file I can link to.  
All the code I have inserts into the same worksheet, but this keeps crashing my computer.

Ideally I would like to include:
Folder
Sub Folder
Path
Name
Type
Size
Last Modified By or Owner (Not sure if possbile)
Date Last Modified

Exported to a text file.  

We have an insane amount of access databases, I need to do a formal audit to gain an insight of what is out there, size and when used last.
1
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
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

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.