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 am using 7-Zip to automatically backup a database directory from a batch file.

The command is something like:
C:\Program Files\7-Zip\7z.exe a "C:\MyDataFolder"

Open in new window

What switch can I add to automatically skip any files that may being modified at that time ?

I have searched and searched the net and can find no switch to do this !
0
The 14th Annual Expert Award Winners
LVL 7
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Hello Experts,

Using this batch how to print %sum1% in words along with numbers

@echo off
:Loop
echo Enter a number:
set /p num1=  
set /a sum1="num1 * 100000"
echo The total is %sum1%
goto :Loop
0
I need a batch (ie .bat or .cmd) logon script that will check if the hostname is one of the 20
& if so, then only execute a series of commands on the PC.  The pseudo code will be like:

if %computername%="host1"  or ... or %computername%="host20"
then
   (
    command 1
    command 2
   )

Basically I need to get the syntax right
0
I would like to use AD logon script to set persistent routes on selected PCs in our domain:
  ... some checks on the selected PCs (ie those with hostnames starting with ABC...) ..., then only execute commands below
  route del 0.0.0.0 mask 0.0.0.0  current_gateway
  route add -P 10.6.7.0 mask 255.255.255.0  new_gateway

Can it be done?

Understand the above command requires admin privilege & a colleague told me it will fail as domain
/AD users don't have admin rights.    To put it into GPO is too complex, so we want to put into user
logon scripts
0
Hello,

done a search and haven't found anything exactly like what I'd like to do.

We have a single domain with users in multiple locations. Each main location has its own file server and users map their home drive based on their location. We've had issues with home drives not mapping in remote locations that do not have a local server. We believe it may be timing out, that issue is being looked into.

Rather than have our IT staff manually map the drives, I'd like to do a small script we could place on their desktop that allows users to put their primary location, which would then map their home drive to the correct server.  Something like this.

Please select your primary location:
0 = HQ
1= Region 1
2= Region 2
3 = Region 3
4 = Region 4

Based on their answer I assume it would then run a command

HQ
Net Use K:\\hqserver\vol\%username%

Reg 1
Net Use K:\\r1server\vol\%username%

Reg 2
Net Use K:\\r2server\vol\%username%

Reg 3
Net Use K:\\r3server\vol\%username%

Reg 4
Net Use K:\\r4server\vol\%username%

I've tried writing a few, but scripting is definitely not a strong suit. I'm sure it would take a talented scripter about 2 minutes.

TIA
0
I created a script that collects information on computers in our environment.  It's very basic, and uses commands like "Systeminfo", "Ipconfig", "Set User", and even queries the registry to find any ODBC connections on systems.  Then, I have all of the information export to a text file that is saved on a network share that I created.  Here is the actual script I am using (I hid the actual name of our server in the initial "SET LOG" section:

@echo off
SET LOG="\\SERVERNAME\testshare\joe\reports\%computername%.txt"

echo Report Date: %date% > %LOG%
echo. >> %LOG%
echo ------------------ >> %LOG%
echo System Information >> %LOG%
echo ------------------ >> %LOG%
systeminfo | findstr /C:"Host Name" /C:"OS Name" /C:"OS Version" /C:"System Manufacturer" /C:"System Model" >> %LOG%
echo. >> %LOG%

echo ---------------- >> %LOG%
echo User Information >> %LOG%
echo ---------------- >> %LOG%
set user | findstr /C:"USERNAME" /C:"USERDOMAIN=" >> %LOG%
echo. >> %LOG%

echo ------------------- >> %LOG%
echo Network Information >> %LOG%
echo ------------------- >> %LOG%
ipconfig | findstr /C:"IP" /C:"Subnet Mask" /C:"Default Gateway" >> %LOG%
echo. >> %LOG%

echo ------------- >> %LOG%
echo Mapped Drives >> %LOG%
echo ------------- >> %LOG%
net use | findstr /C:":" /C:"\\" >> %LOG%
echo. >> %LOG%

echo ---------------- >> %LOG%
echo ODBC Information >> %LOG%
echo ---------------- >> %LOG%
echo System DSN(s): >> %LOG%
reg query …
0
Running a batch file from excel

The code in excel is:

set arg1 %1

if [%1] equ [] set arg1=%cd:~0,1%

echo "Test" %arg1%

