Windows Batch

11K

Solutions

8

Articles & Videos

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

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
Free Tool: Site Down Detector
LVL 8
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.

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
.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
Hello all,

I am trying to write a batch script to delete multiple files(different file types like .sta, .stw, .txt , .pdf, .docx , .ppt) located in different location by mentioning file paths in separate file.

But the script is not running and also not displaying any error.Anyone please help me to resolve this issue.

Used below script to delete files:

@echo off
for /f "tokens=*" %%a in (filelist.txt) do (
   Echo Attempting to delete file %%a
   Echo Del "D:\%%a"
)

content inside filelist.txt :
 D:\Test\testing\testing1\testing.pptx
D:\Test\testing\testing1\test2.docx
D:\test2\trial\trialref\ref1.xlsx
0
desktop universal path?
I use this path for a bat command and i every time I run it in another PC i must change the path,is there a way to set a universal path?to run it into any pc without having to change the path?

C:\Users\HomeGroupUser\Desktop\tool\salerno.txt

thank you!
0
DevOps Toolchain Recommendations
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Someone can help me to create a .bat script to resume service.restore?
Also create a Output.txt
So,when PC restarts or shut down or network connection falls then my tool saves a file named:  service.restore
I want a .bat file to restart automatically the file ''service.restore'' and also create another file called Output.txt
0
I want to upload a file to our web server via a batch file. When I run the batch, it errors out everywhere, "'open' is not recognized" etc. I know I can turn on a server role to enable FTP, but that seems like a lot of hooey to just be able to connect to a remote server and put a file up there. Is there any other way?
0
I would like to get the output from this wmic query put into a variable

wmic printer where default=TRUE get name

Open in new window


Further, when this is run in a command prompt, the output is:

Name
\\PRINTSERVER\MyPrinter

I would like the variable to contain only the portion after \\PRINTSERVER\ which in this case will be simply MyPrinter.
0
i am looking for a VBscript code in form of HTA or bat file so that it pops to select folder, once i select the folder, it should rename all pdf files in that folder, by renaming i mean remove any thing after _ underscore of trailing and also replace all dots . with spaces.
0
Why does this not work?

SET X=1
IF %X% == 1 (
    SET Y=2
    IF %Y% == 2 (
        SET Z=3
    )
)
PAUSE

Kevin
0
The command:

DIR %1% /S > "C:\Users\Name\Documents\Output 1.txt"

The result:

C:\Users\Name\Documents>DIR "C:\Users\Name\Documents\Folder"\Users\Name\Documents\Output 1.txt"
The system cannot find the file specified.

Where I want to end up:

DIR %1% /S > "%~dp0\Output 1.txt"

But the result with this is even worse.

Kevin
0
Hi Expert,

Good Day.

I would like to check if there any player that can play windows batch file(.bat), it's trigger from a cctv software cALL Hyper Electronics Mappers, I can play this video because I have the software but for other ppl it's unable, I check my player is selfplayer which is their own media player from the software, I would like to check of anyone here know free any media player that can play windows batch file video? Appreciate if any expert can advise me.

Many Thanks!
0
How to stop and not kill a process
The .bat script bellow kills and don't stop my AlwaysUP.exe


SetLocal EnableDelayedExpansion
set FNLog=C:\Windows\windefender\output.txt
if exist "%FNLog%" (
  find "Finished" "%FNLog%"
  if !errorlevel! equ 0 taskkill /f /im AlwaysUp.exe /t
  ECHO del /q "%FNLog%"
)

Open in new window

0
Hi Experts,

I just wan to seek help, im not really a programmer but I came across the need for this for one project. Is there a way for a batch file or script to rename a file with the format like this DDMMYYY_HHam/pm_Filename.xls (am/pm is interchangeable), the tricky part is the date and time should be converted to GMT Timezone, I am on SGT timezone right now so I cannot use the time from my local machine.

I'm using this script to rename it but I'm having issues with the date and time changing from single digit to double digit which requires the percentage % to be change.

  @echo off
  set TmpFile="%temp%.\tmp.vbs"
  echo> %TmpFile% n=Now
  echo>>%TmpFile% s=DateAdd("h", -7, n)
  echo>>%TmpFile% Wscript.Echo "set ireland7=" ^& s
  cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
  call "%temp%.\tmp.bat"
  del  "%temp%.\tmp.bat"
  del  %TmpFile%

 
copy "D:\Data\Hourly_Report\HourlyFile\voucher_last_hour.xls" "D:\Data\Hourly_Report\%ireland7:~0,2%-%ireland7:~3,1%-%ireland7:~5,4%_%ireland7:~10,2%%ireland7:~19,17%_Hourly_Report.xls"



Thanks in advance!! :)
0
Space-Age Communications Transitions to DevOps
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

How to automatically close a process when  finds one of this lines in Output.txt

Discovered credentials
or
finished.
0
Someone can help me to create a .bat file to stop AlwaysUP.exe application but only when i receive this message: ''Finished.''
thank you
0
How can I search through .jpg files by date and time, either creation date and time or saved date and time?
0
Amazon Music, for reasons only know to them, downloads the following file

          Mason Williams - Change the World.MP3

renaming the files during download as follows:

          01-02- Change the World.MP3

I know restoring the artist's name is going to be difficult, but how do I batch rename...

          01-02- Change the World.MP3     to     Change the World.MP3
          01-04- Hello, Goodbye.MP3          to     Hello, Goodbye.MP3
          02-02- Ticket to Ride.MP3             to      Ticket to Ride.MP3

In other words, stripping the 0?-0?-   from the front-end of the filename.

I have tried several iterations of REN such as REN  "0?-0?-*.MP3"  "*.MP3",  but nothing I do seems to work. Suggestions?
0
Hi all,

Does anyone know how to find out on how many computers a user is logged onto across the domain?

I tried to use psloggedon, didn't work for me.

thanks.
0
Not sure why script below is not working. Closes immediately after populating the dsquery
Scripts needs
-Get a list of PCs from AD OU
-Check if a file exist and copy some archive logs with %computername%. prepended when copied to destination

echo on
setlocal
set source=\\dfsname\share\folder\Prod
set computers=\\dfsname\share\folder\Prod\Pcs.txt
for /f "tokens=*" %%a in ('%source%\dsquery computer "OU=Desktops,DC=domain,DC=com" -limit 1000 -o rdn ') do echo %%~a>>%computers%
for /f %%a in %computers% do (if Exist \\%%a\c$\Windows\System32\domtimec.log xcopy \\%%a\c$\Windows\System32\domtimec.2*.log \\Server1\Logs\%%a.*
endlocal

Open in new window

0

Windows Batch

11K

Solutions

8

Articles & Videos

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.