Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

hello all

I am trying to create a batch file to add registry key.
its should run on both 32bit and 64 bit
there are 2 different registry keys for 32bit and 64bit.
so if it is 32-bit, it adds the 32-bit registry key and vice versa

Any ideas?

Thanks in advance
0
Keep up with what's happening at Experts Exchange!
LVL 11
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

I had this question after viewing Scheduled reboot if User is Logged Off.

Hello,

if I run your mentionend script while I'm logged in (I've changed the conditions to shutdown while logged in), it will shutdown.
If I schedule the shutdown nothing happens (changed the conditions to original).
If I start the schedule while I'm logged in nothing happens (changed the conditions to shutdown while logged in).

I attached my script-files and task - I've changed the conditions, so I can test it while I'm logged in.

I think there is something wrong with the task.

Please help.

Thanks.
SHUTDOWN-BAT.png
SHUTDOWN-CMD.png
SHUTDOWN-TASK.png
0
Hi,

i'm looking for a solution to run a For Loop a certain amount of times, which i set before in a variable.

i did something like this:
set /p count=Count:

for %%i IN (0,1,%%count%%) do

Open in new window


But no matter what i set the variable to, the code runs exact 3 times.
Where is my mistake ?
0
To check health of our customized Windows appliances after Meltdown patching,
I'll need a  bat/cmd/vb (don't want Powershell) script to :

1. to list the 1st 5 lines of output (which we'll run before patch/reboot & after to compare)
2. the patch date+time  &  compare with the last reboot date/time & the date a registry
     key is added : the sequence should be  add registry key 1st, apply patch & last reboot
     date/time last


1st 5 lines:
========
SERVICE_NAME: ACDaemon
DISPLAY_NAME: ArcSoft Connect Daemon
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE,PAUSABLE,IGNORES_SHUTDOWN)
. . . . .

SERVICE_NAME: AcPrfMgrSvc
DISPLAY_NAME: Ac Profile Manager Service
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
0
So here's the data I am looking at..I have a single folder files named this way:
file one (1).ext
file one (2).ext
file one (3).ext
file two 1.ext
file two 2.ext
file two 3.ext
file three a.ext
file three b.ext
file three c.ext ... etc etc

There are about 250,000 of these files in a single folder. I am trying to create a batch file where it will read the name of the file and create a folder based off of the text thats the same and stops when it reaches where the file is different and moves on to the next folder. Then copies the files into the created folder.

For example in the set above, I would end up with three folders: file one, file two and file the each with the 3 corresponding files moved to the correct folder. I came up with as much below but I cant figure out a way to get it to stop reading the file name when it reaches the "(" or the number or the different letter or whatever may be different in the file name. What I end up with is a folder for each file (full file name) and the corresponding file in that folder.

Heres my code:

