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

I would like to position this notification found in this script to show up at specific coordinates on the desktop.

What do I need to change in order to do this?

@echo off
mode 40,6
color 3f
setlocal
set /a Interval = 5
set /a Seconds = 0
:Loop

@echo off
cls
echo ****************************************
echo ****************************************
echo ****      PROCESS RUNNING       ****
echo ****************************************
echo **** Processing DATA.           ****
echo ****************************************
ping localhost -n 2 >nul

cls
0
Search USB Drives. If file is not found on the first one to go to next.


Hi All,

I am trying to use a batch file that is run from local disk C: which looks for a specific file. If file not found on the first one to go to the second one.  It checks the first drive letter but it will not go to the next drive.


echo  Checking For USB
for %%a in (f g) do if exist %%a:\nul (
  set Drive=%%a
  echo  USB or Extended Drive Found
  goto Run
)
echo.
echo  File Not Found, Please USB Stick
pause
goto EndBad
0
I would like to within a .bat file open a .gif file so that it displays for perhaps 5 seconds and then exits.
how can this be incorporated into a .bat script?
0
Hi,

I have a batch script that the final exit is:

:SUCCESS_EXIT
SET JOB_DESC=Notifying users that %JOB_NAME% data load has been completed.
ECHO %DATE% - %TIME% - STARTING - %JOB_DESC% >> %MSTR_LOG_FILE%
call :COMBINE_MAXL_LOG_FILES
set emailsubj=%EMAIL_SUCC_SUBJ%
set emailbody=The script '%JOB_NAME%.bat' to export Lev0 data and application artifacts to '%EXPORT_DATA_DIR%' and '%EXPORT_APP_DIR%' was successful.
set emailbody=%emailbody%  See attached log file for details.
ECHO %DATE% - %TIME% - FINISHED - %JOB_DESC% >> %MSTR_LOG_FILE%
ECHO. >> %MSTR_LOG_FILE%
cscript %UtilFolder%\sendEmail.vbs "%ADMIN_EMAIL_LIST%" "%emailsubj%" "%emailbody%" "%MSTR_LOG_FILE%"
call :RESTART_SVCS
call :BKUP_LOG_FILES
echo Successfully exiting the program
exit 0


However in the Task Scheduler it stays in 'Running' mode.  If I change the last line to 'exit' only, then Task Scheduler properly resets to 'Ready' mode.   I need an exit code of 0 as I'm moving this to Autosys, but want to make sure I don't have anything improper here or I need to revise how I handle exit codes.

Any help and education on exit codes is appreciated as they seem to differ from system to system....
0
I have to add additinal logic to ensure the process is not running:

Current Code that works.  But need to add logic where file ' %TRIGGER_DIR%\%RUNNING%.trig' doesn't exist......

if exist %TRIGGER_DIR%\%JOB_NAME%.trig (
 call :RUNJOB
  ) else (
  call :QUIT
  )
:QUIT
exit 0

:RUNJOB

Open in new window

0
I'm trying to determine whether a file exists in a folder and if so exit my batch file.

What I would like to do is pass the batch file a folder and a filename as separate arguments.

The filename will be something like: MyAccessDatabase.accdb

Then, in the batch file, I need to check to see whether there is a file in the folder passed as the 1st argument with a file extension of .laccdb, so I would be looking for the existence of: MyAccessDatabase.laccdb

If that file exists, I would like to display a message on screen for the user: "The application is already open or closed improperly.  If the application is not running, contact Steve"

Then I want it to exit the batch file.  If that file does not already exist, I want it to continue process the rest of the batch file
0
Experts, we have a batch script that we run on a user's pc to aid in trouble-shooting.  The script echo's out the results to a log file but as we gather more info and put it into the log file, it's becoming a bit lengthy.  If I could put it into an html format, I'd like to be able to jump to different sections by links.  

Any suggestions on how to go about accomplishing this?  Thanks Experts.
0
Hey Experts.  I've got a little in-house script that we use to gather system info on our PC's.  I'm trying to gather the service_name and status of the Windows services on the PC and echo those to a log file.

I've tried:  sc query type= service and sc query type= service | show/find/select service_name, state with no luck.

Need this to be a batch script so please limit suggestions to that coding language.  Thank you in advance.
0
I'm trying to use 7-Zips Uninstall String in Registry to do a batch uninstall, how would i accomplish this task?
0
Explain Windows Batch file

I have windows Batch file below. I need someone to explain what it does it..
if you can comments important lines what they do , that might help.

