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

Hello experts,

I have the following procedure to remove folders based on column A.
I would like to call cmd.exe and launch rmdir /q /s in folderPth
I am aware that I can use rmdir directly withtout calling CMD but I would like to remove it through cmd.exe.
Thank you in advance for your help.
Sub Remove_Folders()
Dim Ws As Worksheet
Dim i As Long
Dim LRow As Long
Dim Ans As Integer
Dim FSO As Object

Set Ws = ActiveSheet
Set FSO = CreateObject("Scripting.FileSystemObject")
LRow = Ws.Range("A" & Rows.Count).End(xlUp).Row

Ans = MsgBox("Before running this procedure, please check that" & _
             vbNewLine & "Folders to remove are reported in column A (initial range A2)" & _
             vbNewLine & "If so, please click on Yes else click on No.", vbQuestion + vbYesNo, "Confirm Please!")
If Ans = vbNo Then Exit Sub

      For i = 2 To LRow
      FolderPath = Ws.Range("A" & i).Value
        'Chek if folder end with \. If not create it
        If Right(FolderPath, 1) <> "\" Then
            FolderPath = FolderPath & "\"
        End If
        'Check if folder exist
        If Dir(FolderPath, vbDirectory) <> vbNullString Then
        'MsgBox "Folder exist", vbInformation
        Else
            MsgBox "Folder: " & FolderPath & " doesn't exist, operation has been aborted", vbInformation
            Exit Sub
        End If
    'add rmdir /q /s through cmd.exe
    MsgBox ("Folder " & FolderPath & " has been removed")
    Next i
End Sub

Open in new window

0
Starting with Angular 5
LVL 13
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

I have a mix of PCs/laptops that are standalone as well as those that join our AD/domain.

Have a public key that I wanted to import into the standalone PCs'  IE, Chrome & Firefox & was given steps below by vendor
for standalone PCs.  How can I automate the steps below (I have Desktop Central which could spawn a shell using the
non-interactive SYSTEM into them) & I have local administrator access to them (so I can issue
  'net use drive:  \\standalone_PC\c$ /user:administrator  admpassword' & copy files into them).

a)If there is no AD, you have to copy the certificate to clients.
b)On clients, go to IE > Tools > Internet Options > Content | Certificates.
c) On the Trusted Root Certification Authorities tab, click Import,  and Browse to the get_current_ca.cer
d) check "Place all certs in the following store"
e) change "Personal" to "Trusted Root Certification Authorities" & click Finish

Our users can't be trained to do steps a-e above, so need some sort of automation/scripts.

f) For PCs in the AD domain, modify the group policy to add the get_current_ca.cer into Trusted Root Certificate Authorities.
for step f above, as I'm not Wintel trained, can provide screen shot or will be something like what's mentioned in url below?
  https://support.securly.com/hc/en-us/articles/206688537-How-to-push-the-Securly-SSL-certificate-with-Active-Directory-GPO-

We disabled PowerShell, so Powershell scripting is not an option but  batch or VB scripting is allowed
0
Hello,
I need to export the various trigger of windows task scheduler in a csv & txt.
I supposed there is an option through cmd or powershell.

Could you please advice.
Thank you very much for your help.
1
I am trying to run procedure in cshtml and want to run one procedure automatically.  Dont want to use windows service or batch file as it is not really working.

i am using something like this in the batch file which runs every hour
start "<C:\Program Files\Internet Explorer\iexplore.exe>" http://10.180.8.5:9093/Feature/DownloadFeatures 

at one point it says completed successfully but it is not doing anything ie. not running the downloadfeatures method. Can you please help? Any automated tool i need to use to run this cshtml file?
0
Hello,

I need to write a script to detect a particular software guid exists in the registry on computers and run particular msiexec command line to uninstall it.  

For example, if 7B4192A1-84C4-4E90-A31B-B4847CA8E23C exists in HKLM, run msiexec /x {7B4192A1-84C4-4E90-A31B-B4847CA8E23C} /qn

I need to do that in a bat script.  Please advise how to do it.  

Many thanks.
0
I have a scheduled task that runs a batch file.  The batch file has several lines where I do a "git pull" command from a specific Git repository.  The Windows server where this runs has already been configured with proxy settings so that when you run "git pull" or any "git" command, it will properly connect to the required repository and run the command.  I have figured out that this schedule task and batch file will run just fine when a user is logged on.  But if I log out of the server, the schedule task start, but the "git pull" command gets stuck.  It's almost like it's can't connect and then the rest of the batch file will not run.  What should I do to ensure the "git" commands run fine even when a user is not logged in?

Thanks in advance!
-Christian
0
Hi there,

I have a scheduled task with these properties:

User account to run the task: A Service account that has logon as batch file privileges
Run whether user is logged on or not is enabled
Run with highest privileges is enabled
Configured for Windows Server 2012 R2
Trigger: Runs hourly
Actions values:
  • Action: Start a program
  • Program/script: Powershell.exe
  • Arguments: -command "Start-Process  C:\Build.bat -Verb runas"
  • Start in: C:\SDS_IT\

