Skip to content

Commit

Permalink
Install Startup shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
XWolfOverride committed Apr 9, 2015
1 parent aa5773d commit 7135d49
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 31 deletions.
Binary file modified DuckDNS.v12.suo
Binary file not shown.
2 changes: 2 additions & 0 deletions DuckDNS/DuckDNS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShellLink.cs" />
<Compile Include="Windows.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
Expand Down
74 changes: 46 additions & 28 deletions DuckDNS/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions DuckDNS/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

Expand Down Expand Up @@ -138,5 +140,11 @@ private void updateNowToolStripMenuItem_Click(object sender, EventArgs e)
{
UpdateDNS();
}

private void installStartupShortcutToolStripMenuItem_Click(object sender, EventArgs e)
{
string linkPath = Windows.GetStartupPath() + Path.DirectorySeparatorChar + "DuckDNS.lnk";
WShellLink.CreateLink(linkPath,"Duck DNS Updater",Assembly.GetExecutingAssembly().Location);
}
}
}
3 changes: 0 additions & 3 deletions DuckDNS/Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@
<metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>123, 17</value>
</metadata>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>358, 17</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAMAEBAAAAEAIABoBAAANgAAACAgAAABACAAqBAAAJ4EAAAwMAAAAQAgAKglAABGFQAAKAAAABAA
Expand Down
57 changes: 57 additions & 0 deletions DuckDNS/ShellLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;

namespace DuckDNS
{
class WShellLink
{
public static void CreateLink(string name, string description, string path)
{
IShellLink link = (IShellLink)new ShellLink();

// setup shortcut information
link.SetDescription(description);
link.SetPath(path);

// save it
IPersistFile file = (IPersistFile)link;
file.Save(name, false);
}
}

[ComImport]
[Guid("00021401-0000-0000-C000-000000000046")]
class ShellLink
{
}

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("000214F9-0000-0000-C000-000000000046")]
interface IShellLink
{
void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, out IntPtr pfd, int fFlags);
void GetIDList(out IntPtr ppidl);
void SetIDList(IntPtr pidl);
void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName);
void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath);
void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath);
void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
void GetHotkey(out short pwHotkey);
void SetHotkey(short wHotkey);
void GetShowCmd(out int piShowCmd);
void SetShowCmd(int iShowCmd);
void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, out int piIcon);
void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved);
void Resolve(IntPtr hwnd, int fFlags);
void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
}
}
23 changes: 23 additions & 0 deletions DuckDNS/Windows.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace DuckDNS
{
class Windows
{
[DllImport("shell32.dll")]
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner,
[Out] StringBuilder lpszPath, int nFolder, bool fCreate);
const int CSIDL_STARTUP = 0x7;

public static string GetStartupPath()
{
StringBuilder path = new StringBuilder(260);
SHGetSpecialFolderPath(IntPtr.Zero, path, CSIDL_STARTUP, false);
return path.ToString();
}
}
}
Binary file modified DuckDNS/bin/Debug/DuckDNS.exe
Binary file not shown.

0 comments on commit 7135d49

Please sign in to comment.