@echo off
color 17
pushd %~dp0
cls
mode Con: cols=90 lines=80
Title: General Closets
:main
hostname
setlocal enabledelayedexpansion
for /f "delims=[] tokens=1-4" %%a in ('ping -4 -n 1 %computername% ^| findstr [') do ( 
	set RP=%%b
	for /f "delims=. tokens=1-4" %%a in ('echo !RP!') do (

	if %%b==73 (
		goto :MACA
)
	if %%b==64 (
		if %%c leq 75 (
			goto :LMC
	)
)
	if not %%b==64 (
		if not %%b==65 (
			goto :notdefined
	)
)

	if %%b==65 (
		if %%c leq 42 (
			goto :RB
	)
)
	if %%b==64 (
		if %%c geq 192 (
			goto :RS
	)
)
	if %%b==65 (
		if %%c geq 64 (
			if %%c leq 83 (
				goto :RP
		)
	)
) 	
)
)



:LMC
echo This is RG!!!

set Factory=RG
if RG==%Factory% goto :switch
) else (
goto :closet
)

:RB
echo This is RB!!!

set Factory=RB
if RB==%Factory% goto :closet
) else (
goto :switch
)

:RS
echo This is CS!!!

set Factory=CS
if CS==%Factory% goto :closet
) else (
goto :switch
)

:RP
echo This is RP!!!

set Factory=RP
if RP==%Factory% goto :closet
) else (
goto :switch
)

:notdefined

echo This RP is not defined, research and update.

goto :closet

:MACA
echo This is the MACA vlan!!!

set Factory=MACA
if MACA==%Factory% goto :closet
) else (
goto :closet
)

