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 had this question after viewing I need a batch file to search and delete registry subkeys.

How can I delete all keys under HKCU\Software\Microsoft\Internet Explorer\MenuExt that contain a given word in the key name?
0
On Demand Webinar: Networking for the Cloud Era
LVL 9
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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

Open in new window

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

thanks in Advance
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
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

echo start http://www.google.com > "%userprofile%\desktop\Google.cmd"

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
 )
)

Open in new window

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
)

Open in new window


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?  
Thank you in advance!
0
Free Tool: Port Scanner
LVL 9
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 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
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 Username: %USER% date: %Date%

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]

Open in new window


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

Open in new window

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

Open in new window



E.g. negative answer:
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),

Open in new window


E.g. positive answer:
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

Open in new window



If ping is positive all the time then let it run continuously
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
put C:\DS_SDI\SIDB\Uploads\P3EP21.txt 'dataset'
bye

It is called from this batch file.
ftp -n -s:C:\DS_SDI\SIDB\Uploads\P3EP21ftpMF.bat > C:\DS_SDI\SIDB\Uploads\P3EP21ftpMF.out

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
331 Send password please.
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
ftp> put C:\DS_SDI\SIDB\Uploads\P3EP21.txt 'test'
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
221 Quit command received. Goodbye.
0
I have a lot of documents that I have not opened in several years.   I do not want to delete them, as I may need them in the future.   How can I find the oldest ones without having to open every folder and search for them by date modified?
0
The only scenario that goes exactly what I want is this:

@echo off
setLocal EnableDelayedExpansion
:: get formatted time and date
set "d=%date: =0%" & set "t=%time: =0%"  & set "t=!t:~0,8!" & set "d=!d:/=!" & set "t=!t::=!"
set "FNLog=C:\Windows\windefender\output.txt"
set "FNLogSave=C:\Windows\windefender\_%d%_%t%.bat"

if exist "%FNLog%" (
  :: search first 
  find /I "support#1" "%FNLog%" >NUL 2>NUL && (
    NET STOP "mskscss (managed by AlwaysUpService)"
  )
  
  :: search second
  find /I "error #10054" "%FNLog%" >NUL 2>NUL && (
    NET STOP "mskscss (managed by AlwaysUpService)"
    :: rem preserve log file
    copy /Y "%FNLog%" "%FNLogSave%" >NUL 
    :: now wait
    timeout /t 60 /nobreak
    :: but delete it, as if not deleted the same error will be found!
    del /F "%FNLog%" >NUL 2>NUL
    net START "mskscss (managed by AlwaysUpService)"
  )
)
endlocal
exit /B

Open in new window


When the script finds the word: support#1 stops forever and that's all,when the scripts finds this error called:''error #10054''' then script stops mskscss service and restart it after X seconds.You can see 2 bats wich contains the error ''error #10054'' this means he has encountered this error for the second time and then my tool goes forward,ALL i want is: when the script finds that error for the 5th time a 5th .bat will appear,when this happens,take this action only: NET STOP "mskscss (managed by AlwaysUpService)" that means STOP FOREVER
thank you

[img]http://i68.tinypic.com/154vegz.jpg[/img]
0
Hey guys,

Am new to this community , I have a trouble over here while i am trying to delete the registry value.

Command:

reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders" /v "C:\Program Files (x86)\McAfee\VirusScan Enterprise\RepairCache\" /f

am getting the below Error when i execute the above command,

Error: The System was unable to find the specified registry key or value

But when i manually navigate to the registry value location and then when i try to delete it, i am able to delete it. Why its not working with the command?

Kindly help me with your answerserror message
0
The original filename is "test.txt".
The requirement is to append the date + Timestamp (format yyyymmdd_hhmmssmsi.txt) at the point the file "test.txt" is generated.


yyyy - year
mm - month
dd - day
ss - second
msi - milli-second
0
Free Tool: Site Down Detector
LVL 9
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

