Monday, November 26, 2012

Drive tools for Windows

Remove Drive:

RemoveDrive prepares drives for "Safe Removal" by commandline. It works with drives only but not for other device types.
RemoveDrive DriveSpec: [-l][-h][-b][-i][-s][-w:nnnn]

DriveSpec  is the drive to remove, e.g. U: or an NTFS mountpoint as "C:\CardReader\Multi Reader SD"
           or . for the current drive
           or \ for the drive of the RemoveDrive.exe
           or a volume name like \\?\Volume{433619ed-c6ea-11d9-a3b2-806d6172696f}
           or a kernel name like \Device\HarddiskVolume2 (Volume)
           or a kernel name like \Device\Harddisk2\DR0 (Disk)
           or a partition name like \Device\Harddisk2\Partition1
           or a device ID
           or a friendly name like 'Corsair Voyager'
           Wildcards can be used.
[-L]       loop until success
[-e]       try to dismount and eject if the removal fails
[-h]       show open handles (admin rights required, exprimental, may freeze!)
[-h:X]     show open handles on a different drive (e.g. a TrueCrypt volume whose container is on the drive to remove)
[-w:nnnn]  wait nnnn milliseconds before close
[-s]       self delete removedrive.exe
[-b]       let Windows show the "Safe To Remove Hardware" balloon tip
[-i]       stop Windows indexing service (CiSvc) for a moment if required (admins)
[-d]       show debug information

Details here:http://www.uwe-sieber.de/drivetools_e.html

Linkd

Have you ever needed a simple way to expand a drive that's quickly running out of space? Windows 2000's support for junction points can be the solution.
Junction points originated as a solution to the problem of needing more than 26 drive letters. If you wanted to install more than 26 drives in Windows NT, you were stuck after you used Z—you were out of letters. Junction points let you install 27 (or more) drives. After you install your 27th drive, the new drive sits in Logical Disk Manager (LDM), formatted and ready to use but basically inaccessible because Win2K has no name to give it. To make the drive accessible, you can use junction points to make the drive look like a directory on an existing volume. After you create a directory (e.g., C:\extradrive) on an existing drive, you connect your unnamed drive to C:\extradrive (I explain how later in this article). From that point on, writing data to C:\extradrive puts the data on a different physical drive than writing data to C:\winnt.
The missing piece in this procedure is how you "glue" the letterless drive to the directory—that is, what you call the drive. Every drive has a globally unique identifier (GUID). You use the drive's GUID and a standard Win2K command called Mountvol to hook up the drive to the directory. A typical Mountvol command might look like
mountvol C:\extradrive
  \\?\Volume{47c8cd01-1a1f-11d5-aa7f-806d6172696f}\
But as I mentioned earlier, you can also use junction points to expand a drive. For example, if you've ever set up a server for a group of printers or for users who print long documents, you know that users write amazingly large quantities of data to spool files. Win2K temporarily queues printer spool files in \winnt\system32\spool\printers. The OS is also in that directory, so you definitely don't want that directory's drive to fill up.
Suppose that directory is on the C drive and you happen to have an E drive that has plenty of space. First, stop the Spooler service and clean out the C:\winnt\system32\spool\printers directory. Then, reparse the E drive to C:\winnt\system32\spool\printers. Restart the Spooler service and—voilĂ —no more filled-up system drive.
The one wrinkle in this approach is finding the GUID for drive E. Mountvol can tell you the GUID, but wouldn't you rather simply type something like
linkd C:\winnt\system32\spool\printers E:

http://www.windowsitpro.com/article/storage-management/the-linkd-utility

Sync

UNIX provides a standard utility called Sync, which can be used to direct the operating system to flush all file system data to disk in order to insure that it is stable and won't be lost in case of a system failure. Otherwise, any modified data present in the cache would be lost. Here is an equivalent that I wrote, called Sync, that works on all versions of Windows. Use it whenever you want to know that modified file data is safely stored on your hard drives. Unfortunately, Sync requires administrative privileges to run. This version also lets you flush removable drives such as ZIP drives.

