diff --git a/SetLnkApp/MainForm.Designer.cs b/SetLnkApp/MainForm.Designer.cs index 304b462..f49d018 100755 --- a/SetLnkApp/MainForm.Designer.cs +++ b/SetLnkApp/MainForm.Designer.cs @@ -28,20 +28,106 @@ /// private void InitializeComponent() { + this.shortcutLabel = new System.Windows.Forms.Label(); + this.path = new System.Windows.Forms.Label(); + this.oldAppLabel = new System.Windows.Forms.Label(); + this.oldApp = new System.Windows.Forms.Label(); + this.newAppLabel = new System.Windows.Forms.Label(); + this.appUserModelId = new System.Windows.Forms.TextBox(); + this.setButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // + // shortcutLabel + // + this.shortcutLabel.AutoSize = true; + this.shortcutLabel.Location = new System.Drawing.Point(13, 13); + this.shortcutLabel.Name = "shortcutLabel"; + this.shortcutLabel.Size = new System.Drawing.Size(74, 20); + this.shortcutLabel.TabIndex = 0; + this.shortcutLabel.Text = "Shortcut:"; + // + // path + // + this.path.Location = new System.Drawing.Point(111, 13); + this.path.Name = "path"; + this.path.Size = new System.Drawing.Size(707, 23); + this.path.TabIndex = 1; + this.path.Text = "Shortcut path"; + // + // oldAppLabel + // + this.oldAppLabel.AutoSize = true; + this.oldAppLabel.Location = new System.Drawing.Point(13, 37); + this.oldAppLabel.Name = "oldAppLabel"; + this.oldAppLabel.Size = new System.Drawing.Size(91, 20); + this.oldAppLabel.TabIndex = 2; + this.oldAppLabel.Text = "Old App ID:"; + // + // oldApp + // + this.oldApp.Location = new System.Drawing.Point(111, 37); + this.oldApp.Name = "oldApp"; + this.oldApp.Size = new System.Drawing.Size(707, 23); + this.oldApp.TabIndex = 3; + this.oldApp.Text = "Old App ID"; + // + // newAppLabel + // + this.newAppLabel.AutoSize = true; + this.newAppLabel.Location = new System.Drawing.Point(13, 61); + this.newAppLabel.Name = "newAppLabel"; + this.newAppLabel.Size = new System.Drawing.Size(98, 20); + this.newAppLabel.TabIndex = 4; + this.newAppLabel.Text = "New App ID:"; + // + // appUserModelId + // + this.appUserModelId.Location = new System.Drawing.Point(115, 61); + this.appUserModelId.Name = "appUserModelId"; + this.appUserModelId.Size = new System.Drawing.Size(515, 26); + this.appUserModelId.TabIndex = 5; + this.appUserModelId.Text = "Microsoft.WindowsTerminal_8wekyb3d8bbwe!App"; + this.appUserModelId.KeyDown += new System.Windows.Forms.KeyEventHandler(this.appUserModelId_KeyDown_KeyDown); + // + // setButton + // + this.setButton.Location = new System.Drawing.Point(638, 59); + this.setButton.Name = "setButton"; + this.setButton.Size = new System.Drawing.Size(99, 30); + this.setButton.TabIndex = 6; + this.setButton.Text = "Set"; + this.setButton.UseVisualStyleBackColor = true; + this.setButton.Click += new System.EventHandler(this.setButton_Click); + // // MainForm // + this.AcceptButton = this.setButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(830, 144); + this.ClientSize = new System.Drawing.Size(749, 99); + this.Controls.Add(this.setButton); + this.Controls.Add(this.appUserModelId); + this.Controls.Add(this.newAppLabel); + this.Controls.Add(this.oldApp); + this.Controls.Add(this.oldAppLabel); + this.Controls.Add(this.path); + this.Controls.Add(this.shortcutLabel); this.Name = "MainForm"; this.Text = "SetLnkApp"; this.ResumeLayout(false); + this.PerformLayout(); } #endregion + + private System.Windows.Forms.Label shortcutLabel; + private System.Windows.Forms.Label path; + private System.Windows.Forms.Label oldAppLabel; + private System.Windows.Forms.Label oldApp; + private System.Windows.Forms.Label newAppLabel; + private System.Windows.Forms.TextBox appUserModelId; + private System.Windows.Forms.Button setButton; } } diff --git a/SetLnkApp/MainForm.Designer.cs b/SetLnkApp/MainForm.Designer.cs index 304b462..f49d018 100755 --- a/SetLnkApp/MainForm.Designer.cs +++ b/SetLnkApp/MainForm.Designer.cs @@ -28,20 +28,106 @@ /// private void InitializeComponent() { + this.shortcutLabel = new System.Windows.Forms.Label(); + this.path = new System.Windows.Forms.Label(); + this.oldAppLabel = new System.Windows.Forms.Label(); + this.oldApp = new System.Windows.Forms.Label(); + this.newAppLabel = new System.Windows.Forms.Label(); + this.appUserModelId = new System.Windows.Forms.TextBox(); + this.setButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // + // shortcutLabel + // + this.shortcutLabel.AutoSize = true; + this.shortcutLabel.Location = new System.Drawing.Point(13, 13); + this.shortcutLabel.Name = "shortcutLabel"; + this.shortcutLabel.Size = new System.Drawing.Size(74, 20); + this.shortcutLabel.TabIndex = 0; + this.shortcutLabel.Text = "Shortcut:"; + // + // path + // + this.path.Location = new System.Drawing.Point(111, 13); + this.path.Name = "path"; + this.path.Size = new System.Drawing.Size(707, 23); + this.path.TabIndex = 1; + this.path.Text = "Shortcut path"; + // + // oldAppLabel + // + this.oldAppLabel.AutoSize = true; + this.oldAppLabel.Location = new System.Drawing.Point(13, 37); + this.oldAppLabel.Name = "oldAppLabel"; + this.oldAppLabel.Size = new System.Drawing.Size(91, 20); + this.oldAppLabel.TabIndex = 2; + this.oldAppLabel.Text = "Old App ID:"; + // + // oldApp + // + this.oldApp.Location = new System.Drawing.Point(111, 37); + this.oldApp.Name = "oldApp"; + this.oldApp.Size = new System.Drawing.Size(707, 23); + this.oldApp.TabIndex = 3; + this.oldApp.Text = "Old App ID"; + // + // newAppLabel + // + this.newAppLabel.AutoSize = true; + this.newAppLabel.Location = new System.Drawing.Point(13, 61); + this.newAppLabel.Name = "newAppLabel"; + this.newAppLabel.Size = new System.Drawing.Size(98, 20); + this.newAppLabel.TabIndex = 4; + this.newAppLabel.Text = "New App ID:"; + // + // appUserModelId + // + this.appUserModelId.Location = new System.Drawing.Point(115, 61); + this.appUserModelId.Name = "appUserModelId"; + this.appUserModelId.Size = new System.Drawing.Size(515, 26); + this.appUserModelId.TabIndex = 5; + this.appUserModelId.Text = "Microsoft.WindowsTerminal_8wekyb3d8bbwe!App"; + this.appUserModelId.KeyDown += new System.Windows.Forms.KeyEventHandler(this.appUserModelId_KeyDown_KeyDown); + // + // setButton + // + this.setButton.Location = new System.Drawing.Point(638, 59); + this.setButton.Name = "setButton"; + this.setButton.Size = new System.Drawing.Size(99, 30); + this.setButton.TabIndex = 6; + this.setButton.Text = "Set"; + this.setButton.UseVisualStyleBackColor = true; + this.setButton.Click += new System.EventHandler(this.setButton_Click); + // // MainForm // + this.AcceptButton = this.setButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(830, 144); + this.ClientSize = new System.Drawing.Size(749, 99); + this.Controls.Add(this.setButton); + this.Controls.Add(this.appUserModelId); + this.Controls.Add(this.newAppLabel); + this.Controls.Add(this.oldApp); + this.Controls.Add(this.oldAppLabel); + this.Controls.Add(this.path); + this.Controls.Add(this.shortcutLabel); this.Name = "MainForm"; this.Text = "SetLnkApp"; this.ResumeLayout(false); + this.PerformLayout(); } #endregion + + private System.Windows.Forms.Label shortcutLabel; + private System.Windows.Forms.Label path; + private System.Windows.Forms.Label oldAppLabel; + private System.Windows.Forms.Label oldApp; + private System.Windows.Forms.Label newAppLabel; + private System.Windows.Forms.TextBox appUserModelId; + private System.Windows.Forms.Button setButton; } } diff --git a/SetLnkApp/MainForm.cs b/SetLnkApp/MainForm.cs index 3a63c06..bfdb731 100755 --- a/SetLnkApp/MainForm.cs +++ b/SetLnkApp/MainForm.cs @@ -1,4 +1,5 @@ -using System; +using ShellLinkPlus; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +13,31 @@ { public partial class MainForm : Form { - public MainForm() - { + private ShellLink shortcut; + public MainForm(ShellLink shortcut) + { InitializeComponent(); + + this.shortcut = shortcut; + this.path.Text = shortcut.ShortcutFile; + this.oldApp.Text = shortcut.AppUserModelID; + } + + private void appUserModelId_KeyDown_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) + { + e.SuppressKeyPress = true; + setButton.PerformClick(); + } + } + + private void setButton_Click(object sender, EventArgs e) + { + shortcut.AppUserModelID = appUserModelId.Text.Trim(); + shortcut.Save(); + + Close(); } } } diff --git a/SetLnkApp/MainForm.Designer.cs b/SetLnkApp/MainForm.Designer.cs index 304b462..f49d018 100755 --- a/SetLnkApp/MainForm.Designer.cs +++ b/SetLnkApp/MainForm.Designer.cs @@ -28,20 +28,106 @@ /// private void InitializeComponent() { + this.shortcutLabel = new System.Windows.Forms.Label(); + this.path = new System.Windows.Forms.Label(); + this.oldAppLabel = new System.Windows.Forms.Label(); + this.oldApp = new System.Windows.Forms.Label(); + this.newAppLabel = new System.Windows.Forms.Label(); + this.appUserModelId = new System.Windows.Forms.TextBox(); + this.setButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // + // shortcutLabel + // + this.shortcutLabel.AutoSize = true; + this.shortcutLabel.Location = new System.Drawing.Point(13, 13); + this.shortcutLabel.Name = "shortcutLabel"; + this.shortcutLabel.Size = new System.Drawing.Size(74, 20); + this.shortcutLabel.TabIndex = 0; + this.shortcutLabel.Text = "Shortcut:"; + // + // path + // + this.path.Location = new System.Drawing.Point(111, 13); + this.path.Name = "path"; + this.path.Size = new System.Drawing.Size(707, 23); + this.path.TabIndex = 1; + this.path.Text = "Shortcut path"; + // + // oldAppLabel + // + this.oldAppLabel.AutoSize = true; + this.oldAppLabel.Location = new System.Drawing.Point(13, 37); + this.oldAppLabel.Name = "oldAppLabel"; + this.oldAppLabel.Size = new System.Drawing.Size(91, 20); + this.oldAppLabel.TabIndex = 2; + this.oldAppLabel.Text = "Old App ID:"; + // + // oldApp + // + this.oldApp.Location = new System.Drawing.Point(111, 37); + this.oldApp.Name = "oldApp"; + this.oldApp.Size = new System.Drawing.Size(707, 23); + this.oldApp.TabIndex = 3; + this.oldApp.Text = "Old App ID"; + // + // newAppLabel + // + this.newAppLabel.AutoSize = true; + this.newAppLabel.Location = new System.Drawing.Point(13, 61); + this.newAppLabel.Name = "newAppLabel"; + this.newAppLabel.Size = new System.Drawing.Size(98, 20); + this.newAppLabel.TabIndex = 4; + this.newAppLabel.Text = "New App ID:"; + // + // appUserModelId + // + this.appUserModelId.Location = new System.Drawing.Point(115, 61); + this.appUserModelId.Name = "appUserModelId"; + this.appUserModelId.Size = new System.Drawing.Size(515, 26); + this.appUserModelId.TabIndex = 5; + this.appUserModelId.Text = "Microsoft.WindowsTerminal_8wekyb3d8bbwe!App"; + this.appUserModelId.KeyDown += new System.Windows.Forms.KeyEventHandler(this.appUserModelId_KeyDown_KeyDown); + // + // setButton + // + this.setButton.Location = new System.Drawing.Point(638, 59); + this.setButton.Name = "setButton"; + this.setButton.Size = new System.Drawing.Size(99, 30); + this.setButton.TabIndex = 6; + this.setButton.Text = "Set"; + this.setButton.UseVisualStyleBackColor = true; + this.setButton.Click += new System.EventHandler(this.setButton_Click); + // // MainForm // + this.AcceptButton = this.setButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(830, 144); + this.ClientSize = new System.Drawing.Size(749, 99); + this.Controls.Add(this.setButton); + this.Controls.Add(this.appUserModelId); + this.Controls.Add(this.newAppLabel); + this.Controls.Add(this.oldApp); + this.Controls.Add(this.oldAppLabel); + this.Controls.Add(this.path); + this.Controls.Add(this.shortcutLabel); this.Name = "MainForm"; this.Text = "SetLnkApp"; this.ResumeLayout(false); + this.PerformLayout(); } #endregion + + private System.Windows.Forms.Label shortcutLabel; + private System.Windows.Forms.Label path; + private System.Windows.Forms.Label oldAppLabel; + private System.Windows.Forms.Label oldApp; + private System.Windows.Forms.Label newAppLabel; + private System.Windows.Forms.TextBox appUserModelId; + private System.Windows.Forms.Button setButton; } } diff --git a/SetLnkApp/MainForm.cs b/SetLnkApp/MainForm.cs index 3a63c06..bfdb731 100755 --- a/SetLnkApp/MainForm.cs +++ b/SetLnkApp/MainForm.cs @@ -1,4 +1,5 @@ -using System; +using ShellLinkPlus; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +13,31 @@ { public partial class MainForm : Form { - public MainForm() - { + private ShellLink shortcut; + public MainForm(ShellLink shortcut) + { InitializeComponent(); + + this.shortcut = shortcut; + this.path.Text = shortcut.ShortcutFile; + this.oldApp.Text = shortcut.AppUserModelID; + } + + private void appUserModelId_KeyDown_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) + { + e.SuppressKeyPress = true; + setButton.PerformClick(); + } + } + + private void setButton_Click(object sender, EventArgs e) + { + shortcut.AppUserModelID = appUserModelId.Text.Trim(); + shortcut.Save(); + + Close(); } } } diff --git a/SetLnkApp/Program.cs b/SetLnkApp/Program.cs index a583108..023999d 100755 --- a/SetLnkApp/Program.cs +++ b/SetLnkApp/Program.cs @@ -1,5 +1,7 @@ -using System; +using ShellLinkPlus; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; @@ -14,9 +16,39 @@ [STAThread] static void Main() { + string[] args = Environment.GetCommandLineArgs(); + + if (args.Length < 2 || !File.Exists(args[1]) || Path.GetExtension(args[1]).ToLower() != ".lnk") + { + Usage(); + return; + } + + ShellLink shortcut = null; + try + { + shortcut = new ShellLink(args[1]); + } + catch (Exception e) + { + Usage(); + return; + } + + if (shortcut == null) + { + Usage(); + return; + } + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); + Application.Run(new MainForm(shortcut)); + } + + private static void Usage() + { + MessageBox.Show("Please drag a .lnk file onto SetLnkApp.exe"); } } }