Thursday, March 20, 2008

Windows Command Line Tricks

Automatically Defragment C: Daily

schtasks /create /tn "Defrag C" /tr "defrag c: /f" /sc daily /st 23:00:00 /ru "System"

This will set your computer to automatically perform a complete defrag of the C: drive each day at 11:00:00 PM (23:00:00). It does this by creating a scheduled task called Defrag C. It will run this command under the computer’s system account.

---------------------------------------
Map A Drive Letter to a Folder
subst W: C:\Windows

Sometimes, your directory structure can get pretty deep and complicated. You can simplify this a bit by mapping a drive letter to commonly used folders. In the example that I have given, this will create a drive letter W: and map it to the C:\Windows directory. Then, whenever you go into My Computer, you will see a W: drive and when you browse to it, it will automatically take you to the contents of the C:\Windows folder.

You can do this with any unused drive letter and any folder that exists on your system.
-------------------------------------------

List All Tasks Running On The Computer

tasklist

It’s always good to know what is running on your system. This is the command line version of the processes tab in Taks Manager.
Kill A Program

taskkill /im programname.exe /f

If, when using the tasklist command, you discover that there is something running you just want killed. This is the way to do it! Just note the program name and use it in place of programname.exe.


--------------------------------------------
Reboot a Remote Computer

shutdown -r -f -m \\remotePC -c "System will be rebooted in 20 seconds"

Sometimes, you just need to reboot a system. This will do it remotely and give the user a 20 second warning.

---------------------------------------------
stopping and starting the print spooler

%windir%\System32\cmd.exe /c "net.exe stop Spooler && net start Spooler"

--------------------------------------------
To flush the DNS lookup cache (in case you’re using a dynamic DNS service for connecting to a remote machine etc.):

ipconfig /flushdns

If you’re using IIS for local web development and you need to restart the web server (to clear the application data, to fix a DLL problem etc.), don’t take the long trip through Control Panel -> Administrative Tools -> Internet Information Services etc. Simply issue:

iisreset
------------------------------------------------

runas /user:domain\user “cmd.exe /c shutdown -r -f -m 192.168.0.2 -t 1″

if you also supply the password it will not prompt
------------------------------------------------

1 comment:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Celulite, I hope you enjoy. The address is http://eliminando-a-celulite.blogspot.com. A hug.

OCgeeks Knowledgebase

OCgeeks News

Latest Tech News

Daily Techno-Babble