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 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
Exploring SQL Server 2016: Fundamentals
LVL 12
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

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 scheduled task that runs a batch file.  The batch file has several lines where I do a "git pull" command from a specific Git repository.  The Windows server where this runs has already been configured with proxy settings so that when you run "git pull" or any "git" command, it will properly connect to the required repository and run the command.  I have figured out that this schedule task and batch file will run just fine when a user is logged on.  But if I log out of the server, the schedule task start, but the "git pull" command gets stuck.  It's almost like it's can't connect and then the rest of the batch file will not run.  What should I do to ensure the "git" commands run fine even when a user is not logged in?

Thanks in advance!
-Christian
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
Hi there,

I have a scheduled task with these properties:

User account to run the task: A Service account that has logon as batch file privileges
Run whether user is logged on or not is enabled
Run with highest privileges is enabled
Configured for Windows Server 2012 R2
Trigger: Runs hourly
Actions values:
  • Action: Start a program
  • Program/script: Powershell.exe
  • Arguments: -command "Start-Process  C:\Build.bat -Verb runas"
  • Start in: C:\SDS_IT\

Now the problem I am having is that even though I have set the task to run whether user is logged on or not, it never completes unless the user is actually logged on.  If it I log out, the task starts and it gets to about 95% done and then it just gets stuck.  I've tested this theory several times and this is always the case.  I'm confused as to why it's not working.  The service account has local administrative permissions on this VM too.  I'm using PoweShell because I want the script to run a command prompt as administrator.

Any thoughts????
Thank you in advance!
-Christian
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
Become a Microsoft Certified Solutions Expert
LVL 12
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

.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
Xpdf - PDFtoPS - Command Line Utility to Convert a PDF File to PS (PostScript)
In this tenth video of my Xpdf series, I discuss and demonstrate the PDFtoPS utility, which converts a PDF file to PostScript (PS). Also, it provides an option allowing creation of an Encapsulated PostScript (EPS) file. It performs its functions via a command line interface, making it suitable for use in programs, scripts, batch files — any place where a command line call can be made.

1. Download the software


You may have already downloaded the Xpdf tools while watching one of my earlier videos in the series, but there has since been an upgrade from Version 3 to Version 4 and there is a new download site:

https://www.xpdfreader.com/download.html

Visit that site and download the pre-compiled Windows binary ZIP archive, then unzip it.

Step1

2. Locate the documentation folder for the Xpdf utilities


Go to the folder where you unzipped the downloaded ZIP file and find the doc folder.

Step2

3. Read the documentation for the PDFtoPS tool


Go into the doc folder and find the plain text file called pdftops.txt.

Open it with any text editor, such as Notepad, and read it. This is the documentation for the PDFtoPS tool.

Step3

4. Set up a test folder


Create a test folder.

Copy pdftops.exe from the unzipped bin32 folder into your test folder.

Copy a sample PDF file into your test folder.

Step4

5. Set up a command prompt for testing


Open a command prompt window.

Navigate to your test folder.

Issue a DIR command in the command prompt to be sure that only two files are in it - the PDFtoPS executable and the sample PDF file.

Step5

6. Run the PDFtoPS utility to create the PostScript file


Issue the following command in the command prompt:

pdftops TestFileName.pdf
1
LVL 25

Expert Comment

by:Andrew Leniart
Great video and introduction to a very useful tool indeed.
0
LVL 63

Author Comment

by:Joe Winograd, Fellow&MVE
Thank you, Andrew, I appreciate the compliment and the endorsement. Happy New Year! Regards, Joe
0
Xpdf - PDFtoPPM - Command Line Utility to Convert a PDF File to PPM, PGM, PBM
In this ninth video of my Xpdf series, I discuss and demonstrate the PDFtoPPM tool, which converts a PDF file to color portable pixmap (PPM) format, grayscale portable graymap (PGM) format, or monochrome (black & white) portable bitmap (PBM) format. It creates a separate image file for each page of the PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any place where a command line call can be made.

1. Download the software


You may have already downloaded the Xpdf tools while watching one of my earlier videos in the series, but there has since been an upgrade from Version 3 to Version 4 and there is a new download site:

https://www.xpdfreader.com/download.html

Visit that site and download the pre-compiled Windows binary ZIP archive, then unzip it.

Step1

2. Locate the documentation folder for the Xpdf utilities


Go to the folder where you unzipped the downloaded ZIP file and find the doc folder.

Step2

3. Read the documentation for the PDFtoPPM tool


