Skip to content

Commit

Permalink
fix it
Browse files Browse the repository at this point in the history
  • Loading branch information
autumn009 committed Jan 3, 2024
1 parent dc00936 commit 271ea17
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
42 changes: 40 additions & 2 deletions mkshortcut/mkshortcut/Program.cs
@@ -1,2 +1,40 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using System.Runtime.InteropServices;

if( args.Length != 2 )
{
Console.WriteLine("Usage: mkshortcut <shortcut_path> <target_path>");
return;
}
create(args[0], args[1]);

void create(string lnkPath,string fullPath)
{
dynamic? shell = null; // IWshRuntimeLibrary.WshShell
dynamic? lnk = null; // IWshRuntimeLibrary.IWshShortcut
try
{
#pragma warning disable CA1416 // プラットフォームの互換性を検証
// available in Windows only
var type = Type.GetTypeFromProgID("WScript.Shell");
#pragma warning restore CA1416 // プラットフォームの互換性を検証
if (type != null)
{
shell = Activator.CreateInstance(type);
if (shell != null)
{
lnk = shell.CreateShortcut(lnkPath);
if (lnk != null)
{
lnk.TargetPath = fullPath;
lnk.Save();
Console.WriteLine($"created {lnkPath} to {fullPath}");
}
}
}
}
finally
{
if (lnk != null) Marshal.ReleaseComObject(lnk);
if (shell != null) Marshal.ReleaseComObject(shell);
}
}
8 changes: 8 additions & 0 deletions mkshortcut/mkshortcut/Properties/launchSettings.json
@@ -0,0 +1,8 @@
{
"profiles": {
"mkshortcut": {
"commandName": "Project",
"commandLineArgs": "\"c:\\delme\\delme.lnk\" \"C:\\xgit\\WANGF\\WANGF\\OnlyEmbeddedModules\\bin\\Debug\\net8.0\\Asaon.dll\""
}
}
}

0 comments on commit 271ea17

Please sign in to comment.