The tag has no wiki summary.

learn more… | top users | synonyms

82
votes
8answers
138k views

Run a .bat file in a scheduled task without a window

I have a scheduled task that starts a batch script that runs robocopy every hour. Every time it runs a window pops up on the desktop with robocopy's output, which I don't really want to see. I ...
20
votes
7answers
65k views

How do I restart a Windows service from a script?

I have a batch script that looks like: sc stop myservice sc start myservice it errors out because sc doesn't wait till the service is stopped. How do I restart a service with a script?
19
votes
4answers
68k views

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 :- ...
17
votes
13answers
49k views

How to get a list of drive letters on a system through a windows shell (bat, cmd)?

How do I get a list of drive letters and their associated labels on a windows system through a bat file?
14
votes
7answers
25k views

Is there a global, persistent CMD history?

Sometimes I forget how the exact syntax of a CMD command looks and then I would like to search my own CMD history. Clearly, within the same session, you can browse it with the up and down arrow keys ...
11
votes
4answers
21k views

System error 1219 has occurred

I am trying to connect to a remote server and deploy a service there, through a deploy script. I start by stating "Net use" and send the credentials for the server. But here I get system 1219 error: ...
11
votes
5answers
3k views

What's the difference between .cmd and .bat files?

Just curious. "Cool" people in our company always use *.cmd while no one was able to explain the difference to me.
8
votes
2answers
9k views

How to display the first N lines of a command output in Windows? (the equivalent of Unix command “head”)

I need to display the first N lines of the output of a command (any command). In other words, I esentially want an equivalent of the Unix "head" command. After discovering a few tricks from some other ...
7
votes
7answers
6k views

How to remove 'Administrator:' from the command promt title

In Windows Vista, is there a way to remove the word 'Administrator:' from the title of a command prompt window? The 'title' command just updates the part after 'Administrator:', so that will not do.
6
votes
2answers
4k views

How to launch a new cmd window from an existing cmd window?

Simply typing "cmd" keeps it in the same window. I'd also like to do "cmd /c command" and have it run in a separate window.
6
votes
3answers
14k views

Current date in the file name

I have scheduled backup script that makes the database dump. How can I add the date timestamp to the file name? I am talking about Windows and CMD.
6
votes
3answers
872 views

How to escape the > sign on Windows command line?

For example, foo -option 10->30 file.ext (this is an actual syntax required) redirects the output to a file named 30. How do I make cmd understand that I would like to pass the actual > character? ...
6
votes
2answers
294 views

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 ...
5
votes
6answers
2k views

How do I monitor who's logged in?

