Skip to content

Commit 0c1dcac

Browse files
Basic implementation extracted from other project
1 parent a28760b commit 0c1dcac

File tree

4 files changed

+158
-0
lines changed

4 files changed

+158
-0
lines changed

Sunnerberg.Autostarter.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sunnerberg.Autostarter", "Sunnerberg.Autostarter\Sunnerberg.Autostarter.csproj", "{4E31FE73-2A4B-4E84-9D84-1709EFF27092}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{4E31FE73-2A4B-4E84-9D84-1709EFF27092}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{4E31FE73-2A4B-4E84-9D84-1709EFF27092}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{4E31FE73-2A4B-4E84-9D84-1709EFF27092}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{4E31FE73-2A4B-4E84-9D84-1709EFF27092}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

Sunnerberg.Autostarter/Autostarter.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Microsoft.Win32;
2+
3+
namespace Sunnerberg.Autostarter
4+
{
5+
/// <summary>
6+
/// Provides tools to allow an executable to be automatically started upon Windows boot.
7+
/// </summary>
8+
public class Autostarter
9+
{
10+
private readonly RegistryKey _registryKey =
11+
Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
12+
13+
private readonly string _executablePath;
14+
15+
/// <summary>
16+
/// Path to the executable which should be automatically started.
17+
/// </summary>
18+
/// <param name="executablePath">Path to the executable</param>
19+
public Autostarter(string executablePath)
20+
{
21+
_executablePath = executablePath;
22+
}
23+
24+
/// <returns>Whether the executable already will be started upon boot</returns>
25+
public bool IsEnabled()
26+
{
27+
return _registryKey.GetValue("ApplicationName") != null;
28+
}
29+
30+
/// <summary>
31+
/// Makes the executable start automatically upon boot.
32+
/// </summary>
33+
public void Enable()
34+
{
35+
_registryKey.SetValue("ApplicationName", _executablePath);
36+
}
37+
38+
/// <summary>
39+
/// Ensures that the executable no longer will be started upon boot.
40+
/// </summary>
41+
public void Disable()
42+
{
43+
_registryKey.DeleteValue("ApplicationName");
44+
}
45+
46+
}
47+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Sunnerberg.Autostarter")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Microsoft")]
12+
[assembly: AssemblyProduct("Sunnerberg.Autostarter")]
13+
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("341151da-8e2b-4d5c-8168-8160dd662909")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{4E31FE73-2A4B-4E84-9D84-1709EFF27092}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Sunnerberg.Autostarter</RootNamespace>
11+
<AssemblyName>Sunnerberg.Autostarter</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
<Reference Include="System.Core" />
35+
<Reference Include="System.Xml.Linq" />
36+
<Reference Include="System.Data.DataSetExtensions" />
37+
<Reference Include="Microsoft.CSharp" />
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Xml" />
40+
</ItemGroup>
41+
<ItemGroup>
42+
<Compile Include="Autostarter.cs" />
43+
<Compile Include="Properties\AssemblyInfo.cs" />
44+
</ItemGroup>
45+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
46+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
47+
Other similar extension points exist, see Microsoft.Common.targets.
48+
<Target Name="BeforeBuild">
49+
</Target>
50+
<Target Name="AfterBuild">
51+
</Target>
52+
-->
53+
</Project>

0 commit comments

Comments
 (0)