A batch file that copies another into Start Up folder?

别说谁变了你拦得住时间么 提交于 2020-01-02 10:15:15

问题


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 Name I 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".

I hope this is clear enough.


回答1:


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




回答2:


Open a new command prompt window by executing cmd.exe or using the shortcut in Accessories in Windows start menu. Enter set and look on the list of environment variables predefined by Windows. You are mostly interested in USERPROFILE.

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

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.

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.

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 :EOF 1 or more times with various user account names to prevent doing anything for 1 or more specific users.




回答3:


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

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

works perfectly for me.




回答4:


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

echo %userprofile%

To know the name of current user

For copying 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




回答5:


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.




回答6:


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

This should work.



来源:https://stackoverflow.com/questions/25202660/a-batch-file-that-copies-another-into-start-up-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!