The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,854 other subscribers

Archive for the ‘Scripting’ Category

How Can I Determine Which Version of Word is Installed on a Computer? – Hey, Scripting Guy! Blog – Site Home – TechNet Blogs

Posted by jpluimers on 2014/07/24

Late binding sometimes is your friend:

Set objWord = CreateObject("Word.Application")
Wscript.Echo "Version: " & objWord.Version
Wscript.Echo "Build: " & objWord.Build
objWord.Quit

The accompanying Delphi code:

uses
  System.Win.ComObj;

procedure TTestVersionAgnosticWordMainForm.GetWordApplicationInfoButtonClick(Sender: TObject);
var
  WordApplication: OleVariant;
  Version: OleVariant;
  Build: OleVariant;
begin
  WordApplication := CreateOleObject('Word.Application');
  try
    try
      Version := WordApplication.Version;
      Build := WordApplication.Build;
      LogMemo.Lines.Add(Version);
      LogMemo.Lines.Add(Build);
    finally
      WordApplication.Quit;
    end;
  finally
    WordApplication := Unassigned; // release it
  end;
end;

–jeroen

via: How Can I Determine Which Version of Word is Installed on a Computer? – Hey, Scripting Guy! Blog – Site Home – TechNet Blogs.

Posted in Delphi, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Development, Scripting, Software Development, VBScript | 10 Comments »

which.bat (in case I don’t have CygWin on a system)

Posted by jpluimers on 2014/07/08

Small batch file that shows you the files on the path. It is a simple version that does not take into account built-in commands of cmd.exe, DOSKEY macros or PATHEXT environment variable: it just matches a name of an executable. Rob van der Woude has a complete which.bat (text version here) that does take into account all of the above. This is the poor man’s version:

@echo off
for %%f in (%1) do @echo. %%~$PATH:f
goto :eof

It uses this little trick from the FOR command:

%~$PATH:I Searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, this modifier expands to the empty string.

–jeroen

Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »

Windows: programmatically setting date/time stamps of files

Posted by jpluimers on 2014/07/01

For DOS programs, date and time stamps were used to mark versions of files. For instance, Turbo Pascal 6.0, had a 06:00 time stamp on every file.

You can still do this in Windows, but need to watch for a couple of things:

  • daylight saving time
  • more than one time stamp per file

There are various ways to do it. Besides a graphical Attribute Changer at www.petges.lu (thanks User Randolf Richardson), these are console approaches via How can I change the timestamp on a file?:
Read the rest of this entry »

Posted in *nix, Apple, Batch-Files, Cygwin, Development, Linux, Mac, Mac OS X / OS X / MacOS, Mac OS X 10.4 Tiger, Mac OS X 10.5 Leopard, Mac OS X 10.6 Snow Leopard, Mac OS X 10.7 Lion, MacBook, MacBook Retina, MacBook-Air, MacBook-Pro, OS X 10.8 Mountain Lion, Power User, PowerShell, Scripting, Software Development, SuSE Linux, Windows, Windows 7, Windows 8, Windows Server 2000, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Vista, Windows XP | 2 Comments »

Hiding email behind a 30x redirect.

Posted by jpluimers on 2014/06/24

Last week, I thanked Jaykul for helping me out on PowerShell.

But he taught me another thing that was new for me: on his site, he has hidden his email address behind a 302-redirect.

I didn’t even realize that was possible until I saw his site start my mail program without initially showing a mailto in the url. A quick check showed me he was using a 302-redirect: Read the rest of this entry »

Posted in *nix, Apache2, bash, Development, Linux, Power User, Scripting, Software Development, SuSE Linux, wget | Leave a Comment »

Windows consoles: a small list

Posted by jpluimers on 2014/06/19

Many people confuse a shell with a console.

They are distinct: the shell executes commands, and the console hooks up video and keyboard to them.

Some products (like Take Command Console, of which Noah Coad is a huge fan) combine the two.

Some shells you can use for Windows: Read the rest of this entry »

Posted in Batch-Files, CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »

Windows shells: a bit of history

Posted by jpluimers on 2014/06/18

I’ve a long history in DOS/Windows 9x COMMAND.COM and Windows cmd.exe shell programming.

The switch to PowerShell is steep, but for me it is worth it: it has so much more functionality than cmd.exe, and taps right into the .NET ECO system.

If you look for something intermediate, you might want to consider TCC. Formerly TCC was known as 4NT, which has its roots in 4DOS (I totally loved 4DOS back when cmd wasn’t there yet).

A small overview: Read the rest of this entry »

Posted in Batch-Files, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows | Leave a Comment »

Thanks Jaykul for explaining me a custom PowerShell script that acts like DU (DiskUsage).

Posted by jpluimers on 2014/06/17

