Skip to content

Commit

Permalink
allow app to start when the computer powers up by adding shortcut to …
Browse files Browse the repository at this point in the history
…startup folder
  • Loading branch information
Coderkoss committed Dec 31, 2020
1 parent 2c497d1 commit be63c22
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 22 deletions.
93 changes: 93 additions & 0 deletions .vsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.NetCore.Component.Runtime.3.1",
"Microsoft.NetCore.Component.SDK",
"Microsoft.VisualStudio.Component.NuGet",
"Microsoft.Net.Component.4.6.1.TargetingPack",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices",
"Microsoft.VisualStudio.Component.FSharp",
"Microsoft.NetCore.Component.DevelopmentTools",
"Microsoft.VisualStudio.Component.FSharp.WebTemplates",
"Microsoft.VisualStudio.ComponentGroup.WebToolsExtensions",
"Microsoft.VisualStudio.Component.DockerTools",
"Microsoft.NetCore.Component.Web",
"Microsoft.Net.Component.4.8.SDK",
"Microsoft.Net.Component.4.7.2.TargetingPack",
"Microsoft.Net.ComponentGroup.DevelopmentPrerequisites",
"Microsoft.VisualStudio.Component.TypeScript.3.9",
"Microsoft.VisualStudio.Component.JavaScript.TypeScript",
"Microsoft.VisualStudio.Component.JavaScript.Diagnostics",
"Microsoft.Component.MSBuild",
"Microsoft.VisualStudio.Component.TextTemplating",
"Component.Microsoft.VisualStudio.RazorExtension",
"Microsoft.VisualStudio.Component.IISExpress",
"Microsoft.VisualStudio.Component.SQL.ADAL",
"Microsoft.VisualStudio.Component.SQL.LocalDB.Runtime",
"Microsoft.VisualStudio.Component.Common.Azure.Tools",
"Microsoft.VisualStudio.Component.SQL.CLR",
"Microsoft.VisualStudio.Component.MSODBC.SQL",
"Microsoft.VisualStudio.Component.MSSQL.CMDLnUtils",
"Microsoft.VisualStudio.Component.ManagedDesktop.Core",
"Microsoft.Net.Component.4.5.2.TargetingPack",
"Microsoft.Net.Component.4.5.TargetingPack",
"Microsoft.VisualStudio.Component.SQL.SSDT",
"Microsoft.VisualStudio.Component.SQL.DataSources",
"Component.Microsoft.Web.LibraryManager",
"Microsoft.VisualStudio.ComponentGroup.Web",
"Microsoft.VisualStudio.Component.Web",
"Microsoft.VisualStudio.Component.IntelliCode",
"Microsoft.Net.Component.4.TargetingPack",
"Microsoft.Net.Component.4.5.1.TargetingPack",
"Microsoft.Net.Component.4.6.TargetingPack",
"Microsoft.Net.ComponentGroup.TargetingPacks.Common",
"Microsoft.Net.Core.Component.SDK.2.1",
"Component.Microsoft.VisualStudio.Web.AzureFunctions",
"Microsoft.VisualStudio.ComponentGroup.AzureFunctions",
"Microsoft.VisualStudio.Component.Azure.Compute.Emulator",
"Microsoft.VisualStudio.Component.Azure.Storage.Emulator",
"Microsoft.VisualStudio.Component.Azure.ClientLibs",
"Microsoft.VisualStudio.Component.Azure.AuthoringTools",
"Microsoft.VisualStudio.Component.CloudExplorer",
"Microsoft.VisualStudio.ComponentGroup.Web.CloudTools",
"Microsoft.VisualStudio.Component.DiagnosticTools",
"Microsoft.VisualStudio.Component.EntityFramework",
"Microsoft.VisualStudio.Component.AspNet45",
"Microsoft.VisualStudio.Component.AppInsights.Tools",
"Microsoft.VisualStudio.Component.WebDeploy",
"Component.Microsoft.VisualStudio.LiveShare",
"Microsoft.Net.Component.4.7.1.TargetingPack",
"Microsoft.VisualStudio.Workload.NetWeb",
"Microsoft.VisualStudio.Component.VC.CoreIde",
"Microsoft.VisualStudio.Component.Windows10SDK",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"Microsoft.VisualStudio.Component.Graphics.Tools",
"Microsoft.VisualStudio.Component.VC.DiagnosticTools",
"Microsoft.VisualStudio.Component.Windows10SDK.18362",
"Microsoft.VisualStudio.Component.Node.Tools",
"Microsoft.VisualStudio.Workload.Node",
"Microsoft.VisualStudio.Component.ManagedDesktop.Prerequisites",
"Microsoft.ComponentGroup.Blend",
"Microsoft.VisualStudio.Component.Debugger.JustInTime",
"Microsoft.VisualStudio.Component.DotNetModelBuilder",
"Microsoft.VisualStudio.Workload.ManagedDesktop",
"Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
"Microsoft.VisualStudio.ComponentGroup.WebToolsExtensions.CMake",
"Microsoft.VisualStudio.Component.VC.CMake.Project",
"Microsoft.VisualStudio.Component.VC.ATL",
"Microsoft.VisualStudio.Component.VC.TestAdapterForBoostTest",
"Microsoft.VisualStudio.Component.VC.TestAdapterForGoogleTest",
"Microsoft.VisualStudio.Component.VC.ASAN",
"Microsoft.VisualStudio.Workload.NativeDesktop",
"Microsoft.Net.Component.3.5.DeveloperTools",
"Microsoft.VisualStudio.Component.Unity",
"Component.UnityEngine.x64",
"Component.UnityEngine.x86",
"Microsoft.VisualStudio.Workload.ManagedGame",
"Microsoft.VisualStudio.Workload.NativeGame"
]
}
93 changes: 92 additions & 1 deletion TextSpeech/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
using IWshRuntimeLibrary;

