[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

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

Good afternoon,
I'm need some help with a script I'm using to clean up the profiles on the public pc's. I need to add some code to remove .bak files from the profile list. particularly this one, S-1-5-21-3822824043-2368925748-477173625-1177.bak For that matter, I could use a totally different script but I would prefer to just add it to this one.



@ECHO OFF

FOR /F "tokens=*" %%a IN ('REG QUERY "HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"^|FIND /I "S-1-5-21"') DO CALL :REGDELETE "%%a"
GOTO CLEAN

:REGDELETE
FOR /F %%b IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "internet"') DO REG DELETE "%%b" /F
FOR /F %%c IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "TEMP"') DO REG DELETE "%%c" /F
FOR /F %%d IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "short"') DO REG DELETE "%%d" /F
FOR /F %%e IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "jobseeker"') DO REG DELETE "%%e" /F
FOR /F %%f IN ('REG QUERY %1 /V ProfileImagePath^|FIND /I "catalog"') DO REG DELETE "%%f" /F
GOTO CLEAN

:CLEAN
FOR /F %%b IN ('DIR C:\Users /B^|FIND /I "internet"') DO RMDIR /S /Q "C:\Users\%%b"
FOR /F %%c IN ('DIR C:\Users /B^|FIND /I "TEMP"') DO RMDIR /S /Q "C:\Users\%%c"
FOR /F %%d IN ('DIR C:\Users /B^|FIND /I "short"') DO RMDIR /S /Q "C:\Users\%%d"
FOR /F %%e IN ('DIR C:\Users /B^|FIND /I "jobseeker"') DO RMDIR /S /Q "C:\Users\%%e"
FOR /F %%f IN ('DIR C:\Users /B^|FIND /I "public"') DO RMDIR /S /Q "C:\Users\%%f"
FOR /F %%g IN ('DIR C:\Users /B^|FIND /I …
0
Rowby Goren Makes an Impact on Screen and Online
LVL 12
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

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
I had this question after viewing List folders and sub-folders of a path with its size.

I need to take this a step further.  I need to be able to search for file types like .mdb, and ,accdb..
Then output data to a text file I can link to.  
All the code I have inserts into the same worksheet, but this keeps crashing my computer.

Ideally I would like to include:
Folder
Sub Folder
Path
Name
Type
Size
Last Modified By or Owner (Not sure if possbile)
Date Last Modified

Exported to a text file.  

We have an insane amount of access databases, I need to do a formal audit to gain an insight of what is out there, size and when used last.
1
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
Around 350 pc and servers running windows os, how to  generate windows patch update status report of those pc & servers, information such as last update date, patch installed. powershell script or other ways to generate the report?
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
I want improve this batch script I wrote to rename a file and upload

@echo off
#Rename Files
cd c:\aaaa\bbbb\
ren QQ-PS.txt QQ-PS.%date:~-10,2%%date:~-7,2%%date:~-2,4%.%time:~0,2%%time:~3,2%%time:~6,2%.txt
ren QQ-OR.txt QQ-OR.%date:~-10,2%%date:~-7,2%%date:~-2,4%.%time:~0,2%%time:~3,2%%time:~6,2%.txt
#Send QQ file to SFTP SERVER
ftp -n -i SFTP SERVER <<END
user xxxx xxxxx
lcd c:\aaaa\bbbb\
cd "\ccc\ddd\"
bin
mput QQ-*.*.txt
bye
exit
0
Learn Ruby Fundamentals
LVL 12
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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
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
Python 3 Fundamentals
LVL 12
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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
I do not have a problem. I need to know where to look to learn the different types of files in script.
0
Good morning. I want to schedule a task for all users of a business I support to auto delete the downloads and desktop folder. This is because of GDPR. I have created and run a .bat file successfully, however the problem with my bat file is that if another user logs on to the computer it doesn't run. The contents of the bat file are as follows:

@echo off
forfiles -p "C:\Users\%username%\Desktop" -s -m *.* /C "cmd /c del @path"
forfiles -p "C:\Users\%username%\Downloads" -s -m *.* /C "cmd /c del @path"

In order for it to work via a scheduled task I have to add in the correct username as follows (fredbloggs is an example)

@echo off
forfiles -p "C:\Users\fredbloggs\Desktop" -s -m *.* /C "cmd /c del @path"
forfiles -p "C:\Users\fredbloggs\Downloads" -s -m *.* /C "cmd /c del @path"

The business can have a high turnover of staff and sometimes other users login. It is connected to an Azure AD (Office 365)

Is there a way round it, or even better a way I can tell Azure to run the .bat for every user?
0
Hello Experts,

I am trying to run as administrator a .bat file on a Windows 10 virtual machine remotely via VirtualBox's command line interface. I am controlling the Windows 10 virtual machine via a Linux headless server.

Currently I am using the command:

vboxmanage guestcontrol "win10clean" exec --image "C:/Temp/run.bat" --username localadmin --password *** --verbose --wait-stdout

Output:

Opening guest session as user 'localadmin' ...
Waiting for guest session to start ...
Guest session (ID 13) has been started
Starting guest process ...
Process 'C:/Temp/run.bat' (PID 4592) started

C:\WINDOWS\system32>REG ADD HKLM\Software\Microsoft\Windows\currentversion\explorer\advanced /v Start_PowerButtonAction /t REG_DWORD /d 2 Process terminated
Exit code=1 (Status=500 [successfully terminated])
Closing guest session ...

The VM name is win10clean
The .bat file is called run.bat and is stored on the VM under the path C:/Temp/
The run.bat file is suppose to update a registry value which is why the command must be run as administrator. However the registry value says the same.
1
I want to automate the file transfer.
FTP Client : Reflection FTP Client
SFTP Server : Tectia SFTP Server.
I tried using similar to winscp scripts powershell but it didnt work.
Can someone help me providing the script which will work to transfer file to sftp server running script.
Authentication method is public key + password authentication and password must be encrypted.
0
Hi All,

I have .txt  files in FileZilla server. I need to transfer files from FileZilla server to Local Path C:\, Below is the code i am running in job schedule,

prompt
lcd C:\
open sftp.getixhealth.com 22
abcd
xyz
bin
cd /In
mput *.txt
Quit


When i run the above code batch files is getting executed but files are not genearting in Local Path C:\. Please help me in transferring files from fileZilla Server to local path C:\.

Thank You In advance....
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.