Loading
Showing posts with label Windows7. Show all posts
Showing posts with label Windows7. Show all posts

Tuesday, December 8, 2009

Getting the Most out of Windows Command Prompt

If you are like me you use the command prompt a lot.  It seems each time I logon to a new system I have to setup the command prompt just the way I want.  The first thing I do is create a shortcut in the Quick Launch toolbar.  Next I modify that shortcut so it will better suit my needs.

Right-click the shortcut and select Properties.  On the Shortcut tab add " /f:on" (without the quotes) to the Target - make sure there is a space between cmd.exe and /f:on, and if cmd.exe ends with a quote place the /f:on outside the quotes. This will enable file and directory name completion characters - you can use Ctl + d for directories and Ctl + f for files.  I also like to set the Start In target to C:\.



Click the Options tab.  I like to increase the command history buffer to at least 100, this is especially useful if you have a command prompt open for a long time and want to scroll back through your previous commands.  Check discard old duplicates to, well, do just that.  And check QuickEdit mode.  This is a great one as it enables selecting text directly and pasting directly (with right-click) without having to right-click and select copy and/or paste.



Personally I don't change the fonts or colors, but you may prefer different settings.  Play around, have fun.

Now click the Layout tab.  I normally increase the height and width of the window size a bit, especially with today's higher resolution monitors.  And I definitely increase the screen buffer size height, usually to a couple thousand or more.  Make sure to increase the screen buffer width to at least match that of your window size width.



I usually leave "Let System Position Window" checked so Windows will tile subsequent command prompt windows:



See also:

CMD.exe /? (help) in Windows 7
Starts a new instance of the Windows command interpreter


CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string]

/C      Carries out the command specified by string and then terminates
/K      Carries out the command specified by string but remains
/S      Modifies the treatment of string after /C or /K (see below)
/Q      Turns echo off
/D      Disable execution of AutoRun commands from registry (see below)
/A      Causes the output of internal commands to a pipe or file to be ANSI
/U      Causes the output of internal commands to a pipe or file to be Unicode
/T:fg   Sets the foreground/background colors (see COLOR /? for more info)
/E:ON   Enable command extensions (see below)
/E:OFF  Disable command extensions (see below)
/F:ON   Enable file and directory name completion characters (see below)
/F:OFF  Disable file and directory name completion characters (see below)
/V:ON   Enable delayed environment variable expansion using ! as the
        delimiter. For example, /V:ON would allow !var! to expand the
        variable var at execution time.  The var syntax expands variables
        at input time, which is quite a different thing when inside of a FOR
        loop.
/V:OFF  Disable delayed environment expansion.

Note that multiple commands separated by the command separator '&&'
are accepted for string if surrounded by quotes.  Also, for compatibility
reasons, /X is the same as /E:ON, /Y is the same as /E:OFF and /R is the
same as /C.  Any other switches are ignored.