namespace TextSpeech
{
Expand All @@ -15,7 +18,12 @@ static class Program
private static LowLevelKeyboardProc _proc = HookCallback;
private static IntPtr _hookID = IntPtr.Zero;
public static TextSpeaker speaker;

const int CSIDL_COMMON_STARTUP = 0x0018;
const int CSIDL_STARTUP = 0x0018;

[DllImport("shell32.dll")]
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out] StringBuilder lpszPath, int nFolder, bool fCreate);

[STAThread]
static void Main()
{
Expand All @@ -24,10 +32,92 @@ static void Main()
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
speaker = new TextSpeaker();
//check to see if the app.exe exist in the startup folder
CreateStartupShortcut();
Application.Run(speaker);
UnhookWindowsHookEx(_hookID);


}

public static string FindStartupFolder()
{
String path;
//SHGetSpecialFolderPath(IntPtr.Zero, path, CSIDL_COMMON_STARTUP, false);
path = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
return path.ToString();
}
private static string getAppShortcutFileName()
{
return Path.Combine(FindStartupFolder(), Application.ProductName) + ".lnk";
}
public static bool CheckStartupFileExist()
{
return System.IO.File.Exists(getAppShortcutFileName());
}
public static string Createlocalshortcut()
{
//TODO: this method needs to be fixed
string shortcutPath = Application.StartupPath;
string shortcutLocation = System.IO.Path.Combine(shortcutPath, @"textSpeech" + ".lnk");

//Create all users desktop shortcut for application settings
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
shortcut.TargetPath = Application.ExecutablePath;
shortcut.IconLocation = @"icon1";
shortcut.Description = "Description";
shortcut.Save();

return shortcutLocation;

}
public static bool CreateStartupShortcut()
{
//Createlocalshortcut();
bool retval = false;
string shortcutName = Createlocalshortcut();
FileInfo shortcutFile = new FileInfo(shortcutName);
FileInfo destination = new FileInfo(getAppShortcutFileName());

if (destination.Exists)
{
//run overwrite code
retval = CopyShortcut(shortcutFile,destination);
}
else if (!shortcutFile.Exists)
{
MessageBox.Show("Unable to RunOnStartup becasue the local shortcut cant be found.");
}
else
{
retval = CopyShortcut(shortcutFile,destination);
}


return retval;
}
public static bool CopyShortcut(FileInfo src, FileInfo dest)
{
bool retVal = false;
try
{
//System.IO.File.Copy(src.FullName, dest.FullName, true); you need to run this to overwrite the file
System.IO.File.Copy(src.FullName,dest.FullName);
retVal = true;
}
catch (UnauthorizedAccessException authEX)
{
MessageBox.Show(string.Format("UnauthorizedAccessException: {0}",authEX.Message), "Copy Shortcut", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Copy Shortcut", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
return retVal;
}
/// <summary>
/// This method sets up the windows hook for the keyboard proc
/// </summary>
Expand Down Expand Up @@ -74,6 +164,7 @@ private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);


}
#endregion

Expand Down
10 changes: 0 additions & 10 deletions TextSpeech/Properties/Resources.Designer.cs

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

3 changes: 0 additions & 3 deletions TextSpeech/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,4 @@
<data name="icon1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon1.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="totallyradshowbg" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\totallyradshowbg.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
24 changes: 16 additions & 8 deletions TextSpeech/TextSpeech.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<IsWebBootstrapper>false</IsWebBootstrapper>
<TargetFrameworkProfile />
<PublishUrl>C:\Users\white\Desktop\New folder\</PublishUrl>
<PublishUrl>C:\Users\white\Desktop\test\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
Expand All @@ -24,7 +24,6 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<AutorunEnabled>true</AutorunEnabled>
<ApplicationRevision>6</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
Expand Down Expand Up @@ -78,6 +77,10 @@
<Win32Resource>
</Win32Resource>
</PropertyGroup>
<PropertyGroup />
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -130,11 +133,6 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
Expand All @@ -146,7 +144,17 @@
<Content Include="Resources\icon1.ico" />
<None Include="Resources\totallyradshowbg.jpg" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down

0 comments on commit be63c22

Please sign in to comment.