echo %arg1%:\ZZZ\ZIP-BAT\source-zip.txt

dir e:\ZZZ\Zip-Bak\DayBkup\hm18*.zip>%arg1%:\ZZZ\ZIP-BAT\source-zip.txt

dir %arg1%:\ZZZ\Zip-Bak\DayBkup\hm*.zip>%arg1%:\ZZZ\ZIP-BAT\dest-zip.txt

The Dos batch file content is

set arg1 %1

if [%1] equ [] set arg1=%cd:~0,1%

echo "Test" %arg1%

echo %arg1%:\ZZZ\ZIP-BAT\source-zip.txt

dir e:\ZZZ\Zip-Bak\DayBkup\hm18*.zip>%arg1%:\ZZZ\ZIP-BAT\source-zip.txt

dir %arg1%:\ZZZ\Zip-Bak\DayBkup\hm*.zip>%arg1%:\ZZZ\ZIP-BAT\dest-zip.txt


I get an error Environment variable not defined (see attached screen shot)

Need help

Thanks
Dos-Batch.JPG
0
I need to connect to FTP server through Command Prompt.

When I am trying to connect to it, it says Connection Timed Out.

D:\>ftp
ftp> open
To xyz.test.com
ftp: connect :Connection timed out
ftp>

What must be the reason behind it? Please help

I can connect to it through Filezilla.
0
I created the following script to create a fake reg key, if the key isn't present - install software. If the key is there, fall out and end the execution.

The script works just fine. My challenge is when it executes, i get the dialog box pop up - which i do NOT want to be displayed.

Again, the script works fine - but how can i edit the script so i DO NOT receive the notification dialog box as shown in the attachment? (prefer to leave it as a .cmd script if possible). Thanks!

@echo off
rem queries if fake regkey is present
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\DotNetCheck"
if %errorlevel%==1 (goto Install) else (goto End)
REM If errorlevel returns value 1, key is not present and prgm will create key and install .net3.5

:Install
REG ADD HKLM\SOFTWARE\DotNetCheck
dism /online /quiet /enable-feature /featurename:NetFx3 /All /Source:\\ds-dfs01\sxs /LimitAccess

:End
DialogBoxWishToGoAway.png
0
Hello Experts ,
is there a batch or VB script to copy a specified DLL from a local machine to a remote machine and register it with psexec ?
if the remote machine name could be given by the user who will run the script will be great ( strinput )
also if the script can be ran without the need to enter credentials , the user who will run the script have enough access .
very appricated .
0
Cloud Class® Course: Python 3 Fundamentals
LVL 12
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

How do I convert this batch file into a exe or powershell script.
0
I have a test_file.txt

------------------------------------------test_file.txt------------------------------------------------
3
ID | Name | Gender
x1 | A | M
x2 | B | F
x3 | C | M
------------------------------------------------------------------------------------------


3 is our record count.

I need to write a batch script where I have to store the record count value in one variable(X), need to store the data values ( 3 row) in to another variable (Y)
and have to compare both the variables if X == Y then execute a SQL job (ABC) and if they are not equal fail the script raising an ERROR.

Please help folks as I think this is the only forum which can help me solving my problem.
0
Usage will be a daily task to copy only new or modified files into a new folder name with current date.
robocopy \\Srv1\Data\John \\Srv2\Bkup\John\20180507 /maxage:1 /s
0
Try to use the following command to backup a folder. However, it always stay in the attached screen. Any idea ?


robocopy.exe Z:\" D:\ARCH17 /copyall /E /Z /NP /nfl /ndl /r:0 /tee /MIR /XD "@Recycle" "@Recently-Snapshot" /xf "Thumbs.db"  /Log+:C:\MyBackup\robocopy.log

Thx
screen.png
0
We have some upgraded going on some of our web severs.
Till that time we need check many urls manually daily.

I want to write a vb script to check urls if it is up or not and send us status report through mail.

urls address start with https:// and we need to use F5 Token and disable proxy setting to connect those server.

we don't have power shell access as well.

could somebody please help me to write a vbscript or bat script to automate these stuff.
0
Split 1 text file into multiple textfiles based on Row starts with CC and rename the files into different file name.

Rows AA, BB are headers need to be added to the file after the split. Split based on Row CC.

I don't know what is the best way to do this. I am lost.

Is this possible?

See attached:
Original File to be split: Test_05022018.txt