Now the problem I am having is that even though I have set the task to run whether user is logged on or not, it never completes unless the user is actually logged on.  If it I log out, the task starts and it gets to about 95% done and then it just gets stuck.  I've tested this theory several times and this is always the case.  I'm confused as to why it's not working.  The service account has local administrative permissions on this VM too.  I'm using PoweShell because I want the script to run a command prompt as administrator.

Any thoughts????
Thank you in advance!
-Christian
0
How to get count of system dump file from control panel through batch script?
It has to select the path as control panel->system security-> system->advanced system settings->startup and recovery->settings-> dump file count

we have to run this script in background, every time when dump create it has to show the count.

And each time it has to save the dump files to some other folder, when dump created..
0
I had this question after viewing SID account to username.

I tried creating the batch file to run through a text file with SIDs in it. This is what i came up with

@echo off
>output.txt (
for /f %%i IN (unresolvedsids.txt) DO C:Desktop\psgetsid.exe %%i
)

When i run it, it creates an empty output file, this is my first attempt at a batch file so i'm not very sure how to troubleshoot what is happening behind the scenes when you click the .bat file
0
What is the command line, within a batch, if possible, to start that batch in Administrator mode?
Or would another batch be needed to trigger this batch in Administrator?
0
Why Diversity in Tech Matters
LVL 13
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

I would like to change the script below, to produce a different output.  

Here is the file that contains the data to use.
C:\Users\user\Desktop\Folder\file.txt

ISA*11*          *22*          *33*1234567891234  *BB*ABCDEFGDH       *181127*3445*¬*00100*000000500*1*Q*:!
GS*PO*0012345678912*JDJDLSLA*20181127*3445*600*A*001234!
ST*850*78945611!
BEG*11*AB*12345**20181127!
N1*CD*COMP*LA*0012345678901!
N3*1 Street Drive!
N4*Pineland*OL*12345*US!
N1*AJ*SOMECOMPANY!
N1*TJ*Company Corp*2*456363748!
N3*1 Street Road!
N4*City, Somewhere**12345*u!
N1*AC*Company*2*987654321!
N3*1234 Street Blvd!
N4*Someplace*NY*12345*US!
N1*YG*Company Name*AL*0012345678912!
N3*5 Place Drive!
N4*Ackanhaw*MI*654321*US!
PO1**151*CA***IN*5465*CR*789456*GG*55555*EQ*Case(s)!
PID*F****Description One!
CTT*3****5*PQ!
SE*30*1234567!
GE*5*500!
IEA*1*000004567!


Here is the current script:
$InputFile = "C:\Users\user\Desktop\Folder\file.txt"
$OutputFile = "C:\Users\user\Desktop\Folder\fileR.txt"

