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

This is my command line:
@echo off
FOR %%f IN (P*) DO type %%f >> combiness.txt & echo. >> combiness.txt

To put all files starting with P in a combiness.txt file, it worked on my old computer but i recently got a new one and its not working like I had hoped.
0
I have a user who puts the date he wants me to change the to reflect the update in the file name.

Example:  BMS Update 7.21.2017.xlsx

Is there a way to capture this Date in the file name so I can use it in my batch routine?  Maybe like store it in a set variable so I can use it in my batch file.       Set FileDate=FileDate

I cant use file modify date because the modify date and the date in the file name are different.
0
Hi Experts,

I have this script tested and works as expected.  script checks the disks attached to server and checks the  drive label  of the disks and create a .txt file with the drive letter name ( such as "D drive.txt")  scripts is copied to  each server already and locally run.

For an example, if four disk found as D, E,Y,S on a local server, after running the script,  when I  go into each disk, I should have a .txt file saved in there as D drive.txt, E drive.txt , Y drive.txt and S drive.txt

batch script will be used on  mixture Windows OS versions. ( 2003 to 2012)

Issue: it works fine when script is run locally but when needed to run using PSexec, it produces different issues  even though script is on the local server and all PSexec should do is executing the script with remotely instead of logging into the each server. I have read on forums that vmic is not very friendly with PSExec, is there way to eliminate wmic from the script? here is forum talks about the issues it causes:  https://forum.sysinternals.com/psexec-hangs-when-running-wmicexe_topic14752.html

markerfile.txt
0
hello

I want to reboot my client computer.
I want to give him time like 1 hour
but I want him to have a option he can restart before 1 hr whenever he wants.
0
I have created a Powershell Script and a Batch file.  I have placed the batch file in the startup directory of the machine.  It appears to run as I see the command prompt window on the screen with the message "Press any Key to continue".  If I press any key the command prompt goes away and the app I want removed (XBox) is still on the Tiles Page and works.   If I double click the script once logged in as any user it runs ... presents the same cmd prompt window with press any key to continue ... and removes the app.

I am hoping to fix two issues:

1) Remove the need to press any key to continue.  I want it to be invisible to the end users.

2) Get the script to delete the XBox app without having to wait until logged in and then manually clicking the batch file.

BATCH FILE:
@ECHO OFF
PowerShell.exe -ExecutionPolicy Bypass -Command "C:\scripts\RemoveW10Apps.ps1"
PAUSE

PS Script:
Get-AppxPackage Microsoft.XboxApp | Remove-AppxPackage

0
This is about the Acronis Backup & Recovery 11. We found that one of the service - Acronis Managed Machine service (mms) sometimes shows "stopping" while kicks start the scheduled backup job. When this service in this state, the only way we can do is to system reboot the server so as the service will be back to normal started state. We did use process explorer to "kill" the mms, however, we still can't manually start the backup job.

Out of no way, we are using the task scheduler to schedule to stop and start 5 Acronis services. Basically are those net stop/net start commands with 30 seconds interval as attached. The sequences are, net stop all the services in this orderly - Acronis Managed Machine service > Acronis Remote Agent > Acronis removable storage management > Acronis Scheduler2 > Acronis VSS Provider; and then net start same services in reverse order.

However, still, the Acronis Managed Machine service shows "stopping" upon the schedule restart. Is there a way that stop this service forcibly? As long as this service is stop, and then re-start shouldn't be a problem.

Thanks,
RestartAcronisServices.JPG
0
Every month I have to go through several text files after paying bills online to send to the CFO to show all the bills that have been paid. I have tried to get him to accept a print of confirmation page but instead he wants it in the format of file 2 below (ee-online-pmts-result.txt). So I copy the results from the web page, past it to a text file and then clean it up removing all the "junk" not needed. As such is there a way I can read the first text file (ee-online-pmts.txt) and then have a list of variables to parse that if found would be removed in such a way that the result will be what the 2nd text file looks like? For instance if  "Print this activity" and two carriage returns (enter, enter) are found it will remove it? Thanks!
ee-online-pmts.txt
ee-online-pmts-result.txt
0
Hello folks,
I need to create a shortcut by using a script batch or PS1 or vbs, I have found this for now but it will not give me a ie
icon

