Thursday, January 27, 2011

Windows Command Line args to get file paths

%~0 - expands %I removing any surrounding quotes (")
%~f0 - expands %I to a fully qualified path name
%~d0 - expands %I to a drive letter only
%~p0 - expands %I to a path only
%~n0 - expands %I to a file name only
%~x0 - expands %I to a file extension only
%~s0 - expanded path contains short names only
%~a0 - expands %I to file attributes of file
%~t0 - expands %I to date/time of file
%~z0 - expands %I to size of file

The flags can be combined.

Friday, January 21, 2011

Accessing 32bit Registry under 64bit machine (non-wow location)

Starting from .Net 4.0, there is actually RegistryView used for this purpose. For any .Net version earlier than that, here is the rule:

"The rules are pretty straightforward:

  • .NET app compiled for "x86":
    • Always 32-bit
    • On 32-bit platforms, accesses 32-bit registry
    • On 64-bit platforms, accesses 32-bit registry (inside Wow6432Node)
      • 64-bit registry inaccessible (without doing something weird)
  • .NET app compiled for "x64":
    • Always 64 bit
    • On 32-bit platforms, won't run
    • On 64-bit platforms, accesses 64-bit registry (not inside Wow6432Node)
      • If you want to get to the 32-bit registry, you need to do something weird
  • .NET app compiled for "AnyCpu"
    • Either 32 or 64 bit depending on platform
    • On 32-bit platforms, accesses 32-bit registry
    • On 64-bit platforms, accesses 64-bit registry (not inside Wow6432Node)
      • If you want to get to the 32-bit registry, you need to do something weird

"Something weird" technically requires passing a special flag to RegOpenKeyEx to obtain the alternate registry view. .NET doesn't expose any function that will do this nicely, so you'd have to drop to p/invoke to get there."

Reference: http://social.msdn.microsoft.com/forums/en-US/netfx64bit/thread/92f962d6-7f5e-4e62-ac0a-b8b0c9f552a3