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?
Asked
Active
Viewed 1,752 times
0
-
What do you mean by "I don't want to put it manually" ? It's the best way that you add the exe in Start up – Sachin Oct 19 '16 at 08:44
-
@Sachin actually user dont know how to put the application on startup so that i want to put my exe on startup automatically – Muhammad Faizan Khan Oct 19 '16 at 09:08
3 Answers
1
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
-
-
I have now experience with unity. But you should place it in a function that runs on start – Pepernoot Oct 19 '16 at 09:55
-
ok i got your meaning but is their any way available to exe name also so that i can put it automatically. – Muhammad Faizan Khan Oct 19 '16 at 09:58
-
how do i folder also at there? because it is mandatory to add folder with exe – Muhammad Faizan Khan Oct 19 '16 at 10:30
-
if the exe is open and i run this code then it is not fully copy the exe. So what to do if exe is open and you want to copy – Muhammad Faizan Khan Oct 20 '16 at 04:27
0
In windows 10 you can do this:
FileUtil.CopyFileOrDirectory("unityProject/mygame.exe", "%userprofile%/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/mygame.exe" );

Bizhan
- 16,157
- 9
- 63
- 101
-
This will also copy when already in startup folder, Causing an exeption – Pepernoot Oct 19 '16 at 08:51
-
0
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.

Muhammad Faizan Khan
- 10,013
- 18
- 97
- 186