[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

Using Windows batch how can I rename up to 4 files, 1.pdf, 2.pdf, 3.pdf and 4.pdf all based on time stamp, 1.pdf being the file with the earliest time stamp..

At C:\Attachment\.... there could be several files all names differently, but all. pdf files.  
I want to rename each file based on when they were created etc..
0
Build an E-Commerce Site with Angular 5
LVL 12
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Hello experts, some users report bad performance of application that manage my team. In order to launch an action plan I would like to report ping information in a txt file in order to discard network issues.
The idea is that user run bat or vbscript and then a txt file will be generated with ping results.
In bat & vbs file I should be able to report:
1-Adress that I want to ping
2-Time scale and frame option in order to run ping during a certain period of time.

If you have some feedback or ideas about this please don’t hesitate to help me.
0
i   want to upload file called b.txt to any  uploading website ex. uploadfiles.io -  openload.co........  and then past the url on pastebin with a title like here is your file b.txt with Paste Exposure public so i can find it later on the site !!!!!!

the whole point of doing this is to avoid putting any personal info in bat file like online uploading website account info or ftp server info
just safe and quick .... as i love to use them Freely  without caring about getting my info exposed  .
hope you understands
0
I have 100 pc's (mix of windows 10 & 7) and I need a script that will help me find out which if any need to have windows activated. I know I have at least 6 out of the 100 pc's that need reactivation. I would like the script to run against a text file of computer names.

Thanks.
0
I prefer to do this with batch, I've done lots of research and feel that I have like an 80-85% solution I just need some help to get me over the top and clean it up a bit and add some stuff I don't have working yet

batch file to compare 2 folders checking to see if files exist in both folders
if the file exists in folder A and in folder  B then copy it to an archive folder
log the file that is being copied and add the YYYYMMDD to the filename

>>>>>>>start script


@echo on

rem To add YYYYMMDD stamp to files copied to the archive folder

for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
set week=%%i
set day=%%j
set month=%%k
set year=%%l
)

setlocal
rem set variables for folder and network share location to compare files
set movedir=c:\move
set netdir= "\\name\folder"
set archivedir= c:\archive


rem set variable for log folder and log file
set logfile=c:\logpath\logfile.txt

rem check for the archive directory if it doesn't exist create the directory

if not exist "c:\archive" ( echo Creating Archive directory
mkdir "c:\archive"
)

rem map network path
echo Mapping Network location X:

net use x: "%netdir%"

echo Compare Move directory to a Network share

rem Check all files in folder move and Network share with a for loop ???

if the files exist in both directories then copy to archive and add a date stamp to name and log the files that were copied to the archive folder to the c:\logpath\logfile.txt

rem I believe …
0
Is there a script that has the ability to look inside a pdf document and search for a specific text/phrase.. and if it finds it can the script indicate that it found the text?
0
Group policy - startup script, we had add a script to run start a number of services after server rebooted, but it is not executing. able to run manually and the script run fine. checked at the gp result, the policy has been applied successfully
0
I want improve this batch script I wrote to rename a file and upload

@echo off
#Rename Files
cd c:\aaaa\bbbb\
ren QQ-PS.txt QQ-PS.%date:~-10,2%%date:~-7,2%%date:~-2,4%.%time:~0,2%%time:~3,2%%time:~6,2%.txt
ren QQ-OR.txt QQ-OR.%date:~-10,2%%date:~-7,2%%date:~-2,4%.%time:~0,2%%time:~3,2%%time:~6,2%.txt
#Send QQ file to SFTP SERVER
ftp -n -i SFTP SERVER <<END
user xxxx xxxxx
lcd c:\aaaa\bbbb\
cd "\ccc\ddd\"
bin
mput QQ-*.*.txt
bye
exit
0
hi,

i have script working.
When it runs it check for files and send email alert if not files and also if has files.
Currently it sending the email alerts text format.
Request experts help, want to send email with htm format.
and for errors it should bold the text and color RED.
can help...