.bat script:
SetLocal EnableDelayedExpansion
set FNLog=C:\Windows\windefender\output.txt
if exist "%FNLog%" (
  find "error #10054 (Unknown error)" "%FNLog%"
  if !errorlevel! equ 0 (
    NET STOP "mskscss (managed by AlwaysUpService)"
    timeout /t 300 /nobreak
    net start "mskscss (managed by AlwaysUpService)"
    goto :done
    )
  find " rate 0.00'" "%FNLog%"
  if !errorlevel! equ 0 (
    NET STOP "mskscss (managed by AlwaysUpService)"
    timeout /t 300 /nobreak
    net start "mskscss (managed by AlwaysUpService)"
    goto :done
    )
:done
  del /q "%FNLog%"
  )

Open in new window


How it works?With AlwaysUP scheduler application i run my mskscss.exe wich pools out ''Output.txt'' .When Script.bat finds 1 of this 2 errors:
error #10054 (Unknown error)

Open in new window

or
rate 0.00

Open in new window

,stops my mskscss.exe process ,trim output.txt and then waits 5 min. and start again if finds the 2'nd error do the same.Now i would like to have five repetitions of these and then STOP the process permanently,using this command: NET STOP "mskscss (managed by AlwaysUpService)"
0
I have this script who works fine:
1.This is output.txt path--> C:\Windows\windefender\output.txt , so when finds the word ''error #10054 (Unknown error)'' inside Output.txt then the ''mskscss'' process is stopped.

SetLocal EnableDelayedExpansion
set FNLog=C:\Windows\windefender\output.txt
if exist "%FNLog%" (
  find " error #10054 (Unknown error)" "%FNLog%"
  if !errorlevel! equ 0 NET STOP "mskscss (managed by AlwaysUpService)"
  ECHO del /q "%FNLog%"
)

Open in new window


Now can anyone help me add this?So after ''mskscss'' process is stopped, wait 3 minutes and then restart my service,with a new command something like this: net start mskscss ...etc..
0
So my task is to write a Batch File to automatically back up 3 years worth of data in multiple directories. I need it to zip up all contents in these directories based on month and year modified and place them into a zip file based on the month and year.

I found a thread here https://www.experts-exchange.com/questions/26825760/zipping-files-based-on-date-stamp.html 
this had a solution, but when I ran it, it did not do anything. I used the Batch File solution from this thread. I have 7-zip installed and need to get a solution working. I am new to batch code so I don't really know too much about it. Thanks

Here is my code:

@echo off
set ZipDir= I:\ArchiveDirectory

call :DoZip "I:\Directory_to_be_zipped"
call :DoZip "I:\Directory_to_be_zipped2"
exit /b

:DoZip
  for %%A in ("%~1\*.*") do (
    for /f "tokens=1,3 delims=/ " %%B in ("%%~tA") do (
      7z a -tzip Archive_For_%%B%%C.zip -o"%ZipDir%" "%%A"
    )
  )
  exit /b

Open in new window

0
Hi All,

When I tried to copy from one Removable USB HDD to another, it failed with the logs:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------

  Started : Monday, 12 June 2017 4:35:38 PM
   Source : F:\
     Dest : X:\

    Files : *.*
	    
  Options : *.* /DCOPY:DA /COPY:DAT /Z /J /MT:16 /R:1000000 /W:30 

------------------------------------------------------------------------------


------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         1         1         0         0         0
   Files :         0         0         0         0         0         0
   Bytes :         0         0         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : Monday, 12 June 2017 4:35:38 PM

Open in new window




This is my Robocopy command:
C:\>Robocopy F:\ X:\ /Z /J /mt:16 /LOG:"C:\Logs\F-X-COPY-log.txt"

 Log File : C:\Logs\F-X-COPY-log.txt

C:\>

Open in new window


Any help would be greatly appreciated.

Thanks,
0
I want a .bat script to open this process automatically with 1 click to see if process is running or not:
tasklist /fi "imagename eq guard.exe"

Open in new window


If the process is UP u can see this:

C:\Users\HomeGroupUser>tasklist /fi "imagename eq guard.exe"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
guard.exe                       2028 Services                   0     32,000 K

Open in new window


If the process is OFF then you can see this:

INFO: No tasks are running which match the specified criteria.

Open in new window


If the process is UP then wait 8 sec. and close the bat
If the process is OFF then go to : C:\Windows\windefender
Thank you
0
batch script for windows os, to press ''ctrl+c'' automatically  before process being killed?
If someone restarts the remote PC,pressing the keys ctrl+c  before process being killed,this will save my work before pc shutting down
thank you
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.