The Stack Overflow podcast is back! Listen to an interview with our new CEO.
87

You can use something like: $env:DOW = "foo"


68

Not natively but check out: http://mridgers.github.io/clink/ , makes cmd.exe much more productive. Quoting features from the project page: Powerful Bash-like line editing from GNU's Readline library. Superior path completion (TAB). Paste from clipboard (Ctrl-V). Support for the completion of executables/commands, and environment variables. Undo/Redo (Ctrl-_ ...


36

Powershell. PS C:\> netstat | Select -First 20 Edit: I have a feeling that you're going to insist that you're only able to use cmd.exe circa 1989, but that's not true. Powershell is baked into every OS version Vista+, and is installable on XP/2003. It is the future of Windows. Edit: Alright, have it your way. C:\> netstat -an > temp.txt &&...


35

Powershell and WMI. Get-WmiObject Win32_Process | Select ProcessId,CommandLine Or Get-WmiObject -Query "SELECT CommandLine FROM Win32_Process WHERE ProcessID = 3352" Note that you have to have permissions to access this information about a process. So you might have to run the command as admin if the process you want to know about is running in a ...


32

You can also press the following keys simultaneously to bring up the Task Manager - Ctrl + Shift + Esc Then, as xstnc said, File -> Run New Task -> cmd/powershell


29

Simply configure the Scheduled Task as "Run whether user is logged on or not".


25

Apparently you can add /Y and the shell knows to interpret that as supplying a default answer of "yes" to the prompt. net user MyUser MyPasswordIsReallyLong /ADD /Y


24

From the Technet article titled Manage a Server Core Server: If you close all command prompt windows and want to open a new Command Prompt window, press CTRL+ALT+DELETE, click Start Task Manager, click More Details, click File, click Run, and then type cmd.exe. Alternatively, you can log off and log back on.


22

You should run both commands in PowerShell as PowerShell is more than capable of manipulating environmental variables. I.e.: $dow = (get-date).dayofweek [Environment]::SetEnvironmentVariable("DOW", $dow, "Machine") or [Environment]::SetEnvironmentVariable("DOW", $dow, "User") By the way, your script doesn't work because all you're getting is the ...


21

Monitor the event logs on the domain controllers for event 672. It will show all successful logon events for AD users and which computer they logged on from. Filter by computer to get logon events for only those computers that you are interested in.


21

You can use the WMI subsystem, using WMIC.EXE to get to this information. Assuming a PID of 600: wmic.exe path Win32_Process where handle='600' get name, commandline /format:list You can also search for name, or other characteristic of the process. Use this command to list all attributes: wmic.exe path Win32_Process get /format:list


20

I encountered this problem too when trying to get the details of a service where the path to the executable was very long. This discussion contains a workaround; you can pass a buffer size as an argument to sc qc. That is, if you do: sc qc <service name> 5000 the "data area passed to a system call is too small" error goes away. Also see SC QC MSDN ...


20

I believe setting the environment variable from within PowerShell with [Environment]::SetEnvironmentVariable as suggested by Dan is pointless, because you would either lose the variable's content upon the termination of PowerShell if you chose the temporary "process" context or would not have it within your batch file's environment yet if you chose the ...


15

To use diskpart, there is no need to create an intermediate file. Try: echo list volume | diskpart


15

The other answers are certainly good options that will serve you well in an automated system because of their command line nature (and I see from the tag that that's what you wanted). Of course, some folks might want to explore this kind of info with a GUI, so here's an alternative along those lines. Process Explorer is a Sysinternals tool maintained by ...


14

Or from within Powershell: Start-Process powershell -Verb runas


14

To specify the interface in windows route command, you are supposed to use 'IF'... Uppercase letters, not lowercase. Also, where you are specifying you want to add a route to a single IP 192.168.0.6, you need to use a subnet mask of 255.255.255.255. The subnet mask of 255.255.255.255 specifies a single host. A subnet mask of 255.255.255.0 specifies 192.168....


13

I found an workable solution: reg query "HKLM\System\CurrentControlSet\Services\<serviceName>" /v "ImagePath" Of course this needs some parsing, but it gives me the full path that the services.msc dialog box provides.


13

Using built in tools on Windows you have a few options. Use the regedit GUI. Microsoft regedit provides import and export [export visible in your screenshot] options. When you export a key, it will appear in a .REG file. This is an example. example.reg Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\SOFTWARE\Example] [HKEY_CURRENT_USER\SOFTWARE\...


11

You can use clink. Clink combines the native Windows shell cmd.exe with the powerful command line editing features of the GNU Readline library, which provides rich completion, history, and line-editing capabilities. Easiest way to install clink is using chocolatey. Once you install chocolatey, you can install clink by typing choco install clink ...


11

You could make a logon script and link it in Group Policy for those computers that echos %date% %time% %username% %computername% to a file on a hidden share somewhere. Then you'll have a centralized log of all logins.


11

By far, the easiest way to go about this is through the use of the setx command, which is included in Windows 7/Server 2008 and up, or as part of the Windows Server 2003 Resource Kit for XP and Server 2003 systems. You can use the setx command to either specify an entirely new set of directories in the %PATH% variable, or append a value, using a little ...


11

You have 2 problems with your code: 1) IF only does a numeric comparison if the string on both sides evaluates to a number. Your left side is numeric, but your right side has quotes, which forces the entire comparison to be done using string semantics. Numeric digits always sort higher than a quote character, so it always reports TRUE. As austinian ...


11

Start your batch: powershell.exe -Command "Start-Process cmd -Verb RunAs" ... rest of script ... This will open an elevated command prompt Keep in mind for this to work the user would need to have admin privilege on the box. If the user is not a local admin you will have the use the /savecred switch, this is a big security hole as then the user and can ...


10

If you set a Scheduled Task to "Run only when user is logged on" and you are logged in as that user it will display the command window when the task is executed. If you set it to "Run whether user is logged on or not" it will hide the command window. I'm guessing this is the option you selected. I don't think there's a way to have it display the command ...


10

You can do this in PowerShell with a WMI query like this: $service = get-wmiobject -query 'select * from win32_service where name="winrm"'; echo $service.pathname This will give you the full path, including options as they are shown in services.msc. Just replace winrm in my example with whatever service you want to search for. The above query for winrm ...


10

I think using PowerShell might be the way to go. $srcStoreScope = "CurrentUser" $srcStoreName = "CA" $srcStore = New-Object System.Security.Cryptography.X509Certificates.X509Store $srcStoreName, $srcStoreScope $srcStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly) $cert = $srcStore.certificates -match "sometext" $...


10

This should work:  route add 192.168.0.6 mask 255.255.255.0 192.168.0.254 If you want persistence: route -p add 192.168.0.6 mask 255.255.255.0 192.168.0.254 Not sure what the "if" was for, but try this for cost: route add 192.168.0.6 mask 255.255.255.0 192.168.0.254 metric 13


9

On a commandline: tasklist /svc


9

You need to quote everything bar the extension "d:\workspace\Server trunk - CI\make\make & publish".bat


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