#Requires -version 3.0
$WarningPreference="Continue"
function Send-Mail
{
  param (
    [string] $Email_Subject,
    [string] $Email_Body,
    [string] $Email_Attachment
  )
  Send-MailMessage -SmtpServer 'mailserver.com' `
  -Body $Email_Body `
  -From 'donotreply@mail.com' `
  -To 'admin@mail.com' `
  -Subject $Email_Subject `
  -Attachments $Email_Attachment
}
function Send-Error
{
  Write-Host "Sending Error Alert @ $emaildate"
  $subject = "ACTION REQUIRED : Error Alert @ $emaildate"
  $logcontents = get-content $Logfile | Out-String
  $Body = "Dear All,`n`nThis email sent by system for errors highlighted below."  + $logcontents + "`n Regards,`n Job Process"
  Send-Mail -Email_Subject $subject -Email_Body $Body -Email_Attachment $Logfile }
function send-status
{
  Write-Host "Sending Success Alert @ $emaildate"
  $subject = "INFO : Success Alert @ $emaildate"
  $logcontents = get-content $Logfile | Out-String
  $Body = "Dear All,`n`nThis email sent by system for your information"  + $logcontents + "`n Regards,`n Job Process"
  Send-Mail -Email_Subject $subject -Email_Body $Body -Email_Attachment $Logfile }

  #check if source files exists
0
How to remove the %JAVA_HOME%/bin; from Path  variable using cmd?
0
OWASP: Threats Fundamentals
LVL 12
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

I use text files as source data to feed Access tables due to 2GB size limitation of MS Access.  I am currently using two text files that are merged daily after the one is updated, one of the text files is 2016-2017.txt historical data merged with daily updated 2018.txt file.  The merged file size is 1.24 GB and I can work just fine with it without any problems.  

Lately I have decided to use a bigger size text file for a larger historical analysis like going back to 2012.  I compiled text files into one  2012-2017.txt file using Windows commands on C:\ prompt and added my daily updated 2018.txt file into this history so I could work with one historical data set all the way back to the year 2012.  This is the method that I use daily for my current daily updates anyway without any issues.  The expanded file size is 3.45 GB and when opened in Excel Power Pivot it displays 90 fields. My goal is after loading the data model in Excel power pivot cerate various pivot tables for historical data analysis.

The problem is that when I merge daily refreshed 2018.txt file into the historical file then connect to the resulting merged file via Excel Power Pivot (Access fails to open this file due to size but power pivot works ok along with Power BI) and insert a pivot table what I see is that all the years' total sales dollars from 2012 to 2017 get displayed correctly but 2018 is incomplete by a huge margin.  I tried to load and re-load several times in different Excel files and I …
0
Hi Experts,
How to grep connected tcp IP & Port connection then forcefully kill using batch.

example;-
netstat -a output is

Active Connections

  Proto    Local Address                        Foreign Address                State
  TCP       192.168.1.101:49366            192.168.1.55:65000          ESTABLISHED
  TCP       192.168.1.101:49475            192.168.1.55:64000          ESTABLISHED
  TCP       192.168.1.101:49384            192.168.1.55:63500          ESTABLISHED
  TCP       192.168.1.101:49396            192.168.1.55:22                 ESTABLISHED

Need to forcefully kill all TCP connection which is connected with 192.168.1.55
0
Within a batch file, I would like to tell the batch to copy the files to the folder which is found just outside where the batch is running.
Is there a command that will allow this to happen?
0
I have a variable with comma separated values in the batch file. Want to choose a random value?


@echo off
set values=1,4,65,8,3,45,7,90
expected output: any one random value from 1,4,65,8,3,45,7,90
0
I have two batch files A.bat and B.bat. A.bat is calling to B.bat.
B.bat is doing some processing, and return back the result to A.bat. How A.bat can accept the return?

A.bat
@echo off
set str1=1,2,3,4,5
set str2=6,7,8,9
call B.bat %str1% %str2%

B.bat
@echo off
set str1=%1
set str2=%2
set str3=%str1%,%str2%

Expected that B.bat return %str3% (means 1,2,3,4,5,6,7,8,9) back to A.bat file So that A.bat used the result for further processing.
0
I need a batch script for windows that does the following:

Scan *.txt file in the “ARAT_Preverification” folder to find if there are any “Error codes” like 501, 502, 503 - 509 (scenario mentioned below);

Below is the sample .txt file where every 1st row has no data and can be ignored; the following rows has data where the batch should scan and find the error codes (if any) between 18-20 characters only, each row has 90 characters including spaces. The row starts with Letter D in each file except the first row.

H0001200008143800120918155209
D43442371013477773520000001280012091800001
D43442371011722225010000000900012091800001
D43442371007692925040000007200012091800001

If any *.txt file has the above-mentioned error codes then that file should be moved to “ARAT_Verified” Folder.

I got the below code it works sometime if the file is small, if the file size is large (over 1000 rows) it doesn't detect the error code, anything wrong with he code?

@echo off
setlocal enabledelayedexpansion
for %%x in (D:\ARAT\ARAT_Preverification\*.txt) do (
set "file=%%x"
for /f %%i in ('type "!file!"') do set "string=%%i"
    set "str=!string:~17,3!"
    for %%a in (501 502 503 504 505 506 507 508 509) do if "!str!"=="%%a" move "!file!" "D:\ARAT\ARAT_Verified"
)

Open in new window

0
Batch file to ping all network hosts to determinate witch are powered up and store output to a text file

Hello, I need to write a Batch file to ping all network hosts (readed from a hostslist.txt) and write UP/DOWN state to a text file.
0
Hello Experts,

I need a help I've a batch script for folder locking, in this script I've set a password for folder access after that I convert this batch to exe & give it to users.
Now user wants to create own password & after creating the password once user put password for folder access it should not be appear it should be in form in dot or blank.
Most important thing i want set a default password in case users forget password in that case admin should open that folder from default password, also main folder, sub folder & files which is store in Vault folder should not be find if anyone try to find using windows search.

Script:-

cls
@echo off
mode 50, 10
title   ~Safty Vault~

echo.
(SET OUT=3F)

color %OUT%

if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Vault goto MDLOCKER
:CONFIRM
echo Are you sure you want to lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Vault "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
echo Enter password to unlock folder
set/p "pass=>"
if NOT %pass%== password goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Vault
echo Folder Unlocked successfully
0
I wanted to find out if there exists a PDF command line program, that will help to join to different files so that they are side by side.
So let's say 1 file is a manual in English and the other in Spanish.
I wanted to join each page of a 20 page manual, so that the English page 1 is on one side, and the Spanish page 1 is on the other side.
And I want them both to reside in 1 file, as a side by side.
Is there a command line program that I can use that can help me accomplish this?
0
CompTIA Cloud+
LVL 12
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Hi

Running batch file to run long SQL scripts fails to produce results.  I have used the following code as an example of code that works


sqlcmd -S <server> -d <database> -E -Q "set nocount on; set ansi_warnings off;Select * FROM dbo.contact  WHERE CreatedDate >'2018-01-01';"
-o "C:\Users\Documents\MyData.csv" -s"," -w 700

However if I expand the select to more lines, create joins, create a temporary tables then it fails to run.  Anyone know the syntax that must be sues for eacl line and batch file or have a example of a large SQL query inserted into the code above?

The reason I am trying this solution is that I am not allowed to create any stored procedures on the SQL environment and I can run this batch file on the wondows scheduler.

Thanks
0
Chemo has taken a lot from me. I am having problem with a batch file and have gone back to square 1 to test simple things.

@ECHO OFF
IF EXIST %1 GOTO ITEXIST
ECHO %%1 DID NOT EXIST
GOTO EXIT
:ITEXIST
ECHO %%1 DID EXIST
:EXIT
ECHO ON

Why am I getting a syntax error?
1
how to convert dll file into exe by Bat file.
Example abc.dll to abc.exe
abc.dll.config to abc.exe.config
0
I do not have a problem. I need to know where to look to learn the different types of files in script.
0
Good morning. I want to schedule a task for all users of a business I support to auto delete the downloads and desktop folder. This is because of GDPR. I have created and run a .bat file successfully, however the problem with my bat file is that if another user logs on to the computer it doesn't run. The contents of the bat file are as follows:

@echo off
forfiles -p "C:\Users\%username%\Desktop" -s -m *.* /C "cmd /c del @path"
forfiles -p "C:\Users\%username%\Downloads" -s -m *.* /C "cmd /c del @path"

In order for it to work via a scheduled task I have to add in the correct username as follows (fredbloggs is an example)

@echo off
forfiles -p "C:\Users\fredbloggs\Desktop" -s -m *.* /C "cmd /c del @path"
forfiles -p "C:\Users\fredbloggs\Downloads" -s -m *.* /C "cmd /c del @path"

The business can have a high turnover of staff and sometimes other users login. It is connected to an Azure AD (Office 365)

Is there a way round it, or even better a way I can tell Azure to run the .bat for every user?
0
Hello Experts,

I am trying to run as administrator a .bat file on a Windows 10 virtual machine remotely via VirtualBox's command line interface. I am controlling the Windows 10 virtual machine via a Linux headless server.

Currently I am using the command:

vboxmanage guestcontrol "win10clean" exec --image "C:/Temp/run.bat" --username localadmin --password *** --verbose --wait-stdout

Output:

Opening guest session as user 'localadmin' ...
Waiting for guest session to start ...
Guest session (ID 13) has been started
Starting guest process ...
Process 'C:/Temp/run.bat' (PID 4592) started

C:\WINDOWS\system32>REG ADD HKLM\Software\Microsoft\Windows\currentversion\explorer\advanced /v Start_PowerButtonAction /t REG_DWORD /d 2 Process terminated
Exit code=1 (Status=500 [successfully terminated])
Closing guest session ...

The VM name is win10clean
The .bat file is called run.bat and is stored on the VM under the path C:/Temp/
The run.bat file is suppose to update a registry value which is why the command must be run as administrator. However the registry value says the same.
1

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.