Go into the doc folder and find the plain text file called pdftoppm.txt.

Open it with any text editor, such as Notepad, and read it. This is the documentation for the PDFtoPPM tool.

Step3

4. Set up a test folder


Create a test folder.

Copy pdftoppm.exe from the unzipped bin32 folder into your test folder.

Copy a sample PDF file into your test folder, preferably one with numerous pages.

Step4

5. Set up a command prompt for testing


Open a command prompt window.

Navigate to your test folder.

Issue a DIR command in the command prompt to be sure that only two files are in it - the PDFtoPPM executable and the sample PDF file.

Step5
1
Xpdf - PDFtoHTML - Command Line Utility to Convert a PDF File to HTML
In this eighth video of my Xpdf series, I discuss and demonstrate the PDFtoHTML utility, which, exactly as its name says, converts a PDF file to HTML. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any place where a command line call can be made.

1. Download the software


You may have already downloaded the Xpdf tools while watching one of my earlier videos in the series, but there has since been an upgrade from Version 3 to Version 4 and there is a new download site:

https://www.xpdfreader.com/download.html

Visit that site and download the pre-compiled Windows binary ZIP archive, then unzip it.

Step1

2. Locate the documentation folder for the Xpdf utilities


Go to the folder where you unzipped the downloaded ZIP file and find the doc folder.

Step2

3. Read the documentation for the PDFtoHTML tool


Go into the doc folder and find the pdftohtml.txt file.

It is a plain text file. Open it with any text editor, such as Notepad, and read it. This is the documentation for the PDFtoHTML tool.

Step3

4. Set up a test folder


Create a test folder.

Copy pdftohtml.exe from the unzipped bin32 folder into your test folder.

Copy a sample PDF file into your test folder, preferably one with numerous pages.

Step4

5. Set up a command prompt for testing


Open a command prompt window.

Navigate to your test folder.

Issue a DIR command in the command prompt to be sure that only two files are in it - the PDFtoHTML executable and the sample PDF file.

Step5

6. Run the PDFtoHTML utility


Issue the following command in the command prompt:

pdftohtml TestFileName.pdf HTMLfolder
2
xpdfrc - Configuration File for All Xpdf Utilities
This is the eleventh — and final — video of my Experts Exchange Micro Tutorials on the Xpdf utilities. The first video is an overview of the command line tools. The next nine videos are tutorials on all them:

PDFimages - Extract Images from PDF Files
PDFtoText - Convert PDF Files to Plain Text Files
PDFinfo - Retrieve Page Count and Other Information from PDF Files
PDFdetach - Detach Attachments from PDF Files
PDFtoPNG - Convert a Multi-page PDF File into Separate PNG Files
PDFfonts - List Fonts Used in a PDF File
PDFtoHTML - Convert a PDF File to HTML
PDFtoPPM - Convert a PDF File to PPM, PGM, PBM
PDFtoPS - Convert a PDF File to PS (PostScript)

This last video in the series discusses xpdfrc, which is the single configuration file that Xpdf uses for all nine utilities. It provides an enormous number of options, allowing extensive control of the tools, such as character mapping, font configuration, PostScript control, rasterizer settings, text control, and much more.

1. Download the software and fonts


You may have already downloaded the Xpdf tools while watching one of my earlier videos in the series, but there has since been an upgrade from Version 3 to Version 4 and there is a new download site:

https://www.xpdfreader.com/download.html

Visit that site and download the pre-compiled Windows binary ZIP archive, then unzip it.

Download the Symbol and Zapf Dingbats fonts from the same page.

Step1

2. Locate the documentation folder for the Xpdf utilities


Go to the folder where you unzipped the downloaded ZIP file and find the doc folder.

Step2
1
How to get count of system dump file from control panel through batch script?
It has to select the path as control panel->system security-> system->advanced system settings->startup and recovery->settings-> dump file count

we have to run this script in background, every time when dump create it has to show the count.

And each time it has to save the dump files to some other folder, when dump created..
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
Starting with Angular 5
LVL 12
Starting with Angular 5

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

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
I had this question after viewing SID account to username.

I tried creating the batch file to run through a text file with SIDs in it. This is what i came up with

@echo off
>output.txt (
for /f %%i IN (unresolvedsids.txt) DO C:Desktop\psgetsid.exe %%i
)

When i run it, it creates an empty output file, this is my first attempt at a batch file so i'm not very sure how to troubleshoot what is happening behind the scenes when you click the .bat file
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

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.