Thanks Joel Bennett (aka Jaykul) from Huddled Masses for answering my Stack Overflow question PowerShell Get-DiskUsage CmdLet: how to list from a different drive/directory?

In addition to answering it, he also added a complete new and lighter implementation of that script explaining why it was lighter and what idioms to follow in PowerShell.

After reading his aswer, I was even more aware of these two things than I was before:

  • I should emphasize the importance of the object pipeline even more than I already did.
  • You should try to cut down on the dynamically instantiated objects. Like any language with heavy objects, they provide the huge benefit of fast development, but also an inherent cost.

I wasn’t aware you can put your own crafted objects into the pipeline in a very easy way. But you can: Read the rest of this entry »

Posted in Development, PowerShell, Scripting, Software Development | 1 Comment »

StudioShell: integrating Visual Studio in PowerShell

Posted by jpluimers on 2014/06/10

Wow, it seems I’ve been living under a stond since early 2011: the first StudioShell checkin.

[WayBackStudioShell opens marvellous possibilities in Visual Studio 2010, 2012 and up.

Just look at the feature list: Read the rest of this entry »

Posted in .NET, .NET 4.0, .NET 4.5, C#, C# 4.0, C# 5.0, CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »

using tf to list the workspaces for the current directory in Team Foundation System

Posted by jpluimers on 2014/05/28

Since Visual Studio is always in a 32-bit directory, I needed the SetProgramFilesX86 batch file from

Windows batch file to set ProgramFilesX86 directory for 32-bit program files on x86 and x64 systems.

Here is a small batch file to list workspaces by any user for the current directory (assuming that directory is mapped to a workspace):

call "%~dp0SetProgramFilesX86.bat"
:: assume Visual Studio 2005:
::"%ProgramFilesX86%\Microsoft Visual Studio 8\Common7\IDE\tf" workspaces /owner:* /computer:* 
:: assume Visual Studio 2010:
"%ProgramFilesX86%\Microsoft Visual Studio 10.0\Common7\IDE\tf" workspaces /owner:* /computer:*

It uses TF, and assumes default locations for various Visual Studio versions based on the internal version number.

A generic TF batch file that finds the TF is this one:

call "%~dp0SetProgramFilesX86.bat"
:: assume Visual Studio 2005:
::"%ProgramFilesX86%\Microsoft Visual Studio 8\Common7\IDE\tf" %*
:: assume Visual Studio 2010:
"%ProgramFilesX86%\Microsoft Visual Studio 10.0\Common7\IDE\tf" %*

–jeroen

Posted in Batch-Files, Development, Scripting, Software Development | 1 Comment »

Windows batch file to set ProgramFilesX86 directory for 32-bit program files on x86 and x64 systems (via: Stack Overflow)

Posted by jpluimers on 2014/05/27

Every once in a while you need to execute a binaryfrom a batch file that will always be available 32-bits.
Examples include development tools (that usually are x86 hosts talking or encapsulating managed environments, and x64 debuggers) or office versions for which certain plugins are not available in x64 versions.

That’s why I wrote the below batch file to fill the ProgramFilesX86 environment variable to point to the 32-bit Program Files directory on any system (x86, x64, or one that does not make a distinction).

Determining processor architecture

The batch file makes use of the flags mentioned in HOWTO: Detect Process Bitness – David Wang – Site Home – MSDN Blogs:

Notes:

  • There are 3 distinct cases and two outcomes
  • We default to x86 just in case we run on a system that has none of the flags defined (for instance on legacy systems).
Environment Variable \ Program Bitness 32bit Native 64bit Native WOW64
PROCESSOR_ARCHITECTURE x86 AMD64 x86
PROCESSOR_ARCHITEW6432 undefined undefined AMD64

Source of 32-bit program files

The place of the 32-bit program files directory is determined by the environment variables mentioned in WOW64 Implementation Details (Windows):

Process Environment variables
64-bit process PROCESSOR_ARCHITECTURE=AMD64 or PROCESSOR_ARCHITECTURE=IA64
ProgramFiles=%ProgramFiles%
ProgramW6432=%ProgramFiles%
CommonProgramFiles=%CommonProgramFiles%
CommonProgramW6432=%CommonProgramFiles%
32-bit process PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=%PROCESSOR_ARCHITECTURE%
ProgramFiles=%ProgramFiles(x86)%
ProgramW6432=%ProgramFiles%
CommonProgramFiles=%CommonProgramFiles(x86)%
CommonProgramW6432=%CommonProgramFiles%
Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP: The ProgramW6432 and CommonProgramW6432 environment variables were added starting with Windows 7 and Windows Server 2008 R2.

Boolean logic and case insensitive compare in batch files

Many things in batch files can be tricky including these two:

The batch file

Finally: the batch file: Read the rest of this entry »

Posted in Batch-Files, Development, Scripting, Software Development | 4 Comments »