Windows shortcuts (lnk) help

Hello,

i still have the problem that i want to parse and create windows shortcuts (.lnk). I know it gives one Library for that problem https://github.com/forensicmatt/RustyLnk but this Library only export to json and i have problems to read the code. I cannot snip the code that reads lnks byte for byte.

At the moment i use an wrapper for an PowerShell Script that uses:

$shell = New-Object -comObject WScript.Shell;
            $lnk = $shell.CreateShortcut($shortcut);
            $lnk.TargetPath = "$commandName";
            $lnk.Arguments = "-start";
            $lnk.IconLocation =  $app.Icon;
            $lnk.Save();

I give an cmd the parameters and this command bypass the policy and take the parametes to this PowerShell Script. Creepy but functional:).

But i want a pure rust solution for that problem.

My first question, can i use/access the com-object in rust that i can replicate the powershell script in rust?

Knows anybody a page where i have an doc about windows shortcuts,lnks? And what's the best way to go for my problem in pure rust, is it possible in pure rust?

thx

The right way to directly access the COM object is using the winapi crate. It already has the basic functions for creating COM objects, and bindings to a few existing COM-based interfaces. I don't think it has bindings to IShellLink, so you'll probably need to hand-convert the IDL into Rust (it should be theoretically possible to write a script that will automatically convert COM interfaces into an invocation of the RIDL! macro, but it hasn't been done yet).

Based on this C++ sample on Microsoft's Developer Network. While I have coded directly against winapi, I've technically never used CoCreateInstance, so I'm not speaking from proper experience using COM with Rust, just from what I've gleaned from winapi while working on other stuff.

@notriddle Thx for your solution but I'm using powershell scripting within my executables as easiest variant.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.