Extending Chris' original post:

http://blogs.vertigosoftware.com/chris/archive/2005/04/27/891.aspx

VS.NET 2005 actually has an accessibility macro that allows you to increase/decrease the font very easily. You can execute the macro either:

  • by running it through the Macro Explorer or
  • by binding a keyboard shortcut to it allowing you instant access to the feature.

with 6 Comments

Ever wanted to create a batch file, but wished you could write the code in C#/.NET? Have you ever wanted to try out a snippet of code, but didn't want to go through the trouble of creating a new solution, then a command prompt project in Visual Studio?

I asked these exact same questions when I started searching for a way to write .NET batch files. Those of you who have heard of Longhorn probably have heard about Monad. This is Longhorn's new command shell that allows you to pipe and return data similar to unix shells. The cool thing about Monad however is that it allows you to write little managed code snippets called commandlets. This means you can write mini batch files that are in .NET code and can pass and return .NET objects. 

Monad is great, but how about now? Well it turns out that someone has written a really neat batch file template that allows you to write the batch file as a standard .NET command line project. By running the batch file, it dynamically compiles your code into a command line application and then runs it passing in any command line arguments you pass in. The original blog post about this is here:

http://wintellect.com/WEBLOGS/wintellect/archive/2005/03/23/931.aspx

and here's an example of what I created so I can hash some passwords for testing:

@echo off & goto :beginScript
#endif
#line 4

/******** Put compilable C# code after this line ********/
using System;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text;

class App {

 public static void Main(String[] args) {
  if (args.Length < 2) {
   DisplayUsage();
   return;
  }
  
  string salt = args[0];
  string password = args[1];
  
  string hashPassword = App.HashPassword(salt, password);
  
  Console.WriteLine ("Your hashed password is: " + hashPassword);
 }
 
 private static string HashPassword (string salt, string password) {
  string inputText = string.Format("{0}{1}", password, salt);

  Byte[] clearBytes = new UnicodeEncoding().GetBytes(inputText);
  Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
  
  return BitConverter.ToString(hashedBytes);
 }
 
 private static void DisplayUsage() {
  Console.WriteLine ("Hashes the input password as used...");
  Console.WriteLine ();
  Console.WriteLine (" HASHPASS.BAT ");
  Console.WriteLine ();
  Console.WriteLine ("         The salt to add to the hash.");
  Console.WriteLine ("     The password to hash.");
  Console.WriteLine ();
 }
  
}
 

/*******************************************************/

#if NO

:beginScript
setlocal
set versions=
:: Uncomment the following line (remove REM) to limit the fx versions. Uses newest by default.
rem SET versions=v1.0.3705 v1.1.4322
set tempCs=%~s0
set tempCs=%tempCs:\=.%
set tempCs=%tempCs::=.%
set tempCs=%TEMP%\%tempCs%

if not exist %tempCs%.exe goto :build
::check for up-to-date .exe
copy %~s0 %tempCs%.tst 1>nul 2>&1
for /F %%i in ('dir /od /b %tempCs%.*') do set latestCs=%%~xi
del %tempCs%.tst 1>nul 2>&1
if "%latestCs%"==".exe" goto :run

:build
if defined versions FOR %%c IN (%versions%) DO IF EXIST %SystemRoot%\Microsoft.Net\Framework\%%c\csc.exe (SET netpath=%SystemRoot%\Microsoft.Net\Framework\%%c)
if not defined versions for /F %%c in ('dir /b /on %SystemRoot%\Microsoft.Net\Framework\v?.*') do if exist %SystemRoot%\Microsoft.Net\Framework\%%c\csc.exe (SET netpath=%SystemRoot%\Microsoft.Net\Framework\%%c)
if not exist %netpath%\csc.exe GOTO noFramework
echo #line 1 "%0" >%tempCs%.cs
echo #if NO >>%tempCs%.cs
TYPE %~s0 >>%tempCs%.cs
%netpath%\csc.exe /out:"%tempCs%.exe" %tempCs%.cs >nul
if ERRORLEVEL 1 goto badCompile
if exist %tempCs%.cs DEL /q %tempCs%.cs

:run
%tempCs%.exe %*
goto :EOF

:badCompile
%netpath%\csc.exe /out:"%tempCs%.exe" %tempCs%.cs
IF EXIST %tempCs%.cs DEL /q %tempCs%.cs
goto :EOF

:noFramework
ECHO ERROR: This batch file requires the .Net framework.
goto :EOF

#endif