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

Want to remove the %JAVA_HOME%/bin; from Path  variable using cmd.
Is there any way to do this through cmd?
0
Become a Certified Penetration Testing Engineer
LVL 12
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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
We need to place a .rdp shortcut in the desktop folder of all our user's roaming profile. Looking for a script to quickly accomplish this. The user's roaming profile directory names are in this format: "username.contoso.V6", within this directory is a "desktop" directory which is where we'd like to copy the shortcut.


source: c:\folder\rdpshortcut.rdp
destination: \\gsf1\rds\username.contoso.V6\desktop
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 have two variables A and B, having values in a comma separated format. I am trying to find out the result, which is present in A, but not in B using a batch file.
@echo off
set A=1,2,3,4
set B=3,4,5,6

expected result: 1,2
0
I have a batch file. Here I assigned some values to a variable. Want to remove duplicate values from the variable.

@echo off
set test=1,2,4,1,5,6,2,3


expected output: 1,2,3,4,5,6
0
I would like to use the pushd command in a batch file to specific to run the command from the folder that it is in.. and to stay there..
I don't want to specify a path, however I just want it to run in the specific folder I am in..
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.

This code isn't pushing the log files out for me, I'd like to to confirm if it's been successful or not in the file and it's not working. :(

@echo off
setlocal enabledelayedexpansion

set GUIDs=DDF96E66-E39B-4A69-B776-2DE49EBCAFBD D7D3F00A-638B-41DE-A2A3-FFC6EF034783 B1A6CB20-C032-4228-940F-AC3BC9BF6B3E 3EB41C0B-00EF-4C8B-9FF7-FF252E2F4E33 D8A08493-2F06-4EB2-A636-4392991981AB 
for %%a in (%GUIDs%) do (
     reg.exe query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{%%a}" >NUL 2>&1
      if not errorlevel 1 (
            echo Uninstalling %%a
            start "Uninstalling %%a" /wait msiexec.exe /X{%%a} /quiet
      )
)

:::8x8 VOD Latest Version Installation
::: Copy the latest version of the VOD to the path below and change the msi filename
start "Installing VOD" /wait msiexec.exe /i \\Domain.com\SYSVOL\domain.com\scripts\8x8\VOD_5_6_0.msi /qn
if not errlorlevel 1 echo %date% %time% %Computername% - Installation succeeded >> "\\fileserver\company Common\logs\InstallVOD.log"

::: Please wait for the time to finish

timeout 15

:::Reboot machine

shutdown /r /t 60

Open in new window


Any ideas?
0
Hi ,

i have working script..
i want to put additional checks in the script to check for files and proceed further.
it should check for files after it checks for source folder.
if all three files available then proceed further to run remaining lines of checking backupfolder.
if even one file is missing or all missing it should write log the missing files and exit

Files names to check-
cat.xml
rat.xml
bat.xml

$logdate=Get-Date -Format ddMMMyyyy_HHmmss
$Logfile = "E:\Logs\FileProcessing_$logdate.txt"

function LogWrite ([string]$logstring)
{  
   Add-content $Logfile -value $logstring
}

#Zip Files
$sourcefolder="E:\INT\PUT"
$backupFolder="E:\INT\Archive"

#check if source exists
if(!(Test-Path $sourcefolder)){
    $msj="The source folder ""$($sourcefolder)"" doesn't exists. Exiting..."
    LogWrite "$( Get-Date -Format "yyyy-MM-dd HH:mm:ss" ) ERROR:`t$msj"
    LogWrite -ForegroundColor Red $msj
    exit -1
}

#check the target folder or create it
if(!(Test-Path $backupFolder)){
    $msj="The target folder ""$($backupFolder)"" was created"
    LogWrite "$( Get-Date -Format "yyyy-MM-dd HH:mm:ss" ) EXECUTE:`t$msj"
    LogWrite -ForegroundColor Magenta $msj
    New-Item -ItemType Directory -Path $backupFolder | Out-Null
}
foreach($file in (Get-ChildItem -File $sourcefolder -Filter "*.xml" -Recurse)){
    $date = Get-date -Format "ddMMyyyy_HHmmss"
    $destinationFile = "$($FILE.Directory.FullName)\$($file.Name).zip"
    $MoveFile = …
0
I would like to change this script, so that instead of hard coding in the destination email addresses, it will look into a flat txt file and use the email addresses listed in that specific file instead.


###SETUP START###
#-------DO NOT MODIFY-------#
    #Yesterdays Date
        $date = ((Get-Date).AddDays(-2)).ToString("MMM/dd/yyyy")
###SETUP END###

###USER VARIABLES START###
#-------MODIFY AS NEEDED-------#
    #Mail Subject
        $Subject = "Report: "+$date+" REVISED "
    #Body of Email
        $MessageBody = "REVISED - Report for $date. Thank you."
###USER VARIABLES END###

###PROGRAM START###
      # Invokes the Send-MailMessage function to send notification email
Send-MailMessage -From 'email1@mail.com' -To 'email2@mail.com', 'email3@mail.com', 'email4@mail.com' `
  -SmtpServer 'smtp.mail.com' `
  -Subject  $subject `
  -body $MessageBody `
  -BodyAsHtml `
  -Attachment 'C:\Attachment\Attachment.pdf'
 ###PROGRAM END###

Thanks in advance for your assistance
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
How do I get this to report if it was successful on the installation?

@echo off
setlocal enabledelayedexpansion

set GUIDs=DDF96E66-E39B-4A69-B776-2DE49EBCAFBD D7D3F00A-638B-41DE-A2A3-FFC6EF034783 B1A6CB20-C032-4228-940F-AC3BC9BF6B3E 3EB41C0B-00EF-4C8B-9FF7-FF252E2F4E33 D8A08493-2F06-4EB2-A636-4392991981AB 
for %%a in (%GUIDs%) do (
     reg.exe query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{%%a}" >NUL 2>&1
      if not errorlevel 1 (
            echo Uninstalling %%a
            start "Uninstalling %%a" /wait msiexec.exe /X{%%a} /quiet
      )
)

:::8x8 VOD Latest Version Installation
::: Copy the latest version of the VOD to the path below and change the msi filename
start "Installing VOD" /wait msiexec.exe /i \\Domain.com\SYSVOL\Domain.com\scripts\8x8\VOD_5_6_0.msi /qn
::: Please wait for the time to finish

timeout 5

taskkill /im "8x8 - Virtual Office.exe"

:::Launching 8x8
Timeout 5

"C:\Program Files (x86)\8x8 Virtual Office\8x8 - Virtual Office\8x8 - Virtual Office.exe"

Open in new window


I'm thinking something like this

I mean is it easy or?

Thanks
Alex
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
Hi,

Please advise on how to fix below;

Trying to run;
SET AppExec1=start /wait "%~dp01_Completed\EXE\Source\setup.exe" -r "%~dp01_Completed\EXE\Source\Install.ini"

getting error


Thank you in advance
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
Angular Fundamentals
LVL 12
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

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
I have one folder "destination" where I have files and their time stamps (created, modified) I would like to preserve when I overwrite a few of those files with updated version of those files.

example

Destination Folder 
File.mp4- Created 01/01/01 (size 500mb)

Source Folder 
File.nmp4 - Created 12/12/12 (size 4.00gb)

Open in new window

I overwrite the file in the Destination folder with the new updated version from the Source Folder but keeping the original file in the destination folder timestamps

End Result (new overwrite file in the destination folder with original file timestamps)

Destination Folder
File.mp4 - Created 01/01/01 (size 4.00gb)

Open in new window


I have written a batch file to move the file as so

 
robocopy "Source" "Destination" /E

Open in new window


and this handles my overwrites and moving of my files perfectly, but I haven't found a way to preserves timestamps. I am looking for command-line so I can implement it in a batch file. Any help will be appreciated. I been reading flags for robocopy etc but maybe I'm reading it wrong or something but I haven't figured it out yet.
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
Hello,

How do you create an executable file to open a non-executable file?

I just began using a Corsair K95 RGB keyboard (which includes 18 programmable G-keys) along with its software (CorsairUtilityEngineSetup_2.24.50_release). While assigning macros to the G-keys, I discovered that while the software does allow you to run an executable file (*.exe *.bat *.cmd), there is no option to open a simple non-executable file (eg .txt, .xls, .ahk, .png, etc).

That seemed a bit odd to me but it was confirmed by Corsair tech support so during the conversation I asked about possible workarounds and the response was that I could create an .exe or .cmd file to open the desired non-executable file.

So for example, suppose you want to open the following Excel file:

    C:\Users\UserName\FolderName\FileName.xlsm

How would you create an .exe or .cmd file to do that?

Thanks
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.