windows 将另一个复制到启动文件夹的批处理文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25202660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:38:45  来源:igfitidea点击:

A batch file that copies another into Start Up folder?

windowsbatch-filecopycommandwildcard

提问by IDK

I am making a batch file that needs to copy another batch file into the Start Menu Start Up folder(the one used when a program launches on login/start up). Since the path uses the user's computer name eg. C:\Documents and Settings\User NameI need the batch file to get the user's correct name instead of the "User Name" or *(wildcard). Wildcards doesn't work as the batch file comes up with "the filename directory name or volume label syntax is incorrect".

我正在制作一个批处理文件,需要将另一个批处理文件复制到“开始”菜单“启动”文件夹(在登录/启动程序时使用的文件夹。由于路径使用用户的计算机名称,例如。C:\Documents and Settings\User Name我需要批处理文件来获取用户的正确名称,而不是“用户名”或*(通配符)。通配符不起作用,因为批处理文件出现“文件名目录名称或卷标语法不正确”。

I hope this is clear enough.

我希望这已经足够清楚了。

回答by zask

You can also try this:

你也可以试试这个:

cd %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup

It works in Windows 10. The %appdata%variable gives you your required username by default

它适用于 Windows 10。%appdata%默认情况下,该变量为您提供所需的用户名

回答by Mofi

Open a new command prompt window by executing cmd.exeor using the shortcut in Accessoriesin Windows start menu. Enter setand look on the list of environment variables predefined by Windows. You are mostly interested in USERPROFILE.

通过执行cmd.exe或使用AccessoriesWindows 开始菜单中的快捷方式打开一个新的命令提示符窗口。输入set并查看 Windows 预定义的环境变量列表。您最感兴趣的是USERPROFILE

The following command can be used to copy a batch file with name AaRM.batfrom a folder available for all users like the all users desktop folder to startup folder of the currently logged in user.

以下命令可用于将名称AaRM.bat为所有用户可用的文件夹(如所有用户桌面文件夹)中的批处理文件复制到当前登录用户的启动文件夹中。

copy "%ALLUSERSPROFILE%\Desktop\AaRM.bat" "%USERPROFILE%\Start Menu\Programs\Startup"

The double quotes are important as the name of the batch file with path and the path to the startup folder both contain spaces.

双引号很重要,因为带有路径的批处理文件的名称和启动文件夹的路径都包含空格。

Copying the batch file from your desktop folder to the startup folder of the other user is most likely not possible as the other user might have no permission to access anything in your user profile directory and below.

很可能无法将批处理文件从您的桌面文件夹复制到其他用户的启动文件夹,因为其他用户可能无权访问您的用户配置文件目录及以下的任何内容。

You can copy the batch file to distribute also to a different folder accessible for all users like "%ProgramFiles%"or %SystemRoot%as the batch file in all users desktop folder is visible for all user accounts on desktop.

您可以复制批处理文件以分发到所有用户都可以访问的不同文件夹,例如"%ProgramFiles%"%SystemRoot%因为所有用户桌面文件夹中的批处理文件对桌面上的所有用户帐户都是可见的。

Best would be to put the batch file into Windows directory (%SystemRoot%or %windir%) and create / copy a shortcut file (*.lnk) in / to startup folder of the other user accounts. The Windows start menu folders should contain only *.lnk files and not batch files and applications.

最好将批处理文件放入 Windows 目录(%SystemRoot%%windir%)并在 / 中创建/复制快捷方式文件(*.lnk)到其他用户帐户的启动文件夹。Windows 开始菜单文件夹应该只包含 *.lnk 文件,而不是批处理文件和应用程序。

And last it would be also possible to create a shortcut in "%ALLUSERSPROFILE%\Start Menu\Programs\Startup"to the batch file in %windir%to execute this batch file for any user who logs in on this computer. Your batch file could contain at top something like if "%USERNAME%"=="your account name" goto :EOF1 or more times with various user account names to prevent doing anything for 1 or more specific users.

最后,还可以创建"%ALLUSERSPROFILE%\Start Menu\Programs\Startup"批处理文件的快捷方式,以便%windir%为登录此计算机的任何用户执行此批处理文件。您的批处理文件可以在顶部包含if "%USERNAME%"=="your account name" goto :EOF1 次或多次不同用户帐户名称的内容,以防止为 1 个或多个特定用户执行任何操作。

回答by jitesh

try the following command if u r using win 7. never tried on win 8 though.

如果您使用的是 win 7,请尝试以下命令。不过从未尝试过 win 8。

cd C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

cd C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

works perfectly for me.

非常适合我。

回答by Kingzel

Stumped about nobody answering yet..Why are we so lost?

为没有人回答而难倒..为什么我们如此迷茫?

echo %userprofile%

To know the name of current user

知道当前用户的名字

For copyingCopy /y %~f0 "%USERPROFILE%\%AppData%\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

用于复制Copy /y %~f0 "%USERPROFILE%\%AppData%\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Alternative copy "path of file you want to copy" "path of the directory where you want it copied"

替代副本“要复制的文件的路径”“要复制的目录的路径”

copy path of batch file path of startup folder

启动文件夹的批处理文件路径的复制路径

回答by KSP

Copy /y "File-Address-to-copy-here" "where-to-copy-to-here"
(as above) then save file as .bat and you have a batch file, run as admin if in system directories.

复制 /y "File-Address-to-copy-here" "where-to-copy-to-here"
(如上所述),然后将文件另存为 .bat 并且您有一个批处理文件,如果在系统目录中,则以管理员身份运行。

回答by Guest

copy "C:\Documents and Settings\%username%\Desktop\batch.bat" "C:\Documents and Settings\%username%\Start Menu\Programs\Startup\"

This should work.

这应该有效。

回答by Matmamba

Try this:

尝试这个:

copy "CopyPath" "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"

Also, if you want to skip the username for the copy path, then use %username%instead of the actual username.

此外,如果您想跳过复制路径的用户名,请使用%username%而不是实际用户名。

回答by ando100

This works:

这有效:

@echo off
copy "C:\Users\%username%\Desktop\somefolder\example.bat" "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"