Using Sync

Usage: sync [-r] [-e] [drive letter list]
-rFlush removable drives.
-eEjects removable drives.
Specifying specific drives (e.g. "c e") will result in Sync only flushing those drives.
http://technet.microsoft.com/en-us/sysinternals/bb897438.aspx

BounceBack

BounceBackInstant Recovery software enables you to back up your entire PC or laptop hard drive, including the Operating System, data files, applications, pictures, video, financial documents and settings. Using our patent pending Instant PC Recovery mode, you can start your PC or laptop directly from an external USB backup hard drive in the event of an operating system malfunction or even a failed hard drive. Key benefits: instant recovery software for your pc; start-up and recover from your external usb storage device; continuous data protection (CDP); immediate access to your files ; data saved in native file format; creates a bootable drive--ability to startup direct from backup; backup to any USB hard drive, secondary drive or network drive; data security--built-in AES-256 encryption; backup automation through backup scheduling, auto shut down; parallel backup--backup to multiple destinations; version control--ability to go back to point in time backups.

Friday, November 23, 2012

Remote Debugging

Prerequisites

To debug on a remote device:
  • The remote device and the Visual Studio computer must be connected over a network or connected directly through an Ethernet cable. Debugging over the internet is not supported.
  • The remote device must be running the remote debugging components.
  • You must be an administrator to install the remote debugger on the remote device. To communicate with the remote debugger, you must have user access to the remote device.
Installing the remote debugging components
You can run or download the Visual Studio Remote Debugger setup program from the Microsoft download center. Setup programs are also available on the Visual Studio installation media in subfolders of the vs\Remote Debugger folder. Run the setup program that matches the operating system (x86, x64, ARM) on the remote device.

Tuesday, November 20, 2012

Robocopy MSBuild Task

#region

Copyright © 2007 Paul Welter. All rights reserved.