If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic is
used to process quote (") characters:

    1.  If all of the following conditions are met, then quote characters
        on the command line are preserved:

        - no /S switch
        - exactly two quote characters
        - no special characters between the two quote characters,
          where special is one of: &<>()@^|
        - there are one or more whitespace characters between the
          two quote characters
        - the string between the two quote characters is the name
          of an executable file.

    2.  Otherwise, old behavior is to see if the first character is
        a quote character and if so, strip the leading character and
        remove the last quote character on the command line, preserving
        any text after the last quote character.

If /D was NOT specified on the command line, then when CMD.EXE starts, it
looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if
either or both are present, they are executed first.

    HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun

        and/or

    HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun

Command Extensions are enabled by default.  You may also disable
extensions for a particular invocation by using the /E:OFF switch.  You
can enable or disable extensions for all invocations of CMD.EXE on a
machine and/or user logon session by setting either or both of the
following REG_DWORD values in the registry using REGEDIT.EXE:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\EnableExtensions

        and/or

    HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions

to either 0x1 or 0x0.  The user specific setting takes precedence over
the machine setting.  The command line switches take precedence over the
registry settings.

In a batch file, the SETLOCAL ENABLEEXTENSIONS or DISABLEEXTENSIONS arguments
takes precedence over the /E:ON or /E:OFF switch. See SETLOCAL /? for details.

The command extensions involve changes and/or additions to the following
commands:

    DEL or ERASE
    COLOR
    CD or CHDIR
    MD or MKDIR
    PROMPT
    PUSHD
    POPD
    SET
    SETLOCAL
    ENDLOCAL
    IF
    FOR
    CALL
    SHIFT
    GOTO
    START (also includes changes to external command invocation)
    ASSOC
    FTYPE

To get specific details, type commandname /? to view the specifics.

Delayed environment variable expansion is NOT enabled by default.  You
can enable or disable delayed environment variable expansion for a
particular invocation of CMD.EXE with the /V:ON or /V:OFF switch.  You
can enable or disable delayed expansion for all invocations of CMD.EXE on a
machine and/or user logon session by setting either or both of the
following REG_DWORD values in the registry using REGEDIT.EXE:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\DelayedExpansion

        and/or

    HKEY_CURRENT_USER\Software\Microsoft\Command Processor\DelayedExpansion

to either 0x1 or 0x0.  The user specific setting takes precedence over
the machine setting.  The command line switches take precedence over the
registry settings.

In a batch file the SETLOCAL ENABLEDELAYEDEXPANSION or DISABLEDELAYEDEXPANSION
arguments takes precedence over the /V:ON or /V:OFF switch. See SETLOCAL /?
for details.

If delayed environment variable expansion is enabled, then the exclamation
character can be used to substitute the value of an environment variable
at execution time.

You can enable or disable file name completion for a particular
invocation of CMD.EXE with the /F:ON or /F:OFF switch.  You can enable
or disable completion for all invocations of CMD.EXE on a machine and/or
user logon session by setting either or both of the following REG_DWORD
values in the registry using REGEDIT.EXE:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\CompletionChar
    HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\PathCompletionChar

        and/or

    HKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar
    HKEY_CURRENT_USER\Software\Microsoft\Command Processor\PathCompletionChar

with the hex value of a control character to use for a particular
function (e.g.  0x4 is Ctrl-D and 0x6 is Ctrl-F).  The user specific
settings take precedence over the machine settings.  The command line
switches take precedence over the registry settings.

If completion is enabled with the /F:ON switch, the two control
characters used are Ctrl-D for directory name completion and Ctrl-F for
file name completion.  To disable a particular completion character in
the registry, use the value for space (0x20) as it is not a valid
control character.

Completion is invoked when you type either of the two control
characters.  The completion function takes the path string to the left
of the cursor appends a wild card character to it if none is already
present and builds up a list of paths that match.  It then displays the
first matching path.  If no paths match, it just beeps and leaves the
display alone.  Thereafter, repeated pressing of the same control
character will cycle through the list of matching paths.  Pressing the
Shift key with the control character will move through the list
backwards.  If you edit the line in any way and press the control
character again, the saved list of matching paths is discarded and a new
one generated.  The same occurs if you switch between file and directory
name completion.  The only difference between the two control characters
is the file completion character matches both file and directory names,
while the directory completion character only matches directory names.
If file completion is used on any of the built in directory commands
(CD, MD or RD) then directory completion is assumed.

The completion code deals correctly with file names that contain spaces
or other special characters by placing quotes around the matching path.
Also, if you back up, then invoke completion from within a line, the
text to the right of the cursor at the point completion was invoked is
discarded.

The special characters that require quotes are:
    
     &()[]{}^=;!'+,`~

Monday, December 7, 2009

Create Windows Shortcuts With a Script at the Command Line

If you are like me you 1) access numerous Windows computers, in my case mainly servers through Remote Desktop; and 2) like to have your Windows desktop setup a certain way.  Here are some examples of a quick and easy way to create shortcuts with a script.  These examples are Visual Basic Scripts (.vbs) and use Windows Script Host to execute.  Create any or all of the examples and execute it from either the command prompt or Start / Run using:
wscript xyz.vbs
Note: These scripts were all tested on Windows 7, Windows 2008 and 2003.  They should run fine on earlier versions of Windows (XP, Vista, 2000, etc.) as well.

Although most of these examples will create shortcuts to Windows Explorer (the last one is a shortcut to the Command Prompt), they are being placed in different locations.  Of course you could modify the examples to launch any program of your choosing.  Additionally you could combine them into one script that could be launched the first time you logon.

For easy reference I highlighted the values you may want to change to tailor the script to your needs.

Windows 7, Vista and Windows 2008 Server note: You will probably have to execute these with administrative rights.  One way to do this is to launch a command prompt (the old fashioned way - Start [All] Programs / Accessories / Command Prompt) using right-click and selecting "Run As Administrator."






