由于我只有Unity格式的统一构建,我如何将它放到我的窗口启动时,以便它在计算机启动时自动运行。请记住,我不想手动添加它是否有任何脚本参考可用于执行此操作或自动解决方案?
答案 0 :(得分:1)
您可以使用注册表将您的应用程序添加到启动 https://stackoverflow.com/a/14280290/6720987
您也可以将其放在Windows启动文件夹
中 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);
}
请注意,几乎每个病毒扫描程序都将此视为恶意
答案 1 :(得分:0)
在Windows 10中,您可以这样做:
FileUtil.CopyFileOrDirectory("unityProject/mygame.exe", "%userprofile%/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/mygame.exe" );
答案 2 :(得分:0)
我想给我的最终用户一个优雅而有效的方法来将我的exe添加到Windows启动中,在这里我已经设法在我的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%"
此文件将放置在我的播放器构建旁边,并且当用户将运行此批处理文件时,我的exe的快捷方式将自动创建并添加到启动。因此,没有手动工作只需要运行批处理文件。