28

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 for input until the .exe is finished


26

Since it applies here, too, I'll copy my answer from another site. If you want to use ping, there is a better way. You'll want to ping an address that does not exist, so you can specify a timeout with millisecond precision. Luckily, such an address is defined in a standard (RFC 3330), and it is 192.0.2.x. This is not made-up, it really is an address with ...


22

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 that the below options are select/checked or unchecked just as shown in Print Screen A Uncheck Run only when user is logged on Check Run whether user is ...


17

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 the currently running batch and the modifier ~dp returns drive and path (with a trailing backslash.)


11

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:\path\to\your\file } And now you have your file name stored in a variable


10

You can sleep in Batch using powershell: Milliseconds powershell -nop -c "& {sleep -m Milliseconds}" Seconds powershell -nop -c "& {sleep seconds}"


10

setlocal enabledelayedexpansion enableextensions set LIST= for %%x in (%baseDir%\*) do set LIST=!LIST! %%x set LIST=%LIST:~1%


8

FOR ANYONE STILL FINDING THIS QUESTION, YOU CAN USE POWERSHELL: Grant-SmbShareAccess -Name example -AccountName Administrators -AccessRight Full -Force Grant-SmbShareAccess -Name example -AccountName Everyone -AccessRight Change -Force HERE IS MY ORIGINAL PRE-POWERSHELL ANSWER: I recently needed to do this for multiple home shares in order to restrict 'Full ...


8

Calling via cscript also works cscript C:\Windows\System32\slmgr.vbs /ato


8

Yes, you can deploy batch files via Group Policy that will run under the context of Local System. A very common way of doing so is Computer Startup scripts. (As opposed to User Logon scripts.) Also, this is probably the worst possible way imaginable of blocking Facebook. From http://technet.microsoft.com/en-us/library/cc770556.aspx Startup scripts are ...


8

Powershell: Get-WmiObject Win32_Process | Select Name, ProcessId, CommandLine


8

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 common local account with an identical password on every computer in a domain. LAPS resolves this issue by setting a different, random password for the common local ...


7

It's not ideal, but you could have a separate task that just writes the username to a log file at the same time, and correlate the logs later. For that matter, since the task runs at login, this information is already available in the event logs. If you're really desparate to not correlate these later, you could add code (or a step) to the existing task to ...


6

Here is an example using MATLAB! I have assumed that the path setup for MATLAB is done and MATLAB exit is being ensured by the FileName.m file (or user has specified it internally). echo off matlab -nosplash /r "FileName.m" :loop tasklist /fi "imagename eq MATLAB.exe" |find ":" > nul if errorlevel 1 goto loop exit


6

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: Get-ChildItem: Gets all items in the directory. You could add -Recurse to get files from sub directories too Foreach-Object: Run the following code block ...


6

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

It seems that batch labels are skipped when LF (Unix line-ending) is used in a .bat file.


5

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. The label parser fails to find a label, if the label is on a 512 byte boundary relative to the current file position. The difference is, because the carriage ...


5

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.


5

Classic batch mistake :-) The SET command is working fine. It is your expansion that is failing. %VAR% expansion occurs when the statement is parsed, and all commands within the FOR loop are parsed at once. The same is true for any parenthesized block of code. So the values of %fullpath% and %basename% are constant throughout the execution of the FOR loop -...


5

This is a classic delayed expansion issue. Type help set or set /? from the command prompt for a discussion about delayed expansion (a bit past half way down the full help). Normal expansion using %var% occurs when the line is parsed. The problem is your entire FOR loop block is parsed in one pass. So you are seeing a constant value that existed before the ...


5

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. For example, you have an installer for the program "Example" and the installer is "Example_install.exe." The vendor doesn't provide any command line switches ...


4

I have been able to setup such a thing a few year ago...but cannot remember how ! So i have powered back on my old VM to check. I have used the srvany.exe utility that comes with the Windows 2003 ressource kit. This utility is not really supported on recent version of Windows but works on Windows 2008 R2. From the previous link, note this important point :...


4

You don't specify whether these machines are part of an Active Directory domain or not. I'll assume that they are not. You don't specify what version of Windows you're running. The pre-Vista and post-Vista cataclysm is huge. It's practically an entirely different operating system. You can't just say "Windows" since Windows has changed a lot in its 20+ year ...


4

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 of deployment system - SCCM, Patch Manager, Puppet, etc - but there is a quick and dirty solution available if you have a 2008+ domain. Basically it is ...


4

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: added naming examples, the # is a comment, only leave one $name = uncommented at a time, if you uncomment multiple, it will be the last uncommented one that ...


4

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.com/securitylog/encyclopedia/event.aspx?eventid=4624 $user2find = "santaClaus" $target = "server1234" Get-winevent -comp $target -FilterHashtable @{Logname='...


4

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 app1.exe with the following line: %~dp0app1.exe. (The %~dp0 variable includes a trailing slash.) This will tell the batch file to run the executable from the ...


4

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 -LocalPort 8081).OwningProcess).SessionId # Get all processes from that session and stop them Get-Process | Where-Object { $_.SessionId -eq $SessionId } | Stop-...


3

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 comments, that's not always an option (e.g. in non-interactive mode). After that, I agree that the ping "kludge" is perhaps the next best option, as it is very ...


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