does anybody has a better solution ?
0
Hello,

I'm changing the DNS Servers on our Environment to new IPs. i found a batch script which worked perfectly on the Servers that have one connection only but for the servers that have two it didn't worked as it some time change the DNS for the correct one and some time no.

how i can modify it to change the DNS for the network interface that have the old IPs or that Connected to the Domain.

below is the script & I want it as batch to deploy it by SCCM

@echo off
set dnsserver=10.10.1.3
set dnsserver2=10.10.1.4

for /f "tokens=1,2,3*" %%i in ('netsh interface show interface') do (
if %%i EQU Enabled (
rem echo change "%%l" : %dnsserver%
netsh interface ipv4 set dnsserver name="%%l" static %dnsserver% both
netsh interface ipv4 add dnsserver name="%%l" %dnsserver2% index=2

Exit
)
)

0
Folks,
I have created the following batch script
For /f %%a in (Clients.txt) do (
psexec \\%%a cmd /c reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v version>>report2.csv
IF %ERRORLEVEL% EQU 0 @echo %%a>>report.csv
)


However my report shows, version information on top and then PC name at the bottom a bit messy ... what do you guys think i should change in order to make the result, two columns one for PC NAME and next column VERSION. or any better suggestions? [including powershell ]?

Thanks for looking
0
Hello,

I am wondering if there is a way to automate (through script) the steps on this article?
0
I'm trying to automate the post-installation actions for a Windows update patch, but running into trouble when it comes to elevating privileges.

Ideally what I want to do, is use a batch file to run an elevated command, then call a PS script to run a separate elevated command, with a minimum of user input.

Is this possible, and if so, what is the best way to implement it?
0
I need to write a batch file to substitute tab with white space
0
I don't know whether this is possible or not but here goes ...

I have a Windows 10 Home laptop and and various Windows 10 Pro boxen.  I'd like to share files between them without using USB sticks or using the HomeGroup feature of Windows.  (I do want the Windows 10 boxen to talk to my [new and upgraded] Linux Samba box but that is a future project).

I've got sharing (over Ethernet) working between the Laptop and one Pro box and I presume I can disable it through the GUI.  I'm only sharing one folder that of Documents on both machines.  BUT I would like an easy way to disable and enable it, hopefully through the use of CLI commands and a batch file.  Is this possible and if so how?
0
My code is posted below.  There 3 IF  ELSE statements to check all possible conditions.  I don't understand all the More? being inserted; or the ) was unexpected at this time.  This is the last hold up I can't correct.

BD

@echo off
rem setlocal EnableExtensions EnableDelayedExpansion
set SrcFolder=E:\SweepstakesNinja\sweepstakesninja\sweepstakesfiles
set DstFolder=E:\SweepstakesNinja\sweepstakesninja\sweepstakesfilesCustomSubmissions
for %a in ("%SrcFolder%\*.txt") do (
More?   (for /f "usebackq delims=" %h in ("%a") do (
More? echo.%h
More? (
More?  if "%h" equ "[**]details==>>countries||==||" (echo [**]details==>>mainsweepstakessubmissiontype^||==^||3)
More?  else if "%h" equ "[**]details==>>countries||==||USA" (echo [**]details==>>mainsweepstakessubmissiontype^||==^||3)
More?  else if "%h" equ "[**]details==>>countries||==||USA, Canada" (echo [**]details==>>mainsweepstakessubmissiontype^||==^||3)
More? )
More? ))>"%DstFolder%\%~nxa"
) was unexpected at this time.
)

echo DONE
0
Hi, please can someone assist with this batch file.

I am trying to get the CMD window to close after the batch file has run, please can someone advise where I am going wrong.