Example 1 - Shortcut to Windows Explorer in the "All Users" Desktop folder.  I named the script Explorer_Shortcut_on_AU_Desktop.vbs.
set WshShell = WScript.CreateObject("WScript.Shell" )
strDesktop = WshShell.SpecialFolders("AllUsersDesktop" )
set oShellLink = WshShell.CreateShortcut(strDesktop & "\Windows Explorer.lnk" )
oShellLink.TargetPath = "%SYSTEMROOT%\explorer.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "%SystemRoot%\explorer.exe"
oShellLink.Description = "Windows Explorer"
oShellLink.WorkingDirectory = "%HOMEPATH%"
oShellLink.Save
Example 2 - Shortcut to Windows Explorer in the "All Users" Start Menu folder.  I named the script Explorer_Shortcut_in_AU_Startmenu.vbs.
set WshShell = WScript.CreateObject("WScript.Shell" )
strStartMenu = WshShell.SpecialFolders("AllUsersStartmenu" )
set oShellLink = WshShell.CreateShortcut(strStartMenu & "\Windows Explorer.lnk" )
oShellLink.TargetPath = "%SYSTEMROOT%\explorer.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "%SystemRoot%\explorer.exe"
oShellLink.Description = "Windows Explorer"
oShellLink.WorkingDirectory = "%HOMEPATH%"
oShellLink.Save
Example 3 - Shortcut to Windows Explorer in the "All Users" Startup folder.  I named the script Explorer_Shortcut_in_AU_Startup.vbs.  This will cause one instance of Windows Explorer to launch during logon.  If you're like me you will be using it anyway, so why not have it open automatically.
set WshShell = WScript.CreateObject("WScript.Shell" )
strStartup = WshShell.SpecialFolders("AllUsersStartmenu" )
set oShellLink = WshShell.CreateShortcut(strStartup & "\programs\startup\Windows Explorer.lnk" )
oShellLink.TargetPath = "%SYSTEMROOT%\explorer.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "%SystemRoot%\explorer.exe"
oShellLink.Description = "Windows Explorer"
oShellLink.WorkingDirectory = "%HOMEPATH%"
oShellLink.Save
Example 4 - Shortcut to Windows Explorer in the "Current User" Quick Launch toolbar.  I named the script Explorer_Shortcut_in_CU_QuickLaunch.vbs.
set WshShell = WScript.CreateObject("WScript.Shell" )
strStartup = WshShell.SpecialFolders("AppData" )
set oShellLink = WshShell.CreateShortcut(strStartup & "\Microsoft\Internet Explorer\Quick Launch\Windows Explorer.lnk" )
oShellLink.TargetPath = "%SYSTEMROOT%\explorer.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "%SystemRoot%\explorer.exe"
oShellLink.Description = "Windows Explorer"
oShellLink.WorkingDirectory = "%HOMEPATH%"
oShellLink.Save
Example 5 - Shortcut to Command Prompt in the Quick Launch toolbar for you, the current user.  I named the script CMD_Shortcut_in_CU_QuickLaunch.vbs.
set WshShell = WScript.CreateObject("WScript.Shell" )
strStartup = WshShell.SpecialFolders("AppData" )
set oShellLink = WshShell.CreateShortcut(strStartup & "\Microsoft\Internet Explorer\Quick Launch\Command Prompt.lnk" )
oShellLink.TargetPath = "%SYSTEMROOT%\system32\cmd.exe"
oShellLink.WindowStyle = 1
oShellLink.Hotkey = "Ctrl+Alt+C"
oShellLink.IconLocation = "%SystemRoot%\system32\cmd.exe"
oShellLink.Description = "Windows Command Prompt"
oShellLink.WorkingDirectory = "%HOMEPATH%"
oShellLink.Save
See also:

Alternatives to HyperTerminal in Windows 7 and Vista