@echo off
setlocal enabledelayedexpansion
for %%A in (*.ext) do (
   echo file found  %%A
   for /f "delims=" %%B in ("%%A") do set fname=%%~nB
   for /f "delims=" %%C in ("%%A") do set fextn=%%~xC
   for /f "tokens=1* delims=_" %%D in ("!fname!") do set folname=%%D
   echo folder name !folname!
   if not exist "!folname!" (
      echo Folder !folname! does not exist, creating
      md "!folname!"
   ) else (
 …
0
Is there a script out there (.bat or .vbs ) that verify the Meltdn/Spectr  patches are successfully applied (including that registry key is added) & the health of Windows after patching?   I don't want Powershell script.
0
I'll describe the error I got when enabling RSAT command line options on my laptop later.

More urgent: how to fix error below:
C:\>dsquery computer ou=DEPT,dc=bbbprod,dc=com,dc=sg
dsquery failed:A referral was returned from the server.
type dsquery /? for help.
0
Hi there,
Was wondering if someone can help me out here...
One of our customers changed their FTP application, and as a result, broke our automated process. What was set up to run daily:

@echo off
echo user "username"> ftpcmd.dat
echo "password">> ftpcmd.dat
echo bin>> ftpcmd.dat
echo put %1>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat ftp.site.com
del ftpcmd.dat

Open in new window


Using FileZilla, I managed to troubleshoot some settings: FTP -> Active Mode and Encryption-> Only use plain FTP (insecure)
Once these were set, I was able to connect to the server and manually upload the file.

Is there any way to set these settings in the batch file above? Or would I need to go a different way?

Please let me know if you need additional info/details...

Much appreciated,
Classic
0
i tried to user the below command via batch script file

START \\%computer%\C$ /user:%username% %Password%

but every time it keep asking for the username and password.
is their any way that i can get it to open the C drive for any computer that i input in the batch file

note: i input in the batch file the username and password and PC name
so i use %username% and %password% and %computer% from my input when i run the batch file.

any advise?
0
I don't have admin rights & can't install dsquery/RSAT.

Is there a Windows command prompt command to list out member computers of an OU ?
Pls give exact syntax
0
Free Tool: Subnet Calculator
LVL 11
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

hello experts
i am using below powershell script to telnet my network device and do some automatic task, for example change WIFI password and send email out daily, while i test it connect to network devices such as router and switch, it works, but when i try to using this script connect to Cisco WLC it failed because WLC do not support raw telnet mode any more so it drop the telnet connection come from my script. for i am new for powershell, could you help me do some modify for my script so that it not using raw telnet mode while connecting to network device?
thank you

Function Get-Telnet
{   Param (
        [Parameter(ValueFromPipeline=$true)]
        [String[]]$Commands = @("username","password","disable clipaging","sh config"),
        [string]$RemoteHost = "HostnameOrIPAddress",
        [string]$Port = "23",
        [int]$WaitTime = 1000,
        [string]$OutputPath = "\\server\share\switchbackup.txt"
    )
    #Attach to the remote device, setup streaming requirements
    $Socket = New-Object System.Net.Sockets.TcpClient($RemoteHost, $Port)
    If ($Socket)
    {   $Stream = $Socket.GetStream()
        $Writer = New-Object System.IO.StreamWriter($Stream)
        $Buffer = New-Object System.Byte[] 1024 
        $Encoding = New-Object System.Text.AsciiEncoding

        #Now start issuing the commands
        ForEach ($Command in $Commands)
        {   $Writer.WriteLine($Command) 
            $Writer.Flush()
            Start-Sleep -Milliseconds $WaitTime
       

Open in new window

0
Hello,

what I would like is a batch file that will get the folder structure of the drive into a menu structure so that you can select the folder you want to go into, and once you select a folder from the menu, the subfolders of that folder would then be listed in a menu as well, and so on and so forth as deep into the folder structure as you want to drill down to. And in each menu would have a "backup current folder level" and a "list all contents of current folder" and if possible include a "go to previous folder" option.

 Basically I would like to run the batch file and be given a menu of the folders only of the c drive, then be given an option to either backup the current folder, list the files of the current folder in case I wanna to only backup one file from that folder, or select a subfolder and then be given the same options with the addition of the go to previous folder option for subfolders.

 I've tried and tried to write something like this but I'm not a strong batch script writer and just can't get anywhere with it.

 Thank you very much in advance for your help,
Ryan
0
SERVERSEYE.txt
Kindly find the above attached code.
Hello,

I am trying to make a batch file that get system information of list of servers.
List of servers is listed in Servers.txt file
could you please advise why it's not working. kindly find the below code:
----------------------------------------
REM set variables
set manufacturer=
set model=
set serialnumber=
set name=
set ustring=
set pstring=

:USERNAME
REM Get Username
set user=%username%
set /p user=[Admin Username  / Press Enter For %username%] :

REM Check If Other Username
IF NOT %user% == %username% goto newuser
goto start

:NEWUSER
REM It's A Different User
set ustring=/user:"%user%"

:PASSWORD
REM Get Password
echo Password:
set pass=
set /p pass=

REM Check if password was entered
IF [%pass%] == [] goto nopass
set pstring=/password:"%pass%"
goto start

:NOPASS
REM No password entered
set pstring=


:START
cls
echo Servers
for /f "tokens=*" %%i in (Servers.txt) do (
FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% ComputerSystem GET Manufacturer /value') do SET manufacturer=%%a
FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% ComputerSystem GET Model /value') do SET model=%%a
FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% CPU GET name /Value') do SET name=%%a
FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% Bios GET SerialNumber /value') do SET serialnumber=%%a
)
echo    %%i …
0
Hello Experts,

I have a log file i.e. a CSV file present in SFTP server.  Now I want to connect to SFTP server using private key then insert a row at end without replacing the file as the same file might be used by other applications.

For example if the CSV should be have 3 rows then 4th row can be written , but there could be a situation like another system will also try to insert another log .

Need batch script .
0
Hi Experts,

As per  my daily job run , Daily one folder (with some files)  will get create in a specified path. I have to copy this folder from one location to another using batch script.

So Copying should happen based on last modified date as previous day's folders will also present in the same path.

I have a script which moves all the folders from one location to another.

set source="x"
set destination="Z"
xcopy %x% %Z% /E /Y

Open in new window


I need to modify this script according to my requirement.

Any help regarding this would be highly appreciated.

Thanks in Advance/.
0
Hi All,

   I have used the following script in a text file "AVS-Weekly.txt".
option batch abort
option confirm off
echo off

open sftp://AVS_USER:aZZaWerP@1.1.4.131 -hostkey="ssh-rsa 1024 60:19:e6:8c:f3:0b:e8:73:90:47:bc:78:a2:ca:c3:c6"
option transfer binary

PUT  C:\AVS_USER\FTP_Files\Weekly\*.TXT  /app/AVS/Outbound/Production              
close
exit

Open in new window


Then a bat file is created with the below script.
"C:\Program Files (x86)\WinSCP\WinSCP.com" -script=C:\AVS_USER\FTP_Files\Weekly\AVS-Weekly.txt

Open in new window


When i double click the bat file, it is not uploading the file to the FTP location.
When i opened the bat file using the command editor, it says "session opened" and "session started", "active session", "session closed".

Can someone kindly help me with the fix?
0
I have the following code, I am trying to modify certain line in XML file but I have to do it with all the files in the directory and retain the original file name.

@echo off
setlocal EnableDelayedExpansion

set anotherVariable=yes

(for /F "delims=" %%a in (sampleCopy.xml) do (
   set "line=%%a"
   set "newLine=!line:?>=!"
   if "!newLine!" neq "!line!" (
      set "newLine=<?xml version="1.0" encoding="UTF-8" standalone="%anotherVariable%"?>"
   )
   echo !newLine!
)) > newFile.xml

Open in new window

0
I've been tasked with finding a backup solution for Yammer (Office 365), and thought it was "job done" when I found this article:

https://developer.yammer.com/v1.0/docs/data-export-api

Towards the end of the article there is a Windows batch script you can run in order to do the backup:

@ECHO OFF

    IF [%1]==[ ] (
      IF [%2]==[ ](
        ECHO "Usage: export.cdm <OAuth Access Token> <Directory>"
        EXIT /B
      )
    )

    :: Your Yammer Oauth 2 Access Token. This must be a token for a verified admin account. 
    SET AT=%1

    :: Download location for the export files.
    SET DIR=%2
    cd %DIR%

    :: Find the last export of there is one. The start date and time of the previous export is encoced in the filename 
    SET LAST_EXPORT=0
    IF EXIST export-*.zip (
      FOR /f "delims=" %%a in ('dir /B /D export-*.zip') do(
        :: Use the timestamp from the most recent file
        SET LAST_EXPORT=%%a
      )
    )

    :: Remove the relevant parts of the filename so the timestamp can be stored 
    SET LAST_EXPORT=%LAST_EXPORT:export-=%
    SET LAST_EXPORT=%LAST_EXPORT:.zip=%
    :: Don't foget the replace the underscore with the colons to ensure correct ISO-8601 formatting
    SET LAST_EXPORT=%LAST_EXPORT:_=:%

    :: Calculate the current date in UNIX time for the filename of the export.
    SET TIME_STAMP=%time:~0,2%:%time:~3,2%:%time:~6,2%z
    SET NEXT_EXPORT=%date:~10,4%-%date:~4,2%-%date:~7,2%T%TIME_STAMP%
    :: Make sure to replace 

Open in new window

0
Hello!

I am trying to sftp a file that is alomost 2.5 GB using WinSCP. When I drag and drop using WinSCP the entire file gets transferred. I am trying to automate this using Batch file (unsuccessful) then Power Shell (unsuccessful again). When I use these scripts, only 2/3rds of the file gets transferred. No error is being shown as well and transfer says complete.

See attached file for the file sizes.file_transfer.jpg
Is there a solution to this?

***********************************************************
Batch File
***********************************************************
/c ""C:\Program Files (x86)\WinSCP\WinSCP.com" /command "option batch on" "option confirm off" "option transfer binary" "open sftp://<user name>:<password>@<server address/path> -hostkey="*" " "put ""<File name & path here>"" " "close" "exit"


***********************************************************
Power Shell Script
***********************************************************
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"


$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = "XYZ"
        UserName = "ABC"
        Password = "PQR"
        SshHostKeyFingerprint = "BBB"
    }


# Connect
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
# …
0
Get your problem seen by more experts
LVL 11
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Hello Experts

Can someone show me how to compile a batch file that will run each time Windows  boots up?

I would like to run the following in a batch file

robocopy z:\mytestfolder c:\myhardfolder /move /minage:1

Regards
0
My default browser is launched when a batch calls this VB Script and refreshes as the application does not open instantly and needs refresh. But it is refreshing all the tabs. I want the particular tab to get refreshed with this particular URL and once the application is  open the refresh operation should stop. can it be done within this VB script.

My code:  

Option Explicit
      
      Dim myowmObj
      Dim ObservedPort
      Dim Counter
 
    Set myowmObj=WScript.CreateObject("WScript.Shell")
    ObservedPort = WScript.Arguments(0)
    myowmObj.Run "http://localhost:"&port&"/HatsDemo"
      'Wait for 3 seconds
      Wscript.Sleep 3000
     
      Counter = 20
      Do While Counter > 0
            Counter = Counter - 1
           
            'Send the F5 key for a refresh
            myowmObj.SendKeys "{F5}"
            'Wait for 2 seconds
            Wscript.Sleep 2000
      Loop
0
Hi All,

With the help of batch script i can rename the file extension but the original format remains same.Is there any command to open the
(.xls) files automatically from a folder and save it to (.xlsx) format without any manual intervention.

Please suggest.

Thanks,
Nithya
0
With robocopy, is it possible to move any files from the destination to another folder whenever the source file has been removed ?

1. Any files / folders in source will be synchronously exactly with that in destination.
2. Files / folders that are removed from the source will be moved to another folder

Thx
0
Looking to create an hourly Schedule task that will launch a script. The script will launch an app if a process is not running. The process will run as logged in user.
The program to launch  is  C:\Program Files\Google\Drive File Stream\25.102.133.409\GoogleDriveFS.exe
The Process name is GoogleDriveFS.exe

It's a Windows 10 PC.
What should the Batch script be.
0
Dears

Due to a mess up in mapping, a user in my domain was working for few days on his backup homefolder instead of his "live" homefolder.
So now I have 2 folders for that users with some file newer than other but in both ways...
How can I re-merge them and get a folder that has all his newest version of each file ?
PS: He has many sub-folders and his homefolder is around 20Gb.

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.