Skip to main content
20 votes
Accepted

call batch file and run using its own path/directory

You are a bit unclear where app1.exe is located. If it shares the folder with run1.bat change run1.bat to either @Echo off Pushd "%~dp0" app1.exe popd or @Echo off "%~dp0app1.exe" %0 refers to ...
LotPings's user avatar
  • 1,073
18 votes

How to sleep in a batch file?

You can sleep in Batch using powershell: Milliseconds powershell -nop -c "& {sleep -m Milliseconds}" Seconds powershell -nop -c "& {sleep seconds}"
wasif's user avatar
  • 341
11 votes

Change current directory to the batch file directory

You can do pushd "%~dp0" to go to the directory of a batch file -- even if it's on another drive. Additionally, that allows you to popd to go back to where you came from.
idbrii's user avatar
  • 213
10 votes

Rename files to add date modified to filename with Windows CMD or simple .TXT

In Powershell you can do this with a One-Liner: Get-ChildItem |Foreach-Object { Rename-Item $_ -NewName ("{0}-{1}{2}" -f $_.BaseName,$_.LastWriteTime.ToString('yyyyMMdd'),$_.Extension) } Explanation:...
Gerald Schneider's user avatar
6 votes

Change directory to "This PC" / "Computer" from .BAT batch file

This works on windows 10, I am not sure if it is version specific. explorer = Also: explorer.exe /e,::{20D04FE0-3AEA-1069-A2D8-08002B30309D} explorer /root,
Anthony Fornito's user avatar
6 votes

Is it safe to write batch files with Unix line endings?

Kinda, but... You will have to be a paranoid and always duplicate your label lines! never use colons outside of label definitions! Eg.: @echo off goto main <- No use of colon ... :main :main <...
Simon Streicher's user avatar
5 votes

Robocopy - All data marked as modified

After lots of trial and error I think I found the reason: the Archive attribute. When Robocopy comes across a file with the Archive attribute set, it will systematically display the file as "Modified"...
jcharaoui's user avatar
  • 352
5 votes
Accepted

How to get all processes under a session of a particular process that is using a port in Windows cmd

That's actually pretty easy in PowerShell: # Get the process of the listening NetTCPConnection and the session ID of the process $SessionId = (Get-Process -Id (Get-NetTCPConnection -State Listen -...
Gerald Schneider's user avatar
4 votes
Accepted

How to check that mstsc.exe has successfully set up a RDP connection?

You can check if the RDP logon was sucessful by querying the security log of the target system. Logon events are ID 4624, RDP logons are type 10. Other logon types https://www.ultimatewindowssecurity....
Clayton's user avatar
  • 4,663
4 votes

call batch file and run using its own path/directory

The answer to your question can be drawn from a similar question on Stack Overflow. What is the current directory in a batch file? Using the variables mentioned here, you can update run1.bat to call ...
Sam Erde's user avatar
  • 3,549
3 votes
Accepted

Windows batch file scripting: how to get directory named with latest date (yyyy-mm-dd format)?

