0

I want to use scripts to create shortcuts under the Windows operating system (.lnk).

In the Windows environment, I chose PowerShell, wrote the script, successfully created .lnk.

$shell = New-Object -ComObject WScript.Shell
$desktop = [System.Environment]::GetFolderPath('Desktop')
$shortcut = $shell.CreateShortcut("$desktop\clickme.lnk")
$shortcut.TargetPath = "C:\Users\scc\Desktop\linkfolder"
$shortcut.IconLocation = "shell32.dll,004"
$shortcut.Save()

But my online running environment is Linux.

Fortunately, I found that PowerShell in 2016 on a multi-platform transplant, yes, it can support Linux. I found it, downloaded, and installed. Under Linux, in the PowerShell command window I can run some basic commands.

There was a run-time error! When I run the first line of code:

$shell = New-Object -ComObject WScript.Shell 

The error message is:

New-Object : Unable to load DLL 'api-ms-win-core-com-l1-1-0.dll': The specified
module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E)
At line:1 char:10
+ $shell = New-Object -ComObject WScript.Shell
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-Object], DllNotFoundException
    + FullyQualifiedErrorId : System.DllNotFoundException,Microsoft.PowerShell.Commands.NewObjectCommand

According to the prompt, it seems that the lack of WScript-related modules. Missing DLL file.

My requirement is to run Java programs under Linux to create shortcuts in Windows format. (Stored in the network disk, the file system for the btrfs, and can provide SMB \ AFP \ NFS \ FTP these file services)

Yes, this demand seems to be strange, if you have a new solution ideas and ideas, please tell me or discuss with me.

I have a bold idea: can I use the SMB protocol to create an .lnk file?

1
  • Based on the error message, it would seem that the Linux implementation of Powershell does not include support for emulating the WScript.Shell object. This is unsurprising. You could try Wine instead, perhaps. Failing that, a shortcut is an ordinary file, it should be possible to reverse-engineer the format and write your own implementation. There might even be an existing third-party solution. Commented Sep 3, 2017 at 21:41

1 Answer 1

0

You can use the below to create Windows Shortcuts in Linux:

MSLink

It is having both bash version and C source.

Refer this also:

Produce-lnk-file-on-gnu-linux-to-transfer-to-windows

Sign up to request clarification or add additional context in comments.

1 Comment

thank you. Your answer looks very reliable, I chose to use mslink.sh way. But I do not know how to use it. Can give me an example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.