:switch
REM each number refers to the third octed
for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %computername% ^| findstr [') do set 

Open in new window

0
I currently have a Windows command line tool that could change
password with the syntax:
changepw current_password new_password

I need a batch script that'll capture the last 2 digits of the year &
month & then use it as a parameter for both current_password
& new_password so that I can change the password on the 1st
of every month in a Windows Task scheduler ie:

changepw fixedportion@AABB fixedportion@CCDD
where
- AA is the last 2 digits of last month
- BB is the last 2 digits of the year of last month
- CC is the last 2 digits of current month
- BB is the last 2 digits of the year of current month

Eg:
if currently it' s Jan 2020, then
AA = 12
BB = 19
CC = 01
DD = 20

Allow me to set in the script the
'fixedportion'  so that I can it to a
string of my preference

Can't use PS / powershell script in
our place as it's disabled so Batch
script is needed
0
Hi guys,

I wanted to have a batch file that will ping multiple IP addresses just once,  and then will output the results out in a text file.

Are you able to help me with that?

Thanks for looking.
Yash
0
Merge Windows Registry key on remote Computers via a Script

I have a CSV file that has the names of Computer Names.
I need WIndows Batch or Powershell or VB Script  that can Merge the Registry key below with the Registry on each computer on CSV file.

Thank you

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports

Open in new window

0
This is part of a .REG file   ... that gets written via a .BAT file :

[HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Access\Security\Trusted Locations\Location1]
"Path"="C:\\Users\\"
"AllowSubfolders"=dword:00000001
"Description"="RSO Local User System Root"
"Date"="01-08-2020 15:00"

Instead the "Date" being hard coded, I need it to be the System Date/Time

thx
1
Migrate /Backup /Restore a printer from Source Computer to Destination Computer

I would like to have a a printer installed on one computer and the same printer will be installed on other computers. There is no Print Server.

I found this link that talks about that:

https://www.robvanderwoude.com/printtools.php

it also has printer commands on this link:
https://www.robvanderwoude.com/2kprintcontrol.php


Thank you
0
I have a batch script setpwd.bat  that contains only 2 lines:

echo off
net user /domain  my_ADid  Myp@ssw0rd


However, when I ran it, I got an error & this is despite I'm changing my
own password which I have the privilege to change ie when Ctrl-Alt-Del,
& select "Change Password", I could change the password.

What was amissed?  I'm on Win 10 which is
connected to our

C:\tool>setpwd.bat

C:\tool>echo off
The request will be processed at a domain controller for domain abc.com.
System error 5 has occurred.  <==
Access is denied.    <==


I'm using a new complex password (that was never used before) that meet
the GPO requirement.  Command below works though:

net user /domain myADid
(to list out my AD Id's attributes)


I should not need a domain admin to do this, right?
0
https://stackoverflow.com/questions/46451344/convert-batch-script-into-base64-non-readable-format?rq=1
I ran the script in above link (in a cmd window) & it created a red-text window which I used Win Explorer
to drag & drop my script into it: didn't get the converted 'hashed' (non readable) script?

What did I miss
1
Explain Windows Batch Script

I need the following elements of the script below to be explained by an Expert:

"tokens=*"
'dir /b'
%1

Thank you

@echo off
SET count=1
FOR /f "tokens=*" %%G IN ('dir /b') DO (call :subroutine "%%G")
GOTO :eof

:subroutine
 echo %count%:%1
 set /a count+=1
timeout 60
 GOTO :eof

pause

Open in new window

0
If I run getmac /v from the command line, I get the mac address for the Ethernet along with other mac addresses...

C:\>getmac /v

Connection Name Network Adapter Physical Address    Transport Name
=============== =============== =================== ==========================================================
VMware Network  VMware Virtual  00-00-56-C0-00-01   \Device\Tcpip_{CB83EEF5-9348-4BA4-8B8A-2325F3DBBABB}
VMware Network  VMware Virtual  00-00-56-C0-00-08   \Device\Tcpip_{70DC019A-AD7F-4CEA-AD6D-0FC1C9404A4F}
Ethernet        Intel(R) Ethern 98-00-96-C6-44-D5   \Device\Tcpip_{3820E95C-BC3B-485B-A07D-ADA3EF9E650E}

How can I have it just return the mac address of the ethernet connection?  Is there a way it can be done in a batch file to only output the ethernet mac address?
0
I've scheduled a task that run's a BAT file from a UNC path.

Path = \\wisdomserver\deployment\deployment.bat

Right now this is what the BAT file is:

Echo is this running?
pause

Open in new window


The trigger in Task Scheduler is "at log on of any user."  And when a user logs onto the machine, it seems to run, but generates a result of 0x1.  I think it's failing to run as it never stops at the pause.

If I right-click on the task and run, it does exactly what it's supposed to do.

I do see something flicker on the screen when I log in, but I don't see anything in the history.  The history tab actually says "disabled."

My Google Foo is not working tonight and I'm not sure how to move forward.  If the task is successfully running, why isn't it stopping at the "pause?"

I suppose I could write a simple copy file routine and test things that way, but I'm sick and out of time for today, so I thought I'd see what you all have to suggest here.

Please advise!
0
Run Install.exe for remote Computers using Powershell

I have HP Drivers folder in the Network , inside the HP Drivers folder there is a file called Install.exe.
I would like to have a script reads computer names from csv file and run the Install.exe silently on each computer listed on CSV file.
The Install.exe will install printer , I would like it to pick up the "HP Universal Printing PCL 6" as driver.

Any Help will be very much appreciated.

Thank you
0
Script to Manage Wireless Networks

I have a list of computers on a CSV file. example:

ComputerName,UserName
CompA, User1
Comp2,User35
Comp3, User62
etc....

Open in new window


for now each technician will go to each computer:

-open Network and Sharing Center
-Click on Manager Wireless Networks
-Right-Click on  one of the Wireless Networks icon , for instance called: CompWireless  and click on its properties to open  properties window
-Click on Security tab , then click on Advanced, then click on Save Credentials
- in the popup window type in DomainName\username  and password then click OK ,OK, OK on all those windows to close them

I thought if this can be done through script that might save a lot of hassle.

Note: the password is the same for all user accounts on the csv file.

Any help will be very much appreciated.

Thank you
0
add work group computers to  DNS (A and PTR Records)

I have computers in work group. I want their hostnames to be add to DNS Forward and Reverse lookup zones( A & PTR Records)


Thank you
0
Vmware View Command line
I have this Vmware  view command line that I want an expert to explain  its function.

Thank you
vmware-view.exe -serverURL VM.DomainName -username Myuseraccount -domainname Mydomainname -password  Mypassword  -ConnectUSBOnStartup true -ConnectUSBOnInsert true -unattended

logoff

Open in new window

0
Which INF file is used by "HP Universal Printing PCL 6"

I would like to know which INF file is used by "HP Universal Printing PCL 6".
When I go to any remote computer and install a printer using the Wizard and select "HP Universal Printing PCL 6", it will install and after install if  I right-click the printer and select properties, it will open up the properties without any issue.

if I remotely install the printer using the script below, it will install the printer, and  after install if  I right-click the printer and select properties, it will first throw an error message shown on the screenshot below then  open up the properties window, when I send test print job, it will not print.

for /f %%a in (C:\Scripts\CalledScripts\CompOnly.CSV) do (


@echo Creating Printer Port on %%a
 cscript.exe "C:\windows\system32\Printing_Admin_Scripts\en-US\prnport.vbs" -u administrator -w "Bouandas1!" -a  -s %%a -r "Printerhostname" -h hostname -o raw -n 9100





\cscript.exe "C:\windows\system32\Printing_Admin_Scripts\en-US\Prndrvr.vbs" -u administrator -w "Bouandas1!" -l -v 3 -e “Windows x64” -m "HP Universal Printing PCL 6"  -h hostname -s %%a



@echo Setting Printer on %%a
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -u administrator -w "Bouandas1!" -d -a -p "Printer Queue Name" -m "HP Universal Printing PCL 6" -r "Printerhostname" -s %%a

)

Open in new window



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