We in our department are implementing a new admin policy: everyone in a department which we support will receive admin access to their computers. We need to know (while we are performing this "pilot ...
5
votes
11answers
64k views

Windows command prompt: how to get the count of all files in current directory?

What command would you use in cmd.exe to find the number of files in the current directory? Is there a powershell option here? Update: I was hoping to avoid dir, as I know there are 10,000+ files in ...
5
votes
7answers
19k views

How do you handle “CMD does not support UNC paths as current directories”?

I am attempting to change directories to a file server such as: cd \\someServer\\someStuff\ However, I get the following error: CMD does not support UNC paths as current directories What ...
5
votes
2answers
4k views

Windows: How do I add a program to the system's path environmental variable from the command line?

I'm looking to permanently add a directory to the %PATH% environmental available on a large number of Windows machines. Is there any way to do this from a command line (cmd) so I can script up a ...
5
votes
6answers
15k views

How do I set an environmental variable from a powershell command?

I want to have a 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 ...
5
votes
4answers
5k views

Correct technique to find application in 32 and 64 bit versions of Vista/Windows 7 from CMD.EXE

BACKGROUND I have an existing CMD script that works fine. It launches an app from PROGRAM FILES like so "%PROGRAMFILES%\MyApp\app.exe" PROBLEM it works fine on 32-bit versions of Windows (Vista, ...
5
votes
1answer
5k views

Looking to add the “Log On as a service” right to an account via the command line

I am looking to make a user from the command line with minimal rights to run a service. cmd.exe or powershell.exe are both options, but cmd.exe is preferable. So far I got this: net user /add ...
5
votes
2answers
1k views

Is there a Windows CMD equivalent of Unix shell's exec?

Is there any equivalent in Windows to Unix Shell's "exec"? Basically, I need to avoid forking a new process, so that input/output pipes are preserved, as well as process id. Edit: So, here's my ...
5
votes
1answer
5k views

Windows: redirect stdout and stderror to nothing

I have a command I am running produces a ton of output, I want to silence the output without writing to a file. I have used the following to send all output to a file, but again I don't want any file ...
4
votes
2answers
2k views

Windows Server 2008 - Calling FTP from .CMD - Pass a parameter to an FTP file?

I am calling the following from a .cmd file: ftp -d -s:D:\backup\web-daily.txt The web-daily.txt file is an ftp input file with similar contents to this: open <server> <login> ...
3
votes
6answers
14k views

remotely check amount of RAM on a computer using command line

How would I remotely check the amount of RAM on a computer using command line? (Windows XP and/or windows server 2003)
3
votes
3answers
15k views

How to Run multiple command remotely using PSEXEC?

I am try to use multiple command with psexec tools but i am only remotely entered in that computer but it won't be perform another command psexec -i \\192.168.30.135 -u username -p password cmd ...
3
votes
4answers
9k views

How can I get the path to a Windows service executable WITHOUT using sc qc?

I need to query a windows service for the path to it's executable via the command prompt. I think the way I would do this is:sc qc myServiceName, but when I do that, I get the following error: ...
3
votes
1answer
2k views

Get error code of last shell command

Using bash, the exit code of the last thing that executed is stored in the $? shell variable: foo bar echo $? # prints exit code of `bar` baz echo $? # prints exit code of `baz` Is there an ...
3
votes
2answers
4k views

How to run x64 bit version of registry from cmd.exe located under c:\windows\sysWow64

I have a 32 bit application which has to add a value to x64 bit portion of the registry. I want to do it through utilization of regedit.exe -s fileWithKeys.reg, However when I try to span regedit ...
3
votes
2answers
2k views

How to enable ANSI escape codes in Windows cmd?

What is the simplest way to enable ANSI escape codes (eg. colored output) in Windows cmd?
3
votes
3answers
619 views

How are “locked” files handled by the system (i.e. WinXP)?

How exactly are locked files handled by the os ? Or to be precise, why is it that sometimes I cannot delete a locked file from a Windows Explorer, but if I open a command prompt in the directory in ...
3
votes
1answer
480 views

Save output and exit code of command to files on windows

I want to run a command and save its output and its exit code, in different files. Here's what i am doing: cmd.exe /C command 1> %TEMP%\output.log 2> %TEMP%\error.log && echo ...
3
votes
2answers
1k views

Difference between UnxUtils and GNU CoreUtils

I am a Windows user who wants programs like grep and sed along with other utilities like ls, cut etc in my command prompt. I came across 2 packages which would accomplish this UnxUtils GNU ...
3
votes
5answers
421 views

windows-server-2003, windows server, download utility from command line , http or ftp or any other protocol , from one command only

I need to know if there is a utility built-in to Windows Server 2003 that I can use from the command line to download a file using only one command. Basically I know that I can download from ftp using ...
3
votes
1answer
111 views

Redirect command line into its own output?

Windows CMD shell - any easy way of redirecting the command itself into the output? If I do net localgroup administrators > %computername%-admins.txt, I'd like the output file to contain the net ...
3
votes
1answer
639 views

Why powershell runs executables in separate window?

On one of my servers (2008 R2) powershell refuses to run executables without extension, so typing cmd (or &cmd) in command prompt results in folowing error message: The term 'cmd' is not ...
3
votes
2answers
123 views

Visual APP to run CMD commands

I make use of the command prompt quite a bit, but I've noticed that it has really poor support for copying and pasting. Usually I get around this by creating a batch file, then executing that. What ...
3
votes
3answers
3k views

Win7 command processor (CMD.EXE) really slow

Does it seem to anyone else that the Windows 7 command processor (CMD.EXE) is really slow starting up? I ran this test from a command line (ntimer is a timing utility from the Windows server resource ...
3
votes
0answers
791 views

DSGET escapes hash signs (#) in outputted Distinguished Names (DN)s but expects unescaped hash signs for input

Lets say I want to do the very simple query in AD dsquery user -name "John Smith" | dsget user -memberof -expand This will output the DNs of the AD groups that this user belongs to. I can make it ...
2
votes
1answer
3k views

What happens when you type Exit in the CMD window on Server Core in an RDP session

I'm getting used to Server Core and I know at some point I am going to type "Exit" in the command window while connected through a remote desktop session. I know that if this is done while connected ...
2
votes
3answers
744 views

Using a for loop in Microsoft cmd.exe, how can I process only the files with a certain extension?

I have a the folder c:\test\ and two files in it a.txt and b.txtv. I would like to process just the files with extension equal to .txt. If I write this commands cd c:\test for %f in (*.txt) do echo ...
2
votes
4answers
17k views

Unlock AD User Account using DSMOD (command line)

Just a quick question. I need to be able to unlock user accounts from the command line, NOT using NET USER loginname /DOMAIN /ACTIVE:YES This is because our corporation lives across 4 domains, and ...
2
votes
5answers
9k views

command line - switch to administrator mode

Is it possible to switch from normal mode to administrator mode in command line? I don't want to open command line by right clicking and selecting "run as administrator". Thanks
2
votes
1answer
2k views

Force “net user” command to set password longer than 14 characters

I'm issuing some "net user" commands to setup a local user on my desktop for some testing purposes and require setting a password longer than 14 characters. In doing so Windows barks back a propmt to ...
2
votes
4answers
7k views

How to run an elevated command prompt from the command prompt?

I have remotely connected to a Windows 7 computer via psexec and am running a remote command prompt on the Windows 7 computer. The command I am trying to execute requires that it be run in an elevated ...
2
votes
3answers
4k views

Copy windows shared file from cmd

Is there a downloading tool that supports Windows Shared files and works from command line? Standard copy is getting hanged with no action on my side. Tried wget but seems it doesn't 'eat' the link.
2
votes
1answer
93 views

set unlimited lease duration throuth CMD

On Windows Server 2008 (R2, 32-Bit, I found the following way to set the lease duration for, say, 3600 Seconds (1 Hour). netsh dhcp server scope 10.0.0.0 set optionvalue 51 DWORD 3600 [→ source] ...
2
votes
2answers
532 views

Recursive CMD or BAT Windows Script

How can I create a BAT or CMD which will iterate through a folder tree and run same command agaists each folder file? E.g myexe.exe C:\Documents and Settings\folder1\filename.txt myexe.exe ...
2
votes
1answer
38 views

NET USE - How to get list of all shares (elevated, non-elevated)

The command: NET USE Will display open connections by any process of current user. But, if command prompt (cmd.exe, or any shell) is non-elevated, it would display only connections opened by ...
2
votes
1answer
96 views

How to remove directories using wildcards by reading a file using batch?

Batch file for /f "delims=" %%f in (7profiledeletelist.txt) do rd /s /q "%%f" PAUSE exit 7profiledeletelist.txt C:\Users\1* C:\Users\2* C:\Users\3* C:\Users\4* C:\Users\5* C:\Users\6* C:\Users\7* ...
2
votes
1answer
51 views

Command Line Script Issue

I've been working on a batchfile script for a few weeks now that should automate certain routine tasks I need to perform during my work. However, I've stumbled upon a problem which I haven't been able ...