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


Windows Batch





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 Scheduled reboot if User is Logged Off.


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.

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.

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:
DISPLAY_NAME: ArcSoft Connect Daemon
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
. . . . .

DISPLAY_NAME: Ac Profile Manager Service
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
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.
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 (
        [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) 
            Start-Sleep -Milliseconds $WaitTime

Open in new window

Kindly find the above attached code.

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=

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

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

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

REM No password entered
set pstring=

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 …
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 .
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@ -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              

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?
I've been tasked with finding a backup solution for Yammer (Office 365), and thought it was "job done" when I found this article:


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


    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 
    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 
    :: Don't foget the replace the underscore with the colons to ensure correct ISO-8601 formatting

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

I am trying to take a value in a CSV file and then search the rest of the file for that value and replace it with another value.  This is a small portion of the file (see attached); so on line one you have these values
"061", "Blaze",      "blaze.jpg","015, 019, postman-joyner.jpg" & "aaron.jpg gingerland.jpg candidum-jr.jpg"
I want to take the 3rd value (blaze.jpg) and then look for blaze.jpg in 4th and 5th columns and in all the rows of those two values/columns and replace it with "061" -- the first value in the row. The goal is to end up with no names in values 4 or 5 (or columns 4 & 5) and have them replaced by values from the first value. So wherever the name blaze.jpg shows up in the rest of the file, have it replaced by the corresponding value in value/column 1 -- hope that makes sense. I did a few of them manually so you can see what happens in columns 4 & 5.
We have a very very old labeling program that the electrical department would like to keep using (The printer works and they still have tons of labels in supply) but the program is dos 32bit and the company is no longer in business. Their computer is windows 10 64 bit. I cannot run a 32 bit dos program in windows 64 bit command prompt (at least haven't been able to) so I installed virtual box and installed Doss 6.22. The program works fine but i cannot get it to access lpt1. does anyone know the steps involved (in windows 10 and in the vbox dos) to allow the doss 6.22 to print to lpt1?
Free Tool: Site Down Detector
LVL 11
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.

I cannot for the life of me get a bat file to run through GPO. I have stored the file on the file server in a public share, in netlogon on the DC, in the actual script folder within the policy object, ran with various switches. I have also used another bat file to call the actual bat file. The bat file will run fine manually, but not when logging on. This is a script provided by the software company used for installing one component. Any tips?
here the link:https://github.com/quarkslab/quarkspwdump
and here the usage:
quarks-pwdump.exe <options>
	Options : 
	-dhl  --dump-hash-local
	-dhdc --dump-hash-domain-cached
	-dhd  --dump-hash-domain (NTDS_FILE must be specified)
	-db   --dump-bitlocker (NTDS_FILE must be specified)
	-nt   --ntds-file FILE
	-hist --with-history (optional)
	-t    --output-type JOHN/LC (optional, if no=>JOHN)
	-o    --output FILE (optional, if no=>stdout)
	Example: quarks-pwdump.exe --dump-hash-domain --with-history

Open in new window

i can't see anywere ''quarks-pwdump.exe''
I need help creating a Script that will Check if the Uptime(Hours) is exided on Windows 10 Operating Systems. I am not that Scripting guy just a newbie in the Scripting world.The following will be the Parameters I would like to have:

Parameter 1 specifies after how many hours without rebooting the user is asked via a message box  to restart their computer themself or to shut down .

Parameter 2 specifies after how many hours without restarting will the script plan an automatic restart in 60min (with no prompt for cancelling)

The script must be controllable with at least two parameters
Thank You in Advance
how to automatically re-connect to rdp session,see pic
any powshell,vbs script?
thank you

I have a file in production server every month I am downloading the file to my local and zipping.

Finally sending this file via FileLink to the person manually. Cant we make this task automate?

1. File will be avilable in one of the production server on /abc/test/test.psp
2. Our job should check the file in the location and download the file to local machine.
3. Once the file got downloaded, the file should be delivered to the user via Outlook or Filelink.

Please share your advise.


I have  a EXCEL Macro in my desktop we are daily double clicking that report and moving to First sheet(Sheet 1) and pressing CNTRL+D to download the files from the Share drive.  As a first step.

Also when it is getting update it will ask for save , dont save , Cancel message and we are clicking Save and it will get update automatically and get idle for sometime.

When we click the EXCEL CLOSE button, it will ask for save the sheet WILL click save. After that the sheet will get close automatically.

Need to automate this process. This is one of the pending daily reports which we have not automated.

Thanks for your help in advance.
I am trying to deploy Intune to all the computers in my company.  Unfortunately, MS requires the user to be a local admin to join Intune.  These are all AD Domain Joined.  I am looking for a way to give the logged in user local admin rights, have them connect to Intune with their username and password and then remove them from the local admin group.  So far I have this for my script:

Net localgroup administrators “domain\%username%” /add
Start ms-device-enrollment:?mode=mdm
Timeout 300
Net localgroup administrators “domain\%username%” /delete

It works fine if a domain admin right clicks and runs the batch file as administrator.  I would like it run as a logon script one time.  I also tried to copy the file to common startup folder so it would run at logon, but get access denied on the first line.  The rest of the script runs without error.  Has anyone had success joining computers to Intune without manually making users local admins?
Hi all...

I've tried finding what I need but most solutions offer various entries and switches on a vbs script or batch file.

I need to delete one single registry key if it is present. The key is as an example:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Application Plugins\DATALOSS1000

How can I accomplish this, and run it remotely on approximately 300 systems?

Batch file preferred...

Thanks in advance...
i need a batch file to create this path: C:\Windows\winwin123
this path already exist: C:\Windows\  but the folder called  ''winwin123 '' must be created ,afetr is created i want to go there: C:\Windows\winwin123
Upgrade your Question Security!
LVL 11
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

I have a FTP transfer from a server to the client(server). It is using a bat file and a .scr file which runs the script. When I run it it goes to ftp command prompt and it stops there. It  was running well in a Sql server 2000. When upgraded to SQL server 2008 R2.
The script is as follows.  (IP Address, user and password have been obscured)

KAinsert. bat runs KAinsert.scr
Opens Command Prompt.

ftp> ftp
put kafada05

We are using a software to generate some results in a .csv format.
If a run the program using the .bat file from the Windows user, it keep the program configuration.

When whe run the .bat file with PHP exec function, the .csv file is generating but it don't keep the program configuration.
Maybe Wamp or PHP don't use the registry configuration of the program ?

Someone has any idea ?

All my best,
As topic says - I'm looking for a way to disable a very specific usb port when I'm running the batch file, or any other method. It just has to be a file that enables / disables the usb port.
Also I'm using win7

thanks in advance!
I am trying to get Trend Micro statistics written out to a text file with a batch file.

pccntmon.exe -c >> File.txt
pccntmon.exe -v >> File.txt

I see that the pccntmon.exe app seems to start a new command line when it is executed so only the flags are passed to the exe.  I am sure that this is due to ensuring that the app is not compromised by some easy silly code.  I have many servers over Win 2K3 and up to gather this info.  I do not have access to the central admin server.

I have tried the following :
start /wait cmd /c "C:\Program Files\Trend Micro\OfficeScan Client\pccntmon.exe" -c >> C:\<desktop>\file.txt
start /B /wait "C:\Program Files\Trend Micro\OfficeScan Client\pccntmon.exe" -c >> C:\<desktop>\file.txt

Open in new window

This opens a new window and displays the agent info in the console only.  
Also, after the pccntmon.exe executes it is expecting a user to hit "Enter" on the keyboard.  I think I can approach this with a bit of  Jscript.

set SendKeys=CScript //nologo //E:JScript "%~F0"

%SendKeys% "start /wait cmd /c "C:\Program Files\Trend Micro\OfficeScan Client\pccntmon.exe" -c >> C:\<desktop>\file.txt"


// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");

Open in new window

But I got to get past the first part first.  Any direction is appreciated.
Here is the batch file I am running:

@echo off
set /p filename=Please enter the filename you want copied:
xcopy \\server\D$\folder1\folder2\%filename%     \\server2\folder3\folder4

I have two users with identical permissions on the network, servers, and individual machines.  One user can use the batch file successfully, and one it says that the drive is invalid.

Any thoughts would be helpful.
I need to set permissions on multiple computers so that the permission will not affect the folder or subfolders but the inheritance will still apply to the files within those folders.

ex:  c:\temp\scratch\sub\ needs to have permissions applied so that users can't delete either the "scratch" or "sub" folders but can add and delete files within them.  

According to Microsoft you need to use the "OI" and "IO" commands together but they don't give examples, any examples I've found online don't appear to work.   It should read something like "cacls c:\temp\scratch /G everyone:(IO)(OI)(C).  I've also tried the icacls version with no success, I've also tried only using the "C" (change) permission without the IO & OI but the folder can still be deleted.

Has anyone gotten this to work?

Windows Batch





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.