Questions tagged [batch]

A batch file is the name given to a type of script file, a text file containing a series of commands to be executed by the command interpreter under MS-DOS and Microsoft Windows.

This was the first extension used by Microsoft for batch files. This extension runs with MS-DOS and all versions of Windows, under COMMAND.COM or cmd.exe, which execute its commands, normally line-by-line.

338 questions
186
votes
5 answers

How to sleep in a batch file?

How to pause execution for a while in a Windows batch file between a command and the next one?
Massimo
  • 68,714
  • 56
  • 196
  • 319
62
votes
7 answers

Windows command prompt: how do I get the output of a command into a environment variable?

I want to have an environment variable that contains the day of week in cmd.exe. When I run this command I get the result I want. C:\Users\tisc> powershell (get-date).dayofweek Friday Here I'm trying to store the result in an environment…
Tim
  • 721
  • 1
  • 5
  • 8
37
votes
4 answers

Get directory containing the currently executed batch script

I use %0 in batch file to get the containing directory of the batch file but the result is :- c:\folder1\folder2\batch.bat I want just directory, without batch file name, like this :- c:\folder1\folder2\ How can I do it? Maybe I should filter the…
34
votes
3 answers

For Loop counting from 1 to n in a windows bat script

I need to run a windows command n times within a bat script file. I know how to do this in various programming languages but cannot manage to get it right on the windows command line :-( I would expect something like either for(int i = 0; i < 100;…
raoulsson
  • 4,633
  • 10
  • 32
  • 29
26
votes
7 answers

How to create a never expiring password & user via net user through .bat file

I am using a .bat file to create a user and password at windows operating system level. The issue am facing is when i pass EXPIRES:NEVER for password, when the user is created, it doesn't have "Password never expires" checkbox checked (meaning the…
Sharpeye500
  • 373
  • 1
  • 3
  • 5
26
votes
13 answers

Need leading zero for batch script using %time% variable

I came across a bug in my DOS script that uses date and time data for file naming. The problem was I ended up with a gap because the time variable didn't automatically provide leading zero for hour < 10. So running> echo %time% gives back: '…
Ira
  • 363
  • 1
  • 3
  • 4
23
votes
4 answers

Locale-unaware %DATE% and %TIME% in batch files?

The %DATE% and %TIME% environment variables provide the current date and time on Windows machines on the command line and inside a batch file. Sadly, those values are locale-aware! Meaning that, say, on a German machine, you will get…
Pekka
  • 2,158
  • 3
  • 19
  • 32
20
votes
4 answers

How do I extract all archives in the subdirectories of this folder?

How do I extract multiple archives in contained in subdirectories in a folder, outputting the results back into the folders where the archives are.
Dmitri Farkov
17
votes
2 answers

call batch file and run using its own path/directory

I have a batch files that calls other batch files like this: e:\foo\master.bat has the content: call e:\bar\run1.bat and e:\bar\run1.bat has the content app1.exe the problem is that when I run the master.bat app1.exe will not be executed, because…
Omu
  • 327
  • 2
  • 6
  • 19
13
votes
8 answers

Program does not run properly as Scheduled Task

Situation I have a batch script that prepares some files, executes a program (.exe) and then deletes said files. This task should run hourly, so I'm trying to configure this using Scheduled Tasks. The problem is that the previously mentioned program…
12
votes
8 answers

Expire Files In A Folder: Delete Files After x Days

I'm looking to make a "Drop Folder" in a windows shared drive that is accessible to everyone. I'd like files to be deleted automagically if they sit in the folder for more than X days. However, it seems like all methods I've found to do this, use…
Brett G
  • 2,023
  • 1
  • 27
  • 45
10
votes
23 answers

Finding day of week in batch file? (Windows Server 2008)

I have a process I run from a batch file, and i only want to run it on a certain day of the week. Is it possible to get the day of week? All the example I found, somehow rely on "date /t" to return "Friday, 12/11/2009", however, in my machine, "date…
Daniel Magliola
  • 1,402
  • 9
  • 20
  • 33
9
votes
1 answer

Shutdown script doesn't run if workstation is not connected to the network

I have a requirement to run a batch script every time a system is shut down, no matter if the computer is connected to the network or not. (It shouldn't matter for the question, but the script in question clears the print queue of the…
Per von Zweigbergk
  • 2,615
  • 2
  • 17
  • 27
9
votes
3 answers

How can I create an ODBC connection from .bat file in Windows?

I need a batch script to create an ODBC/DSN connection from a .bat file in Windows. How can I do this?
Jhonathan
  • 195
  • 1
  • 1
  • 4
8
votes
4 answers

Determine if C drive has 2 GB of free disk space

I am trying to determine if a target pc has atleast 2 GB of free space. Here is what I have so far: @echo off for /f "usebackq delims== tokens=2" %%x in (`wmic logicaldisk where "DeviceID='C:'" get FreeSpace /format:value`) do set…
1
2 3
22 23