Function ParseText ($OutputFile,$InputFile){
Begin{
        $line,$poline,$shipto,$totline,$total,$i,$n3 = $null,$null,$null,$null,$null,0,0
            Set-Content $OutputFile $null
            $Data = Get-Content -Path $InputFile | ?{$_ -match "(BEG\*)|(PO1\*)|(PID\*)|(N\d\*)|(IEA\*)"}
       }
 Process{
       $Data | % {
       #Check the end of data set
             If ($_ -match "IEA\*"){
                   If($poline -ne $null -and $total -ne $null){
                         

Open in new window

0
I am new to Automation testing, i have to write automation scripts for File Router service, this service has a source/input folder and a destination folder, based on the file name, extension the file(s) will be moved to respective destination.

This is a windows service. based on the configuration this router will move the files

What will be better technology stack for this requirement, when i run the tests , they should be able to copy, verify whether it is copied or not
0
Using Windows batch how can I rename up to 4 files, 1.pdf, 2.pdf, 3.pdf and 4.pdf all based on time stamp, 1.pdf being the file with the earliest time stamp..

At C:\Attachment\.... there could be several files all names differently, but all. pdf files.  
I want to rename each file based on when they were created etc..
0
i   want to upload file called b.txt to any  uploading website ex. uploadfiles.io -  openload.co........  and then past the url on pastebin with a title like here is your file b.txt with Paste Exposure public so i can find it later on the site !!!!!!

the whole point of doing this is to avoid putting any personal info in bat file like online uploading website account info or ftp server info
just safe and quick .... as i love to use them Freely  without caring about getting my info exposed  .
hope you understands
0
Is there a script that has the ability to look inside a pdf document and search for a specific text/phrase.. and if it finds it can the script indicate that it found the text?
0
hi,

i have script working.
When it runs it check for files and send email alert if not files and also if has files.
Currently it sending the email alerts text format.
Request experts help, want to send email with htm format.
and for errors it should bold the text and color RED.
can help...


#Requires -version 3.0
$WarningPreference="Continue"
function Send-Mail
{
  param (
    [string] $Email_Subject,
    [string] $Email_Body,
    [string] $Email_Attachment
  )
  Send-MailMessage -SmtpServer 'mailserver.com' `
  -Body $Email_Body `
  -From 'donotreply@mail.com' `
  -To 'admin@mail.com' `
  -Subject $Email_Subject `
  -Attachments $Email_Attachment
}
function Send-Error
{
  Write-Host "Sending Error Alert @ $emaildate"
  $subject = "ACTION REQUIRED : Error Alert @ $emaildate"
  $logcontents = get-content $Logfile | Out-String
  $Body = "Dear All,`n`nThis email sent by system for errors highlighted below."  + $logcontents + "`n Regards,`n Job Process"
  Send-Mail -Email_Subject $subject -Email_Body $Body -Email_Attachment $Logfile }
function send-status
{
  Write-Host "Sending Success Alert @ $emaildate"
  $subject = "INFO : Success Alert @ $emaildate"
  $logcontents = get-content $Logfile | Out-String
  $Body = "Dear All,`n`nThis email sent by system for your information"  + $logcontents + "`n Regards,`n Job Process"
  Send-Mail -Email_Subject $subject -Email_Body $Body -Email_Attachment $Logfile }

  #check if source files exists
0
How to remove the %JAVA_HOME%/bin; from Path  variable using cmd?
0
Within a batch file, I would like to tell the batch to copy the files to the folder which is found just outside where the batch is running.
Is there a command that will allow this to happen?
0
I have a variable with comma separated values in the batch file. Want to choose a random value?


@echo off
set values=1,4,65,8,3,45,7,90
expected output: any one random value from 1,4,65,8,3,45,7,90
0
CompTIA Security+
LVL 13
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

I have two batch files A.bat and B.bat. A.bat is calling to B.bat.
B.bat is doing some processing, and return back the result to A.bat. How A.bat can accept the return?

A.bat
@echo off
set str1=1,2,3,4,5
set str2=6,7,8,9
call B.bat %str1% %str2%

B.bat
@echo off
set str1=%1
set str2=%2
set str3=%str1%,%str2%

Expected that B.bat return %str3% (means 1,2,3,4,5,6,7,8,9) back to A.bat file So that A.bat used the result for further processing.
0
I need a batch script for windows that does the following:

Scan *.txt file in the “ARAT_Preverification” folder to find if there are any “Error codes” like 501, 502, 503 - 509 (scenario mentioned below);

Below is the sample .txt file where every 1st row has no data and can be ignored; the following rows has data where the batch should scan and find the error codes (if any) between 18-20 characters only, each row has 90 characters including spaces. The row starts with Letter D in each file except the first row.

H0001200008143800120918155209
D43442371013477773520000001280012091800001
D43442371011722225010000000900012091800001
D43442371007692925040000007200012091800001

If any *.txt file has the above-mentioned error codes then that file should be moved to “ARAT_Verified” Folder.

I got the below code it works sometime if the file is small, if the file size is large (over 1000 rows) it doesn't detect the error code, anything wrong with he code?

@echo off
setlocal enabledelayedexpansion
for %%x in (D:\ARAT\ARAT_Preverification\*.txt) do (
set "file=%%x"
for /f %%i in ('type "!file!"') do set "string=%%i"
    set "str=!string:~17,3!"
    for %%a in (501 502 503 504 505 506 507 508 509) do if "!str!"=="%%a" move "!file!" "D:\ARAT\ARAT_Verified"
)

Open in new window

0
Batch file to ping all network hosts to determinate witch are powered up and store output to a text file

Hello, I need to write a Batch file to ping all network hosts (readed from a hostslist.txt) and write UP/DOWN state to a text file.
0
Hello Experts,

I need a help I've a batch script for folder locking, in this script I've set a password for folder access after that I convert this batch to exe & give it to users.
Now user wants to create own password & after creating the password once user put password for folder access it should not be appear it should be in form in dot or blank.
Most important thing i want set a default password in case users forget password in that case admin should open that folder from default password, also main folder, sub folder & files which is store in Vault folder should not be find if anyone try to find using windows search.

Script:-

cls
@echo off
mode 50, 10
title   ~Safty Vault~

echo.
(SET OUT=3F)

color %OUT%

if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Vault goto MDLOCKER
:CONFIRM
echo Are you sure you want to lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Vault "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
echo Enter password to unlock folder
set/p "pass=>"
if NOT %pass%== password goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Vault
echo Folder Unlocked successfully
0
I wanted to find out if there exists a PDF command line program, that will help to join to different files so that they are side by side.
So let's say 1 file is a manual in English and the other in Spanish.
I wanted to join each page of a 20 page manual, so that the English page 1 is on one side, and the Spanish page 1 is on the other side.
And I want them both to reside in 1 file, as a side by side.
Is there a command line program that I can use that can help me accomplish this?
0
Chemo has taken a lot from me. I am having problem with a batch file and have gone back to square 1 to test simple things.

@ECHO OFF
IF EXIST %1 GOTO ITEXIST
ECHO %%1 DID NOT EXIST
GOTO EXIT
:ITEXIST
ECHO %%1 DID EXIST
:EXIT
ECHO ON

Why am I getting a syntax error?
1

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.