- MyDownloader_src.zip
- ICSharpCode.SharpZipLib.dll
- Interop.SHDocVw.dll
- MyDownloader.App
- MyDownloader.Core
- MyDownloader.Extension
- MyDownloader.IEPlugin
- MyDownloader.sln
- MyDownloader.Spider
- MyDownloader.Tests
- TabStrip.dll
- MyDownloader_demo.zip
- ffmpeg.exe
- ICSharpCode.SharpZipLib.dll
- MyDownloader.App.exe
- MyDownloader.App.exe.config
- MyDownloader.Core.dll
- MyDownloader.Extension.dll
- MyDownloader.Spider.dll
- pthreadGC2.dll
- TabStrip.dll
|
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.Windows.Forms;
using System.IO;
using System.Security.Permissions;
using System.Security.AccessControl;
namespace MyDownloader.Extension.WindowsIntegration
{
[RegistryPermission(SecurityAction.LinkDemand,
Read = "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
Write = "Software\\Microsoft\\Windows\\CurrentVersion\\Run")]
internal class WindowsStartupUtility
{
private static string GetKeyName()
{
return Path.GetFileNameWithoutExtension(Application.ExecutablePath);
}
private static string GetKeyValue()
{
return String.Format("\"{0}\" /as", Application.ExecutablePath);
}
private static RegistryKey GetRegistryKey()
{
// Create a security context for a new key that we will use to store our data.
// The security context will restrict access to only our user.
string user = Environment.UserDomainName + "\\" + Environment.UserName;
RegistrySecurity security = new RegistrySecurity();
RegistryAccessRule rule = new RegistryAccessRule(user,
RegistryRights.FullControl,
InheritanceFlags.ContainerInherit,
PropagationFlags.None,
AccessControlType.Allow);
security.AddAccessRule(rule);
RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run",
RegistryKeyPermissionCheck.ReadWriteSubTree, security);
return key;
}
public static bool IsRegistered()
{
using (RegistryKey key = GetRegistryKey())
{
string value = key.GetValue(GetKeyName(), null) as string;
return value != null && value.Equals(GetKeyValue(), StringComparison.OrdinalIgnoreCase);
}
}
public static void Register(bool register)
{
using (RegistryKey key = GetRegistryKey())
{
if (register)
{
key.SetValue(GetKeyName(), GetKeyValue(), RegistryValueKind.String);
}
else
{
key.DeleteValue(GetKeyName(), false);
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.