for /f %%d in ('dir /ad /o-n /b .') do ( echo %%d goto break ) :break /ad - Displays files with specified attributes. (D: Directories) /o-n List by files in sorted order. (n: By name (alphabetic),...
k010mb0's user avatar
  • 251
3 votes

How to sleep in a batch file?

Disclaimer: this is not the "ideal" solution, so don't bother beating me over the head with that like done to those recommending ping... When possible, use timeout for sure. But as noted in the ...
BuvinJ's user avatar
  • 419
3 votes
Accepted

Command understanding in Batch script

That one line has a lot of functionality in it. An plain-English summary would go something like this: Ask Java what version it is. This gives multiple pieces of information. Find the line in Java's ...
Doug Deden's user avatar
  • 1,946
2 votes

How do you wait for an exe to complete in batch file?

I had the problem @John Gardeniers Had or described, where my exe called another exe and terminated, therefor start /wait didn't work. I created a "while loop" to check if its running and then move on ...
FreeSoftwareServers's user avatar
2 votes

How can I edit local security policy from a batch file?

I looked for so long too. I figured out the answer! To check the current state : auditpol /get /subcategory:"Process Creation" This next line will make the change. It will set the process creation ...
OatBoat's user avatar
  • 21
2 votes

slmgr.vbs supress dialog

As suggested in this post: https://stackoverflow.com/questions/41423512/batch-file-i-want-to-supress-the-windows-script-host-pop-ups add '//b' to your command. That suppresses the popup. e.g. ...
trindflo's user avatar
  • 131
2 votes

How to get an EC2 Windows machine's instance-id into a batch variable

So I found another way of doing this: $instanceId = Get-EC2InstanceMetadata -Path '/instance-id' It seems a lot cleaner and result contains just what you expect "Instance ID"
Borik's user avatar
  • 121
2 votes

Windows Task Scheduler job not starting but runs on manual start

This highlights the difference in behavior between a “Daily” task and a “One time” task. This is a bit counterintuitive, but if you want to be able to disable a task, then have it start firing ...
Paul Smith's user avatar
2 votes

How to uncheck the Validate server certificate option on the Authentication tab in the Network Connection on windows 10 via command line?

The simplest way, in my opinion, to deploy a WLAN or LAN profile is the following: Create the profile with the GUI on your computer Start a command prompt and use: netsh wlan show profiles to show all ...
Swisstone's user avatar
  • 7,093
2 votes

How to uncheck the Validate server certificate option on the Authentication tab in the Network Connection on windows 10 via command line?

I don't know with a script, but if you have an Active Directory environment, you can do it from a group policy. I've accomplished that by using the GPMC. Create a new Group Policy, name it. The ...
Jorge Valentini's user avatar
2 votes

Robocopy - All data marked as modified

You can add /a-:a to the robocopy commandline to remove the archive bit during the process.
user534618's user avatar
2 votes

Batch - Extract string before the specified character

for extract string before hyphen (special charcter) you need used for @echo off set string=1.0.10-SNAPSHOT echo %string% for /f "tokens=1 delims=-" %%a in ("%string%") do ( echo %...
MohammadReza moeini's user avatar
2 votes
Accepted

cmd - run a batch file after all other concurrent batch files finish

Stop using the antiquated command prompt and use Powershell. You can use the ThreadJob module, as described in this excellent answer on SO: $commands = { ./run_part1.bat }, { ./run_part2....
Gerald Schneider's user avatar
1 vote

remotely destroy all data windows 7

Short than PXE booting or using USB with a special Linux distribution to destroy the data on the drives, the best option that comes to my mind would be encrypting all the drives with BitLocker or ...
Andre de Miranda's user avatar
1 vote

Copy files and folders by specific days of the month

You can use the below command in a text file: robocopy sourcePath destinationPath *.* /e /r:0 /w:0 /np Then save the text file and change the file to cmd file. After that, you can create a ...
Sadabadi's user avatar
  • 358
1 vote

Windows Command - Delayed Expansion Syntax to Echo The VALUE of a Variable That Contains Another Number Variable

The solution to this problem is that the $project!$project_number!_control variable must undergo double expansion in order to return its value. Exclamation marks cannot be used more than once with a ...
Bill Vallance's user avatar
1 vote
Accepted

Copy single file using robocopy

Huh, I'm not sure, but it looks like it can be permissions issue, see here http://blogs.technet.com/filecab/archive/2008/07/31/robocopy-mir-switch-mirroring-file-permissions.aspx For me ...
Johnyd's user avatar
  • 172
1 vote
Accepted

How to create a batch file which after some time execute a file but if interrupted execute another?

See choice /? in a cmd window or read choice :: Q:\Test\2017\08\31\SF_871434.cmd @echo off :loop Cls Echo Select office version to install Echo( Echo [1] Install Microsoft Office 2007 Echo [2] ...
LotPings's user avatar
  • 1,073
1 vote

Run an executable on a remote computer with a batch file

It sounds like you are looking for PSEXEC. https://docs.microsoft.com/en-us/sysinternals/downloads/psexec I use PSEXEC all the time in BAT scripts to restart services, install MSIs, change IIS ...
Dre's user avatar
  • 1,874
1 vote

Is it safe to write batch files with Unix line endings?

I have a GitHub project that is a single, pure batch file. When downloaded from GitHub using the "raw" feature, it serves the file with LF line endings regardless of how I save the file. I'...
Brogan's user avatar
  • 111

Only top scored, non community-wiki answers of a minimum length are eligible