30
votes
How do you wait for an exe to complete in batch file?
One shorter way:
Install.exe|more
Also
install|rem
could be used , though with more eventually you'll be able to catch some console output. And this is the reason it works - the piped command waits ...
22
votes
Accepted
Running a Batch File from Task Scheduler Without User being logged In
TASK SCHEDULER: SCHEDULED BATCH SCRIPT NOT RUNNING
Task Scheduler Properties. . .
From Windows Task Scheduler on the job Properties (see bottom most screen shots) in the. . .
1. General tab, ensure ...
17
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 ...
16
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}"
12
votes
Change Windows network share permissions using command-line tools
FOR ANYONE STILL FINDING THIS QUESTION, YOU CAN USE POWERSHELL:
Grant-SmbShareAccess -Name example -AccountName Administrators -AccessRight Full -Force
Grant-SmbShareAccess -Name example -AccountName ...
11
votes
Check for file by wildcard and store as variable in batch file
Doesn't directly answer your question about a batch file but this would work easily in a PowerShell script:
$validFile = Test-Path "C:\path\to\your\file"
if ($validFile -eq 'True') {
$path = C:\...
10
votes
Check for file by wildcard and store as variable in batch file
setlocal enabledelayedexpansion enableextensions
set LIST=
for %%x in (%baseDir%\*) do set LIST=!LIST! %%x
set LIST=%LIST:~1%
9
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) }
...
8
votes
Accepted
How to query the task manager
Powershell:
Get-WmiObject Win32_Process | Select Name, ProcessId, CommandLine
8
votes
Is there a way to change passwords on multiple servers simultaneously?
If the servers are on the domain.
Local Administrator Password Solution
Microsoft is offering the Local Administrator Password Solution (LAPS) that provides a solution to the issue of using a ...
6
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.
6
votes
Is it safe to write batch files with Unix line endings?
It seems that batch labels are skipped when LF (Unix line-ending) is used in a .bat file.
6
votes
Is it safe to write batch files with Unix line endings?
For batch files there is no big difference between unix line endings and windows line endings.
Currently, there is only a glitch known for the behavior of GOTO and CALL, while searching for a label.
...
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,
5
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 <...
5
votes
How can I install any program unattended on a Windows PC?
Most Windows installers were created with packagers that do have undocumented command line switches; you just need to trial and error them. I usually use this page to get a list of common switches.
...
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 -...
4
votes
Accepted
copy file with date appended
Your %date% contains some reserved character(s), e.g. / (forward slash). As %date% strongly depends on user's locale settings, I'd use next locale-independent solution with date in yyyymmdd format:
...
4
votes
Accepted
Run Log-on Script with Admin Rights
This is a poor use case for login scripts. A startup script or a scheduled task can both easily run as the SYSTEM account take care of your software installation.
Generally I suggest using some kind ...
4
votes
Accepted
Script for renaming files and adding a timestamp (server 2012 r2)
This bit of powershell does what you want. Just put the full path to the source and destination directories at the top between the quotation marks.
Edit: added the bit about file creation time.
Edit: ...
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....
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 ...
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 ...
3
votes
How to see what last batch was run on windows
Windows doesn't have a simple log for started processes. One thing that comes close is the Registry key UserAssist:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist
It ...
3
votes
Accepted
Is there a way to change passwords on multiple servers simultaneously?
You could also use PsPasswd from the SysInternals suite. PsTools tend to have a few dependencies (like maybe a default share or something) but they're usually pretty stable. It's worth noting it does ...
3
votes
Accepted
Rename files to add date modified to filename with Windows CMD or simple .TXT
Here is the code you need to use to iterate the text files, obtain the modified date of each file, copy each file using the modified date as part of the file name, and delete the original files. You ...
3
votes
Accepted
Batch file IF %time% not working
Try this:
SET "ADJUSTEDTIME=%TIME: =0%"
IF "%ADJUSTEDTIME:~0,5%" GEQ "19:58" GOTO :SHUTDOWN
IF "%ADJUSTEDTIME:~0,5%" LSS "08:58" GOTO :SHUTDOWN
GOTO :EOF
:SHUTDOWN
MSG * "Your device has not ...
3
votes
Accepted
Trigger a batch file when a user choose "Switch User" in windows
Best choice is to configure Advanced security audit policy and windows will register for you events about:
User logon
Workstation lock/unlock
User logout
and many others that may be useful to you.
...
3
votes
Accepted
Run a batch file from network shared folder depending on MS outlook bit version
While debugging batch scripts, don't just launch them by clicking the icon, but from the command line (cmd.exe). Otherwise, you won't get to see the error messages. Now, for the actual problems...
...
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)...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
batch-file × 439windows × 174
batch × 64
windows-command-prompt × 46
scripting × 44
windows-server-2008 × 37
command-line-interface × 37
powershell × 31
windows-7 × 29
scheduled-task × 26
windows-server-2003 × 24
windows-server-2008-r2 × 22
group-policy × 19
windows-xp × 18
vbscript × 14
task-scheduler × 13
active-directory × 12
permissions × 12
windows-server-2012-r2 × 10
batch-processing × 10
backup × 9
robocopy × 9
windows-server-2012 × 8
ms-dos × 8
networking × 7