Beginning with Windows Vista Microsoft removed HyperTerminal (aka HyperTerm & Hyper Terminal).  Of course, this means it isn't in Windows 7 either. There are several options you can use to replace its functionality.
  • PuTTY - My Recommendation
    • PuTTY is a free implementation of Telnet and SSH for Win32 and Unix platforms, along with an xterm terminal emulator.
  • WinRS (Windows Remote Shell)
    • If you only need remote shell access, you can use WinRS which was introduced in Windows Vista. To get help and see execution options with WinRS, run winrs /? at a command prompt.
  • Telnet is a simple, text-based program that you can use to connect to other devices over your local network or over the Internet.  Telnet can be executed right from the command prompt, although you may have to enable it in Control Panel.

  • Phone and Modem Options can be used to troubleshoot modem problems
    • Open Phone and Modem Options by clicking the Start button, Control Panel, Hardware and Sound, finally Phone and Modem Options.
  • Realterm is a terminal program specially designed for capturing, controlling and debugging binary and other difficult data streams. It is far better for debugging comms than Hyperterminal. It has no support for dialing modems, etc – that is what hyperterminal does.

  • TeraTerm is another alternative to HyperTerminal.  Tera Term is a free software terminal emulator (communication program) which supports:



    • Serial port connections.
    • TCP/IP (telnet, SSH1, SSH2) connections.
    • IPv6 communication.
    • VT100 emulation and selected VT200/300 emulation.
    • TEK4010 emulation.
    • File transfer protocols (Kermit, XMODEM, ZMODEM, B-PLUS and Quick-VAN).
    • Scripts using the "Tera Term Language".
    • Japanese, English, Russian and Korean character sets.
    • UTF-8 character encoding.



  • AbsoluteTelnet Telnet, SSH, and SFTP Client.  AbsoluteTelnet / SSH is a secure flexible terminal client that is suitable for developers, administrators, or deployment across the enterprise. It includes the industry standard SSH protocols to secure terminal session data across insecure environments such as the internet. Its new tabbed interface is a favorite among AbsoluteTelnet users.

  • XP's Hyper Terminal
    • If you really want (or just can't be without it) you can still use XP's Hyper Terminal. Just copy the following two files from an existing XP, Windows 2000 or 2003 box or extract them from the installation CD's of the previous OS's: hypertrm.dll and hypertrm.exe. Although you could put them anywhere on the disk as installation is not required, you may want to place them in %SYSTEMROOT% (normally C:\Windows\System32).

Sunday, December 6, 2009

RichCopy - RoboCopy GUI (sort of) by Microsoft

RichCopy is a free utility from Ken Tamaru of Microsoft. The tool was first developed in 2001 and has been updated regularly to keep pace with evolving needs.  Worthy of note is that RichCopy is a multithreaded copying tool. That means that rather than copying one file at a time in serial order, RichCopy can open multiple threads simultaneously, allowing many files to be copied in parallel and cutting the total time required to complete the operation several times over. You can also pause and resume file copy operations, so if you lose network connectivity at any point, you can just pick up where you left off.

Of course, these are really just the simplest features of RichCopy. As the figure below shows, you also get a vast array of granular controls that allow you to customize all of those fancy aspects of your file copying —filtering files, saving attributes, adjusting cache size, and so on. If you regularly copy lots of files over the network or between various storage devices, these features will significantly ease your daily life.



Download RichCopy.

For those of you like me who prefer the command line see the following about RoboCopy:

Thursday, December 3, 2009

Ultimate Windows Tweaker v 2.0 for Windows 7 and Vista

Ultimate Windows Tweaker v 2.0 is a freeware Tweak UI Utility for tweaking and optimizing Windows 7 & Windows Vista, 32-bit & 64-bit. It can simply be downloaded and used as a portable application to customize your Windows to meet your requirements. With judicious tweaking, it can make your system faster, more stable, and more secure with just a few mouse clicks. The tweaker detects whether you have Windows 7 or Windows Vista installed and accordingly offers you only the relevant tweaks.




The tweaker is a 345KB .exe file which does not require an install, yet packs over 150 tweaks & settings. Simply download the zip file, extract its contents and run Ultimate Windows Tweaker. Please don’t detach Empty Icon from executable’s root, the Empty Icon is copied to system directory and referred in runtime. The tweaker has been designed by Ramesh Kumar for The Windows Club.

Download Ultimate Windows Tweaker.  More information.




Sunday, November 29, 2009

Disable/Enable User Access Control (UAC) on Windows 7 or Vista from the Command Line

Microsoft introduced User Account Control (UAC) in Windows Vista. UAC enables users to perform common tasks as non-administrators, called standard users in Windows (Vista and Windows 7), and as administrators without having to switch users, log off, or use Run As. A standard user account is synonymous with a user account in Windows XP. User accounts that are members of the local Administrators group will run most applications as a standard user. By separating user and administrator functions while enabling productivity, UAC is an important enhancement for Windows.

Disable UAC from the command line
%systemroot%\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f
Enable UAC from the command line
%systemroot%\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 1 /f
A couple caveats
  1. Must be run with administrative rights.  You could right-click on Command Prompt shortcut and select Run as Administrator.
  2. You may have to reboot for changes to take affect.
You can also enable or disable UAC from the Control Panel.

IIS 7 Log Files Default Location

In Internet Information Services 7 Microsoft changed the default log files location.

IIS 7 Log files location
%SystemDrive%\inetpub\logs\LogFiles
IIS 6 Log files location
%windir%\System32\LogFiles

How to Add Quick Launch to Windows 7 Task Bar

By default Windows 7 does not display quick launch on the taskbar like Windows XP and Vista.

How to Enable Quick Launch in Windows 7
  1. Right-click on taskbar.
  2. From Toolbars Menu select New Toolbar.
  3. Under Folder add: %appdata%\Microsoft\Internet Explorer\Quick Launch then press Select Folder.
How to Unlock the Taskbar
  1. Unlock the taskbar by right-clicking on taskbar and select unlock the taskbar.
  2. To lock, do the same but select lock the taskbar.
Taskbar options
In Windows 7 quick launch you can choose whether to display the title and to show text or not.  To change these settings unlock the taskbar, right-click in the quick launch area of the taskbar and toggle Show Text and Show Title as desired.

How to Install and Configure IIS 7 FTP Publishing Service

The new FTP Publishing Service 7.5 has been rewritten for Windows Server 2008 and lot of new futures and additions included. (Integration with IIS 7, FTP over SSL (from v7.0), Improved Logging, etc..)

Prerequisites
1. Internet Information Services 7.0 installed.
2. Windows Server 2008 or Vista.
3. Download FTP Publishing Service 7.5
4. Create a folder for FTP Publishing Service and allow Full access for Administrators
  • mkdir “c:\inetpub\ftproot\ftp.mydomain.com”
  • cacls “c:\inetpub\ftproot\ftp.mydomain.com” /G administrators:F /T /E
In case we want to add access to specific backup user we can use the following command”
  • cacls “c:\inetpub\ftproot\ftp.mydomain.com” /G username:F /T /E
Permissions:
R  Read
W  Write
C  Change (write)
F  Full control
Installation
Before installing FTP Publishing Service 7.5 over IIS 7.0 be sure that you uninstall any previous versions of FTP Publishing Service.

  1. When the installation program of Microsoft FTP Service for IIS 7.0 begins, click Next.
  2. Accept the End-User License Agreement and click Next.
  3. Select the features you want to be installed and click Next.
  4. Click Install to begin the installation.
  5. At the end click Finish.

Creating the Certificate
After the installation finishes we open Internet Information Services 7.0  Manager and we select Server Certificates to create a self-signed SSL certificate. Another option is to create a certificate request to process with a 3rd party SSL provider which is recommended for production systems as they are from a trusted root.

Server Certificates

Click on Create Self-Signed Certificate…

Create a self-signed certificate

Specify a certificate name and click OK:

Specify certificate name


Creating the FTP Site
Right click the Sites node in the tree and click Add FTP Site…

Add FTP Site...

On the Add FTP Site wizard add the FTP site name and select the path we created in the prerequisites and click Next.

Add FTP Site Wizard

On the next page of the wizard we click the Require SSL option and we choose our SSL Certificate then we click Next.

Binding and SSL Settings

On the next page of the wizard we select Basic for Authentication and on Allow access to we select specified users and we define our backup ftp account with read and write permissions then we click on Finish. In case we want to allow anonymous ftp connections select Anonymous authentication and on Permissions we select the Read.

Authentication and Authorization Information


Configure the Firewall
If we are behind a firewall we should configure the FTP Firewall Support under Internet Information Services Manager and configure our firewall ports to accept passive connections on the ports we specify. In case we want to use dynamic port range under Data Channel Port Range we enter port range “0-0?.

FTP Firewall Support


Configure the FTP Client (FileZilla for example)
Configure FTP Client to connect to our FTP Site using FTP over explicit TLS/SSL.

FTP Client Settings


Troubleshooting
In case you get “534 Local policy on server does not allow TLS secure connections.” error this is because we need to select an SSL certificate at the Server Level.

FTP SSL Settings Server Level
FTP SSL Settings Certificate Selection

Tuesday, November 17, 2009

Reveal, Copy and Get File Full Path with Copy as Path in Windows Vista

Windows 7 (and Vista) comes with a hidden context-sensitive menu or right click menu or shortcut menu that contains Copy as Path menu item or command. Copy as Path, which appears as menu item both for files and folder right click menu, as the name implies, will copy or grab the full path or shortcut to the file or the folder with just one button press and one click. Copy as Path is useful when user want to know the full path or actual location of a file or folder located deep inside a tree of directories or network file share, but want to avoid the hassle to traverse or navigate the path, or avoid having to manually copy and paste from address bar and type the file name.

To use Copy as Path press shift while right-clicking which will reveal the hidden context menu. You will now see the Copy as Path and a couple other options. Click on Copy as Path, then you can paste the full path to the file or folder in your destination application.



Right click context menu without and with hidden menu items (appear only when press Shift key while right clicking).

Thursday, October 22, 2009

Windows 7 Global Launch

Windows 7, Microsoft's newest operating system goes on sale around the world. (Bloomberg News)

This Bloomberg video brought to you by News Distribution Network.

Microsoft Windows 7 OS Takes Off

High hopes for Microsoft's latest operating system platform, Windows 7. Components communities keep their fingers crossed. (The Trade)

This Bloomberg video brought to you by News Distribution Network.

Microsoft Windows 7 OS Faces Piracy

Microsoft feels strongly about piracy, especially in China, and faces this problem head on. (The Trade)

This Bloomberg video brought to you by News Distribution Network.

Microsoft Launches Retail Store

Microsoft takes a new financial risk by getting into retail despite the economy. (The Trade)

This Bloomberg video brought to you by News Distribution Network.

Monday, October 5, 2009

Windows 7 (and Windows 2008) Command Line Utility to Change Time Zone

Here is a great hidden command line utility which is available starting in Windows 7, "tzutil.exe," which can be used to view or change the computer's Time Zone. To use this command:

1. Open the Command Prompt.
2. Enter any of following commands:
tzutil /g (To view current time zone)
tzutil /l (To get a list of all available time zones)
tzutil /s time_zone_ID (To change time zone)
time_zone_ID is the new time zone you want to set. Fox example, if you want to set the time zone to "Eastern Standard Time", then the command would be:
tzutil /s "Eastern Standard Time"
See also Set Time Zone From Command Line in Windows 2003, XP and 2000

Monday, August 31, 2009

Windows 7 Command Line Utility for Timezone Management - tzutil.exe

"tzutil.exe" is a command line utility introduced in Windows Vista (also in Windows 7 and Windows 2008) which can be used to change Time Zone or to view the current time zone information. To use this command (from a command prompt as administrator):
tzutil /g - To view current time zone
tzutil /l - To get a list of all available time zones
tzutil /s <time_zone_ID> - To change time zone
time_zone_ID is the new time zone which you want to set. For example, if you want to set the time zone to Eastern, Central, Mountain or Pacific Daylight Time, you would use any of the following:
tzutil /s "Eastern Daylight Time"
tzutil /s "Central Daylight Time"
tzutil /s "Mountain Daylight Time"
tzutil /s "Pacific Daylight Time"
Windows change timezone command.

Friday, August 21, 2009

Creating Bootable Vista / Windows 7 USB Flash Drive

This will walk through the steps to create a bootable USB flash drive. These instructions assume that you are running Windows Vista or Windows 7.

Required:
  • USB Flash Drive
  • Microsoft OS Disk (Vista / Windows 7)
  • A computer running Vista / Windows 7

Step 1: Format the Drive
Warning: This will erase everything on your USB drive.

  1. Open a command prompt as administrator (Right click on Start > All Programs > Accessories > Command Prompt and select “Run as administrator” - you must do this or it may not work, displaying the message: "Could not map drive partitions to the associated volume device objects"
  2. Find the drive number of your USB Drive by typing the following into the Command Prompt window:
    - diskpart
    - list disk
    The number of your USB drive will listed. You’ll need this for the next step. I’ll assume that the USB flash drive is disk 1.
  3. Format the drive by typing the next instructions into the same window. Replace the number “1” with the number of your disk below.
    - select disk 1
    - clean
    - create partition primary
    - select partition 1
    - active
    - format fs=NTFS
    - assign
    - exit
    When that is done you’ll have a formatted USB flash drive ready to be made bootable.

Step 2: Make the Drive Bootable
Next we’ll use the bootsect utility that comes on the Vista or Windows 7 disk to make the flash drive bootable. In the same command window that you were using in Step 1:

  1. Insert your Windows Vista / 7 DVD into your drive.
  2. Change directory to the DVD’s boot directory where bootsect lives:
    - d:
    - cd d:\boot
  3. Use bootsect to set the USB as a bootable NTFS drive prepared for a Vista/7 image. I’m assuming that your USB flash drive has been labeled disk G:\ by the computer:
    - bootsect /nt60 g:

Step 3: Set your BIOS to boot from USB
This is where you’re on your own since every computer is different. Most BIOS’s allow you to hit a key at boot and select a boot option.

Monday, August 17, 2009

Schedule Windows reboot (restart) from command line with schtasks

Schedule one-time reboot:
schtasks /create /tn "Reboot" /tr "shutdown /r /t 1" /sc once /st 01:00:00 /sd 08/18/2009 /ru "System"
Create scheduled task to run twice daily:
schtasks /create /tn "TTF" /tr "C:\Temp\T\ttf.bat" /sc daily /st 06:00:00 /sd 08/25/2009 /ri 720 /du 720 /ru "System"
Create scheduled task to run every weekday, M-F:
schtasks /create /tn "Reboot" /tr "shutdown /r /t 1" /sc WEEKLY /d "MON, TUE, WED, THU, FRI" /st 01:00:00 /sd 08/18/2009 /ru "System"
To update an existing scheduled task run the same command as above with any desired modifications. You will be prompted with, "WARNING: The task name "Reboot" already exists. Do you want to replace it (Y/N)?"

Upon successful creation the OS will report, "SUCCESS: The scheduled task "Reboot" has successfully been created."

You can also update an existing scheduled task from the Windows command line:
schtasks /change /tn "Reboot" /st 04:00:00 /sd 12/11/2009
Schtasks supports the following options
SCHTASKS /Change [/S system [/U username [/P [password]]]] /TN taskname
     { [/RU runasuser] [/RP runaspassword] [/TR taskrun] [/ST starttime]
       [/RI interval] [ {/ET endtime | /DU duration} [/K] ]
       [/SD startdate] [/ED enddate] [/ENABLE | /DISABLE] [/IT] [/Z] }

Description:
    Changes the program to run, or user account and password used
    by a scheduled task.

Parameter List:
    /S       system      Specifies the remote system to connect to.

    /U       username    Specifies the user context under which schtasks.exe
                         should execute.

    /P       [password]  Specifies the password for the given user context.
                         Prompts for input if omitted.

    /TN      taskname    Specifies which scheduled task to change.

    /RU      username    Changes the user name (user context) under which the
                         scheduled task has to run. For the system account,
                         valid values are "", "NT AUTHORITY\SYSTEM" or "SYSTEM".
                         For v2 tasks, "NT AUTHORITY\LOCALSERVICE" and
                         "NT AUTHORITY\NETWORKSERVICE" are also available as well
                         as the well known SIDs for all three.
    /RP      password    Specifies a new password for the existing user
                         context or the password for a new user account.
                         This password is ignored for the system account.

    /TR      taskrun     Specifies the new program that the
                         scheduled task will run.

    /ST      starttime   Specifies the start time to run the task. The time
                         format is HH:mm (24 hour time) for example, 14:30
                         for 2:30 PM.

    /RI      interval    Specifies the repetition interval in
                         minutes. Valid range: 1 - 599940 minutes.

    /ET      endtime     Specifies the end time to run the task. The time
                         format is HH:mm (24 hour time) for example, 14:50
                         for 2:50 PM.

    /DU      duration    Specifies the duration to run the task. The time
                         format is HH:mm. This is not applicable with /ET.

    /K                   Terminates the task at the endtime or duration time.

    /SD      startdate   Specifies the first date on which the task runs.
                         The format is mm/dd/yyyy.

    /ED      enddate     Specifies the last date when the task should run.
                         The format is mm/dd/yyyy.

    /IT                  Enables the task to run interactively only if the
                         /RU user is currently logged on at the time the job
                         runs. This task runs only if the user is logged in.

    /RL      level       Sets the Run Level for the job. Valid values are
                         LIMITED and HIGHEST. The default is to not change it.

    /ENABLE              Enables the scheduled task.

    /DISABLE             Disables the scheduled task.

    /Z                   Marks the task for deletion after its final run.

    /DELAY   delaytime   Specifies the wait time to delay the running of the
                         task after the trigger is fired.  The time format is
                         mmmm:ss.  This option is only valid for schedule types
                         ONSTART, ONLOGON, ONEVENT.

    /?                   Displays this help message.

Schtasks Examples:
    SCHTASKS /Change /RP password /TN "Backup and Restore"
    SCHTASKS /Change /TR restore.exe /TN "Start Restore"
    SCHTASKS /Change /S system /U user /P password /RU newuser /TN "Start Backup" /IT


Set up your laptop for work: Turn off the crap

When it comes to setting up your work laptop, I suggest that you should only care about speed and efficiency. This means that your computer should be (a) booting up quickly, and (b) running smoothly (without crashes).

The key to a quick startup is minimising the number of programs that run automatically when you bootup Windows. Click the Start button, then Run, and type msconfig. Click on the Startup tab and deselect all of the programs that you do not want to run automatically. For more detailed advice, I refer you to the excellent Make XP Boot Faster from Wikihow.

In order to keep your computer running smoothly you should turn off all of the useless services that run by default in Windows XP. I recommend that you read A Guide To Turning Off Useless XP Services by JasonN and make the necessary changes. If in the future MARCS students begin using Windows Vista *shudder* then I recommend you find a similar guide for turning off all of the useless crap in Vista.

Windows Command Line Tricks

Here are a few Windows command line tricks that might make your life easier.

Save A List of Files to a Text File by Extension

dir *.ext /s /b > files.txt

This command line will create a file called files.txt. When you open this file, there will be a complete list of all the files in that directory and all subdirectories with the .ext extension. You can then open up this text file in any text editor and work this the information.By changing the ext part, you can select different files. For example, if you wanted to list all of the PDF documents, you would type:

dir *.pdf /s /b > files.txt


Get Your IP Address Information

ipconfig /all

This will retrieve a pile of information about your network connection and IP information. From this command, you can get:

* Host Name
* Primary DNS Suffix
* Node Type
* IP Routing Enabled
* WINS Proxy Enabled
* DNS Suffix Search List
* Connection-specific DNS Suffix
* Network Adapter Description
* Physical (MAC) Address
* DHCP Enabled
* IP Address
* Subnet Mask
* Default Gateway
* DNS Servers


Get Installed Driver Information

driverquery

It can be very useful when troubleshooting to know what drivers are installed on a system. This command will give you a complete listing of the drivers and when they were installed.


Find Files Opened By Network Users

openfiles /query

If you are running a system and you want to know who has files open on your computer, this command will provide you a list of those users and the files that they have open.

Note: If you get an error saying The system global flag ‘maintain objects list’ needs to be enabled to see local opened files, you can fix this issue by typing openfiles /local on. You will have to reboot the system but it will resolve the issue.


Monitor Port Activity

netstat -a 30

This will show you all of the TCP/IP ports that are being used on your system and what they are connecting to (or being connected from). It will continue to monitor these ports and refresh the information every 30 seconds. You can change the refresh rate by changing the number at the end of the command.


Recover Information From A Corrupt File

recover filename.ext

If you have a disk with damaged sectors, you can attempt to recover as much information as possible from the damaged file. Data that is not damaged can be retrieved but data in damaged sectors will be lost.


Defragment Remote Computer

rexec remotePC defrag C: /F

This command used the rexec command to force a defragment of the C: drive on the computer named remotePC. You can use whatever you want to for the command (I just used defrag C: /F as an example). This is very useful for remote maintenance.


Retrieve Detailed System Information

systeminfo

With this command, you can retrieve the following information:

* Host Name
* OS Name
* OS Version
* OS Manufacturer
* OS Configuration
* OS Build Type
* Registered Owner
* Registered Organization
* Product ID
* Original Install Date
* System Up Time
* System Manufacturer
* System Model
* System type
* Processor(s)
* BIOS Version
* Windows Directory
* System Directory
* Boot Device
* System Locale
* Input Locale
* Time Zone
* Total Physical Memory
* Available Physical Memory
* Virtual Memory Max Size
* Virtual Memory Available
* Virtual Memory In Use
* Page File Location(s)
* Domain
* Logon Server
* Hotfix(s)
* NetWork Card(s)


Schedule Defrag to Defragment C: Daily

schtasks /create /tn "Defrag C" /tr "defrag c: /f" /sc daily /st 02: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 30 seconds"

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


Schedule computer reboot

schtasks /create /tn "Reboot" /tr "shutdown /r /t 1" /sc once /st 01:00:00 /sd 08/18/2009 /ru "System"


cmd /c - Carries out the command specified by string and then terminates
&& - concatenates commands together

This way you can create a shortcut for short scripts without creating batch files.
e.g. a shortcut for stopping and starting the print spooler.

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


Sleep
No sleep command in Windows 2000/XP (AFAIK) unless you have the Resource Kit, and then you have to move extra files around with your scripts.
Simply use the ping command to wait predefined times. In this example it’s 10 seconds.

ping -n 10 127.0.0.1 > NUL 2>&1


Find
Windows answer to grep. Not as powerful but still useful.

e.g. In conjunction with systeminfo above to find out the Virtual Memory on the PC.

systeminfo find "Virtual Memory"