Reputation: 10561
As i have only unity build in exe format how can i put it to the startup of my window so that it run automatically when computer becomes start. Remember I don't want to put it manually is there any scripting ref available to do this or else auto solution?
Upvotes: 0
Views: 2114
Reputation: 10561
I want to give my end user an elegant and efficient way to add my exe to Windows startup and here i have managed to provide him batch file in the directory of my exe.
@echo off
Rem This Summary: This batch script will use to add current directories exe file into windows startup folder.
Rem It will work as follow
Rem 1. First search the exe file in the parent directory of this batch file (only one exe should be available next to batch file)
Rem 2. Make its shortcut
Rem 3. paste in sLinkFile(variable name of the location)
set "SCRIPT=%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
::Retriving full path of the .exe which is located in the parent directoy of the batch file(next to batch file)
for %%F in ("%~dp0*.exe") do set "EXEFILE=%%~fF"
> "%SCRIPT%" (
echo Set oWS = WScript.CreateObject^("WScript.Shell"^)
Rem Getting the startup path of the current user
echo sLinkFile = "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\Player.lnk"
Rem creating shortcut
echo Set oLink = oWS.CreateShortcut^(sLinkFile^)
Rem target path alread extracted in line 11
echo oLink.TargetPath = "%EXEFILE%"
Rem save the shortcut
echo oLink.Save
)
cscript //NoLogo "%SCRIPT%"
del "%SCRIPT%"
This file will be placed next to my player build and as user will run this batch file a shortcut of my exe will create automatically and added to the startup. So there is no manual work require just a batch file has to run.
Upvotes: 0
Reputation: 3629
You can add your application to startup with registry https://stackoverflow.com/a/14280290/6720987
You can also place it in the windows startup folder
string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
if (Directory.GetCurrentDirectory() != startupFolder)
{
string path = Path.Combine(startupFolder, "MyFile.exe");
string ownPath = Assembly.GetExecutingAssembly().Location;
if (File.Exists(path))
{
File.Delete(path);
}
File.Copy(ownPath, path);
}
Beware that almost every virus scanner with see this as malicious
Upvotes: 1
Reputation: 17095
In windows 10 you can do this:
FileUtil.CopyFileOrDirectory("unityProject/mygame.exe", "%userprofile%/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/mygame.exe" );
Upvotes: 0