Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"profiles": { | ||
"mkshortcut": { | ||
"commandName": "Project", | ||
"commandLineArgs": "\"c:\\delme\\delme.lnk\" \"C:\\xgit\\WANGF\\WANGF\\OnlyEmbeddedModules\\bin\\Debug\\net8.0\\Asaon.dll\"" | ||
} | ||
} | ||
} |