SET year=%DATE:~-4%

SET month=%DATE:~-10,-8%
set month=%month: =0%

SET day=%DATE:~-7,-5%
set day=%day: =0%

SET hour=%time:~0,2%
set hour=%hour: =0%

SET minute=%time:~3,2%
set minute=%minute: =0%

SET second=%time:~6,2%
set second=%second: =0%

SET datetimeStamp=%year%%month%%day%-%hour%%minute%%second%

SET CMD="D:\Program Files\SunGard\Apex\bin\Windows 64-bit\Apex.exe" -logMessages -showMessages -verbose -logFileName %userprofile%\AppData\Local\SunGard\Apex\Logs\SunGardApex-%CIBC_ENV%-%COMPUTERNAME%-%USERNAME%-%datetimeStamp%.log

SET START_PATH="D:\Program Files\SunGard\Apex\bin\Windows 64-bit"

IF NOT EXIST %userprofile%\AppData\Local\SunGard\Apex\Logs MKDIR %userprofile%\AppData\Local\SunGard\Apex\Logs

ECHO CD %START_PATH%
ECHO %CMD%

D:
CD %START_PATH%
%CMD%

EXIT /B 0

0
Hi all...

I've tried finding what I need but most solutions offer various entries and switches on a vbs script or batch file.

I need to delete one single registry key if it is present. The key is as an example:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Application Plugins\DATALOSS1000

How can I accomplish this, and run it remotely on approximately 300 systems?

Batch file preferred...

0
I need to copy files from the source to destination and only copy the files with the current date :  I can create copy etc, but it is grabbing all the files not just the current date.  I don't know what I am missing.

@ECHO Collect Todays WSA Logs.......

Pause

For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set currentDate=%%a-%%b-%%c)

For /f "tokens=1-3 delims=/: " %%a in ('time /t') do (set currentTime=%%a%%b%%c)

echo %currentDate%-%currentTime%
set todaysLogs=%currentDate%--%currentTime%

mkdir d:\Logs\%todaysLogs%\WSA

REM WSA
xcopy /i /e "\\SOURCE\c\$\WINDOWS\temp\*.TMP" "D:\Logs\%todaysLogs%\WSA" %date:~4,2%-%date:~7,2%-

%date:~4%
0
batch script help with exit when finds a specific error( e.g:
TIMEOUT error

) ,exit means close the process
0
Hello All, I have this .bat for change expiration date of users in a .csv file, but I decide which date I want to put.

Now, How can I change that the date will to NEVER?

[b]@echo off
setlocal

:: *** csv-File with the name, first name, and user name:
set UserFile=\\Srv_\publico\DATOS\Procedimiento\Procedimientos\prorrogarUsuario\prorroga.csv

:: *** Distinguished Name of the container to add the new user to:
set UsersDN=OU=Usuarios,OU=UsuariosCM,OU=CM,DC=D,DC=domain,DC=com

for /f "tokens=1-4 delims=," %%a in ('type "%UserFile%"') do (
set Userp=%%a
set Date=%%b
call :process
)
goto :leave

:process
set USER=%Userp%

echo Prorrogando usuario

echo.
:: ***echo Hit ^<ctrl-c^> to stop, any other key to create the user.
:: ***pause >NUL
echo.

:: *** Test mode: Remove the "ECHO" in front of the following line to run the script for real:
net user %USER% /expires:%Date% /DOMAIN

:leave[/b]


Can u help me?
0
How do I check this. Have already written a command in SQL SERVER JOB [Test_Job] and executing the job in Sql Server, **Have disable the Informatica service through Informatica Admin panel**, when I execute this job I don't know why It is still running successfully and cannot generate a failure mail.

This is the command which I have put in a job.

DECLARE @result int
EXEC @result = xp_cmdshell "D:\Informatica\Informatica_961_HotFix2_Installation\server\bin\infacmd ping -dg HERHRETEST:1000"
IF (@result <> 0)
RAISERROR (50001, -1, -1)

