Home

How to using COM Interop.IWshRuntimeLibrary in LINQPad 8

In Visual Studio, I can using IWshRuntimeLibrary by add COM reference "Windows Script Host Object Model".
How to achieve in LINQPad 8.

Comments

  • edited November 26

    AFAIK there is no NuGet for this.

    How I did it for LINQPad 8 x86/x64 .NET 9

    Ran Developer Command Prompt for VS.

    Copied file c:\windows\system32\wshom.ocx somewhere I have write access to.

    Ran tlbimp for that file and got IWshRuntimeLibrary.dll

    tlbimp wshom.ocx
    

    Output:

    Microsoft (R) .NET Framework Type Library to Assembly Converter 4.8.3928.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    TlbImp : warning TI3002 : Importing a type library into a platform agnostic assembly.  This can cause errors if the type library is not truly platform agnostic.
    TlbImp : Type library imported to IWshRuntimeLibrary.dll
    

    IWshRuntimeLibrary.dll:

    // IWshRuntimeLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
    // Global type: <Module>
    // Architecture: AnyCPU (64-bit preferred)
    // Runtime: v4.0.30319
    // Hash algorithm: SHA1
    

    Created new script:

    var sh = new IWshRuntimeLibrary.WshShell(); // Use WshShell instead of WshShellClass!
    sh.CurrentDirectory.Dump();
    

    Pressed F4 > Additional References > Add / Browse...

    Ran test script.

    You might also need to pay attention to bitness. Also you might have to specify STAThread attribute for Main.

  • Thx i2van, it works perfectly. :)

Sign In or Register to comment.