Results should be like this: See attachement.
Test000000001_05022018.txt
Test000000002_05022018.txt
Test000000003_05022018.txt

See attache excel file for more info.


Please help.

Thank you again.
Split_To_Multiple_Texts.xlsx
Test000000001_05022018.txt
Test000000002_05022018.txt
Test0000000003_05022018.txt
0
Evening Experts,

I am trying to find a solution either using VBA in excel or another kind of process.

I want to be able to check folders in a directory to see if any files exist in them. If files are found in a folder, I would like to create a txt file with the name of the folder and the name of the files inside that folder. In a separate text a list of empty files.

If I was going down the excel approach, I would like the same as above but I would like to include an hyperlink of the files in the folder so that I can can open them direct.

Thanks for your help
0
I'm trying to use a batch file run via GPO to open a powershell script at login that will display a splash image.  Script code is here:



# .Net methods for hiding/showing the console in the background
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();

[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
function Hide-Console
{
    $consolePtr = [Console.Window]::GetConsoleWindow()
    #0 hide
    [Console.Window]::ShowWindow($consolePtr, 0)
}
Hide-Console

# Loosely based on http://www.vistax64.com/powershell/202216-display-image-powershell.html

[void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")

$file = (get-item 'C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg')
#$file = (get-item "c:\image.jpg")

$img = [System.Drawing.Image]::Fromfile($file);

# This tip from http://stackoverflow.com/questions/3358372/windows-forms-look-different-in-powershell-and-powershell-ise-why/3359274#3359274
[System.Windows.Forms.Application]::EnableVisualStyles();
$form = new-object Windows.Forms.Form
$form.Text = "I'm obv not a programmer"
$form.Width = $img.Size.Width;
$form.Height =  $img.Size.Height;
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Width =  $img.Size.Width;
$pictureBox.Height =  $img.Size.Height;

$pictureBox.Image = $img;
$form.controls.add($pictureBox)
0
I want a batch script to change the IP address of the NIC.
I need to be able to run it on multiple laptops, and they all seem the have seperate NIC Names.
How can I get it to use the wired NIC / or give the user a choice of ethernet NIC?
1
Cloud Class® Course: Amazon Web Services - Basic
LVL 12
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

@echo off
setlocal

(
    echo SET DEFINE OFF;
    echo.

    for %%A in ("*sql") do (
	IF %%A~="fileslist.sql"(
	REM do nothing
	)
	ELSEIF %%A~="MAIN.sql"(
	REM do nothing
	)
	ELSE(
	echo @@%%~A
	)
	)

    echo.
    echo COMMIT;
    echo.
    echo EXIT

)>result.sql

Open in new window


Hi, Experts,

I am trying to write into "results.sql" a list of *.sql within the folder and with some text before and after the list. Which was already done.
But now i have a problem of excluding 2 .sql files within the foler, namely "fileslist.sql" and "MAIN.sql".
After i added the if elseif statement. The batch file didn't work.
Any advise if my syntax or logic is wrong?
0
I would like to delete the contents of a text every day;  instead of deleting the actual file.

What is the best way to do this?
0
Hello
I have a batchfile with below command, which works good.

msiexec /L c:\setup.log /qn /i %SCRIPTDIR%\setup.msi transforms=\\server\share\%computername%.mst

We are changing the pattern now
we have now \\server\share\parameters.txt
the text file contains the parameters like below
101 param1 param2
102 param3 param4

So if I am running on PC named "ABS101" the batchfile should check the text file and matches 101 and run the setup with parameters next to 101.

is that possible?
0
I’m looking for a bat file to open outlook for a period of 20 minutes and after this time has passed to terminate outlook process.
0
I need to create a batch file that backs up a file then deletes the original file so that I can download a file with the same name.

As follows:

del myfileBackup.csv
copy myfile.csv myfileBackup.csv
del myfile.csv
...
myapplication --username --password --formID  --output myfile.csv

The problem I am running into is when a file is deleted/renamed it ties up that file and prevents the next step.

I get an error message

The process cannot access the file because it is being used by another process.

This caused my import/download to fail.

I appreciate any help that can be provided.

Thanks!

Michael
0
I have mapped drives to the NAS.

Sometimes the shortcuts disappear, I've created a batch file the re-maps the drives but don't re-create the shortcuts.

What is the command to create shortcuts?
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.