0
When ping is negative Stop Xsoft.exe with this command :
 NET STOP "Xsoft (managed by AlwaysUpService)"

Wait 1 min. and try again,if ping is positive then start Xsoft.exe with this command: :
 NET START "Xsoft (managed by AlwaysUpService)"


C:\Users\User2>ping xxx.xxx.xx.200

Pinging xxx.xxx.xx.200 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for xxx.xxx.xx.200:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),


C:\Users\User2>ping xxx.xxx.xx.200

Pinging 5.2.245.86 with 32 bytes of data:
Reply from 5.2.245.86: bytes=32 time=16ms TTL=58
Reply from 5.2.245.86: bytes=32 time=15ms TTL=58
Reply from 5.2.245.86: bytes=32 time=14ms TTL=58
Reply from 5.2.245.86: bytes=32 time=15ms TTL=58

Ping statistics for xxx.xxx.xx.200:
Packets: Sent = 4, Received = 4, Lost = 0 (0%  loss),
Approximate round trip times in milli-seconds:
Minimum = 14ms, Maximum = 16ms, Average = 15ms


If ping is positive all the time then let it run continuously
0
I need a batch command to stop the process and exit immediately when it finds this error:
connection error

the batch works with a certain tool and these are some benchmarks if they help something
The script I own closes the process in these situations and I want someone to help me add a new situation

:: Controll stopping
:: (1=enable,0=disable;)


:: Error exit codes
SET /A ERROR_UNKNOWN=-1
SET /A ERROR_OK=0
SET /A ERROR_NO_BOOKMARK_FOUND=1
SET /A ERROR_NO_MORE_DICTS=2
SET /A ERROR_FINDSTR_UNKNOWN_EXIT_CODE=3


and

1'st exit situation:
:: Check if the file exists
IF NOT EXIST "%filep%" (
ECHO We did not find.
SET /A errno=%ERROR_NO_MORE_DICTS%
GOTO END
)


Another exit situation:

) ELSE (
:: tool did not run ok. No ideea why. The multitude of checks should have
:: prevented this.
ECHO %tool% exited with non-zero exit code. No ideea why. Contact dev.
SET /A errno=%ERROR_UNKNOWN%
GOTO END
)


The 3'rd situation:

:: Call command
%composedcmd%

:: Check if we ran ok
IF /I "%ERRORLEVEL%" EQU "%ERROR_OK%" (
:: Check if we found mamammia
FIND "Discovered mamammia" "%tooloutfile%" >NUL 2>&1 && (
ECHO mamammia.
GOTO END


I want to add new exit,so when finds this error EXIT:
connection error


THANK YOU!
0
I have a file with a £ sign in it.  When I FTP it to a mainframe dataset there is an extra B before it.  How do I get rid of the B?
This is my batch file

open server
user aa bb
quote site xlate=DSUKEAT
bye

It is called from this batch file.

Here is the results file with server names, IDs and passwords changed.

ftp> Connected to server
open server
220-FTPD1 IBM FTP CS V2R1 at TCPP2, 10:42:31 on 2017-06-30.
220-**====================================================
220-**    Welcome to server FTP Server
220-**====================================================
220 Connection will close if idle for more than 15 minutes.
ftp> user aa bb
230-*** User Logon to qq DSP2 FTP Successful
230-*** FTP Queries: qq
230 P3EP21 is logged on.  Working directory is "P3EP21.".
ftp> quote site xlate=DSUKEAT
200 SITE command was accepted
200 Port request OK.
125 Storing data set test
226-Statistics have been updated for the PDS member that was transferred
226 Transfer completed successfully.
ftp: 411 bytes sent in Seconds Kbytes/sec.
ftp> 0.480.85bye
0
i need a batch file to create this path: C:\Windows\winwin123
this path already exist: C:\Windows\  but the folder called  ''winwin123 '' must be created ,afetr is created i want to go there: C:\Windows\winwin123
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.