/*

Copyright © 2007 Paul Welter. All rights reserved.



Redistribution and use in source and binary forms, with or without

modification, are permitted provided that the following conditions

are met:



1. Redistributions of source code must retain the above copyright

notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright

notice, this list of conditions and the following disclaimer in the

documentation and/or other materials provided with the distribution.

3. The name of the author may not be used to endorse or promote products

derived from this software without specific prior written permission.



THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR

IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES

OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.

IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,

INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT

NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF

THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/



#endregion



using

System;

using

System.Collections.Generic;

using

System.Text;

using

Microsoft.Build.Utilities;

using

Microsoft.Build.Framework;

using

System.IO;

 

 


namespace

MSBuild.Community.Tasks

{


///


/// Task wrapping the Window Resource Kit Robocopy.exe command.


///


/// Deploy website to web server.


/// <![CDATA[


///


/// SourceFolder="$(MSBuildProjectDirectory)"


/// DestinationFolder="\\server\webroot\"


/// Mirror="true"


/// ExcludeFolders=".svn;obj;Test"


/// ExcludeFiles="*.cs;*.resx;*.csproj;*.webinfo;*.log"


/// NoJobHeader="true"


/// />


/// ]]>


///


public class RoboCopy : ToolTask

{


#region

Properties


private string _sourceFolder;


///


/// Source directory


///


///


/// You can use drive:\path or \\server\share\path


///

[
Required]


public string SourceFolder

{


get { return _sourceFolder; }


set { _sourceFolder = value; }

}


private string[] _sourceFiles;


///


/// Names of files to act upon.


///


///


/// You can use wildcard characters (? and *). If no


/// files are listed, Robocopy defaults to all files (*.*).


///


public string[] SourceFiles

{


get { return _sourceFiles; }


set { _sourceFiles = value; }

}


private string _destinationFolder;


///


/// Destination directory.


///


///


/// You can use drive:\path or \\server\share\path


///

[
Required]


public string DestinationFolder

{


get { return _destinationFolder; }


set { _destinationFolder = value; }

}


private bool _subdirectories;


///


/// /S Copies subdirectories (excluding empty ones).


///


public bool Subdirectories

{


get { return _subdirectories; }


set { _subdirectories = value; }

}


private bool _allSubdirectories;


///


/// /E Copies all subdirectories (including empty ones).


///


public bool AllSubdirectories

{


get { return _allSubdirectories; }


set { _allSubdirectories = value; }

}


private bool _restartableMode;


///


/// /Z Copies files in restartable mode (that is, restarts the copy process from the point of failure).


///


public bool RestartableMode

{


get { return _restartableMode; }


set { _restartableMode = value; }

}


private bool _backupMode;


///


/// /B Copies files in Backup mode (Backup copies are not restartable, but can copy some files that restartable mode cannot).


///


public bool BackupMode

{


get { return _backupMode; }


set { _backupMode = value; }

}


private string _copyFlags;


///


/// /COPY:copyflags Copies the file information specified by copyflags.


///


///


/// D – file Data, S – file Security (NTFS ACLs), A – file Attributes,


/// O – file Ownership information, T – file Timestamps, U – file Auditing infomation.


///


public string CopyFlags

{


get { return _copyFlags; }


set { _copyFlags = value; }

}


private bool _copyAll;


///


/// /COPYALL Copies Everything. Equivalent to /COPY:DATSOU.


///


public bool CopyAll

{


get { return _copyAll; }


set { _copyAll = value; }

}


private bool _noCopy;


///


/// /NOCOPY Copies Nothing. Can be useful with /PURGE.


///


public bool NoCopy

{


get { return _noCopy; }


set { _noCopy = value; }

}


private bool _security;


///


/// /SEC Copies NTFS security information. (Source and destination volumes must both be NTFS). Equivalent to /COPY:DATS.


///


public bool Security

{


get { return _security; }


set { _security = value; }

}


private bool _moveFiles;


///


/// /MOV Moves files (that is, deletes source files after copying).


///


public bool MoveFiles

{


get { return _moveFiles; }


set { _moveFiles = value; }

}


private bool _move;


///


/// /MOVE Moves files and directories (that is, deletes source files and directories after copying).


///


public bool Move

{


get { return _move; }


set { _move = value; }

}


private bool _purge;


///


/// /PURGE Deletes destination files and directories that no longer exist in the source.


///


public bool Purge

{


get { return _purge; }


set { _purge = value; }

}


private bool _mirror;


///


/// /MIR Mirrors a directory tree (equivalent to running both /E and /PURGE).


///


public bool Mirror

{


get { return _mirror; }


set { _mirror = value; }

}


private bool _create;


///


/// /CREATE Creates a directory tree structure containing zero-length files only (that is, no file data is copied).


///


public bool Create

{


get { return _create; }


set { _create = value; }

}


private bool _fatFileNames;


///


/// /FAT Creates destination files using only 8.3 FAT file names.


///


public bool FatFileNames

{


get { return _fatFileNames; }


set { _fatFileNames = value; }

}


private bool _fatFileTimes;


///


/// /FFT Assume FAT File Times (2-second granularity).


///


public bool FatFileTimes

{


get { return _fatFileTimes; }


set { _fatFileTimes = value; }

}


private string _includeAttributes;


///


/// /IA:{R|A|S|H|C|N|E|T|O} Includes files with the specified attributes.


///


///


/// The following file attributes can be acted upon:


/// R – Read only, A – Archive, S – System, H – Hidden,


/// C – Compressed, N – Not content indexed, E – Encrypted,


/// T – Temporary, O - Offline


///


public string IncludeAttributes

{


get { return _includeAttributes; }


set { _includeAttributes = value; }

}


private string _excluedAttributes;


///


/// /XA:{R|A|S|H|C|N|E|T|O} Excludes files with the specified attributes.


///


///


/// The following file attributes can be acted upon:


/// R – Read only, A – Archive, S – System, H – Hidden,


/// C – Compressed, N – Not content indexed, E – Encrypted,


/// T – Temporary, O - Offline


///


public string ExcluedAttributes

{


get { return _excluedAttributes; }


set { _excluedAttributes = value; }

}


private bool _includeArchive;


///


/// /A Copies only files with the archive attribute set.


///


public bool IncludeArchive

{


get { return _includeArchive; }


set { _includeArchive = value; }

}


private bool _includeArchiveClear;


///


/// /M Copies only files with the archive attribute set and then resets (turns off) the archive attribute in the source files.


///


public bool IncludeArchiveClear

{


get { return _includeArchiveClear; }


set { _includeArchiveClear = value; }

}


private bool _excludeJunctions;


///


/// /XJ Excludes Junction points.


///


public bool ExcludeJunctions

{


get { return _excludeJunctions; }


set { _excludeJunctions = value; }

}


private string[] _excludeFiles;


///


/// /XF file [file] Excludes files with the specified names, paths, or wildcard characters.


///


public string[] ExcludeFiles

{


get { return _excludeFiles; }


set { _excludeFiles = value; }

}


private string[] _excludeFolders;


///


/// /XD dir [dir] Excludes directories with the specified names, paths, or wildcard characters.


///


public string[] ExcludeFolders

{


get { return _excludeFolders; }


set { _excludeFolders = value; }

}


private bool _verbose;


///


/// /V Produces verbose output (including skipped files).


///


public bool Verbose

{


get { return _verbose; }


set { _verbose = value; }

}


private bool _noFileLogging;


///


/// /NFL Turns off logging of file names. File names are still shown, however, if file copy errors occur.


///


public bool NoFileLogging

{


get { return _noFileLogging; }


set { _noFileLogging = value; }

}


private bool _noFolderLogging;


///


/// /NDL Turns off logging of directory names. Full file pathnames (as opposed to simple file names) will be shown if /NDL is used.


///


public bool NoFolderLogging

{


get { return _noFolderLogging; }


set { _noFolderLogging = value; }

}


private bool _noJobHeader;


///


/// /NJH Turns of logging of the job header.


///


public bool NoJobHeader

{


get { return _noJobHeader; }


set { _noJobHeader = value; }

}


private bool _noJobSummary;


///


/// /NJS Turns off logging of the job summary.


///


public bool NoJobSummary

{


get { return _noJobSummary; }


set { _noJobSummary = value; }

}


private bool _noProgress = true;


///


/// /NP Turns off copy progress indicator (% copied).


///


public bool NoProgress

{


get { return _noProgress; }


set { _noProgress = value; }

}


private string _logFile;


///


/// /LOG:file Redirects output to the specified file, overwriting the file if it already exists.


///


public string LogFile

{


get { return _logFile; }


set { _logFile = value; }

}


private string _appendLogFile;


///


/// /LOG+:file Redirects output to the specified file, appending it to the file if it already exists.


///


public string AppendLogFile

{


get { return _appendLogFile; }


set { _appendLogFile = value; }

}


private string[] _options;


///


/// Manually entered options.


///


public string[] Options

{


get { return _options; }


set { _options = value; }

}


#endregion




///


/// Handles execution errors raised by the executable file.


///


///


/// true if the method runs successfully; otherwise, false.


///


protected override bool HandleTaskExecutionErrors()

{


//The return code from Robocopy is a bit map, defined as follows:


//16 Serious error. Robocopy did not copy any files.


//8 Some files or directories could not be copied.


//4 Some Mismatched files or directories were detected.


//2 Some Extra files or directories were detected.


//1 One or more files were copied successfully (that is, new files have arrived).


//0 No errors occurred, and no copying was done.


return !(((ExitCode & 16) == 16) || ((ExitCode & 8) == 8));

}


///


/// Returns a string value containing the command line arguments to pass directly to the executable file.


///


///


/// A string value containing the command line arguments to pass directly to the executable file.


///


protected override string GenerateCommandLineCommands()

{


CommandLineBuilder builder = new CommandLineBuilder();

builder.AppendFileNameIfNotNull(_sourceFolder);

builder.AppendFileNameIfNotNull(_destinationFolder);

builder.AppendFileNamesIfNotNull(_sourceFiles,

" ");


if (_subdirectories)

builder.AppendSwitch(
"/S");


if (_allSubdirectories)

builder.AppendSwitch(
"/E");


if (_restartableMode)

builder.AppendSwitch(
"/Z");


if (_backupMode)

builder.AppendSwitch(
"/B");

builder.AppendSwitchIfNotNull(
"/COPY:", _copyFlags);


if (_copyAll)

builder.AppendSwitch(
"/COPYALL");


if (_noCopy)

builder.AppendSwitch(
"/NOCOPY");


if (_security)

builder.AppendSwitch(
"/SEC");


if (_moveFiles)

builder.AppendSwitch(
"/MOV");


if (_move)

builder.AppendSwitch(
"/move");


if (_purge)

builder.AppendSwitch(
"/PURGE");


if (_mirror)

builder.AppendSwitch(
"/MIR");


if (_noCopy)

builder.AppendSwitch(
"/NOCOPY");


if (_create)

builder.AppendSwitch(
"/CREATE");


if (_fatFileNames)

builder.AppendSwitch(
"/FAT");


if (_fatFileTimes)

builder.AppendSwitch(
"/FFT");

builder.AppendSwitchIfNotNull(
"/IA:", _includeAttributes);

builder.AppendSwitchIfNotNull(
"/XA:", _excluedAttributes);


if (_includeArchive)

builder.AppendSwitch(
"/A");


if (_includeArchiveClear)

builder.AppendSwitch(
"/M");


if (_excludeJunctions)

builder.AppendSwitch(
"/XJ");

builder.AppendSwitchIfNotNull(
"/XF ", _excludeFiles, " ");

builder.AppendSwitchIfNotNull(
"/XD ", _excludeFolders, " ");


if (_verbose)

builder.AppendSwitch(
"/V");


if (_noFileLogging)

builder.AppendSwitch(
"/NFL");


if (_noFolderLogging)

builder.AppendSwitch(
"/NDL");


if (_noJobHeader)

builder.AppendSwitch(
"/NJH");


if (_noJobSummary)

builder.AppendSwitch(
"/NJS");


if (_noProgress)

builder.AppendSwitch(
"/NP");

builder.AppendSwitchIfNotNull(
"/LOG:", _logFile);

builder.AppendSwitchIfNotNull(
"/LOG+:", _appendLogFile);

builder.AppendSwitchIfNotNull(
"", _options, " ");


return builder.ToString();

}


///


/// Returns the fully qualified path to the executable file.


///


///


/// The fully qualified path to the executable file.


///


protected override string GenerateFullPathToTool()

{


return string.IsNullOrEmpty(ToolPath) ? ToolName : Path.Combine(ToolPath, ToolName);

}


///


/// Logs the starting point of the run to all registered loggers.


///


/// A descriptive message to provide loggers, usually the command line and switches.


protected override void LogToolCommand(string message)

{

Log.LogCommandLine(

MessageImportance.Low, message);

}


///


/// Gets the name of the executable file to run.


///


///


/// The name of the executable file to run.


protected override string ToolName

{


get { return "robocopy.exe"; }

}


///


/// Gets the with which to log errors.


///


///


/// The with which to log errors.


protected override MessageImportance StandardOutputLoggingImportance

{


get

{


return MessageImportance.Normal;

}

}

}

}