从 USB 复制 .​​bat 并将其复制到启动文件夹脚本 - WinXP

发布于 2024-12-11 23:41:26 字数 309 浏览 0 评论 0原文

我是一名 Mac/iPhone 开发人员,所以我不太了解 Windows 脚本编写... 关键是我必须在许多计算机上安装启动应用程序,所以我想要一个带有两个 .bat 文件的 USB 记忆棒:

  1. 实际的“应用程序”
  2. 将是从我的计算机上复制第 1st.bat 的脚本USB 到 Windows 启动文件夹...

我该怎么做?

我的 USB 的名称是“USB”,我的启动应用程序的名称是“startup.bat”。 我已经说过了,我在 Windows 编程方面非常蹩脚,而且我非常需要它;)

非常感谢!

I'm a Mac/iPhone dev so I don't know very much about Windows scripting...
The point is I have to install a startup app on many computers, so I'd like to have a USB stick with two .bat files:

  1. would be the actual "app"
  2. would be the script that would copy the 1st.bat off my USB to the Windows startup folder...

How can I do that?

the name of my usb is "USB" and the name of my startup app is "startup.bat".
How I already said, I'm extremely lame in Windows programing, and I need it acutely ;)

Thanks A LOT!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

︶ ̄淡然 2024-12-18 23:41:26

尝试以下脚本。这将导致应用程序在当前用户登录时运行。如果没有管理权限,您将无法一次性为所有用户执行此操作。

@Echo Off
CD /D %~dp0
Set StartupFolder=%AppData%\Microsoft\Windows\Start Menu\Programs\Startup
If Exist "%StartupFolder%" Goto :FoundStartup
Set StartupFolder=%UserProfile%\Start Menu\Programs\Startup
If Exist "%StartupFolder%" Goto :FoundStartup
Echo Cannot find Startup folder.
Exit /B

:FoundStartup
Copy "MyApp" "%StartupFolder%"

每行执行以下操作:

  1. 关闭命令回显,使脚本对于最终用户来说看起来更干净。
  2. 将当前目录设置为该脚本所在的位置。
  3. 按照 Windows Vista 或更高版本中的预期设置启动文件夹的路径。
  4. 如果该文件夹存在,则跳转到复制阶段。
  5. 按照 Windows 2000 或更高版本中的预期设置启动文件夹的路径。
  6. 如果该文件夹存在,则跳转到复制阶段。
  7. 报告找不到启动文件夹。
  8. 退出批处理脚本。
     
  9. 可以跳转到的标签。
  10. 将“MyApp”从当前文件夹(USB)复制到启动文件夹。

Try the following script. This will cause the application to run whenever the current user logs in. Without administrative privilages, you won't be able to do it for all users in one go.

@Echo Off
CD /D %~dp0
Set StartupFolder=%AppData%\Microsoft\Windows\Start Menu\Programs\Startup
If Exist "%StartupFolder%" Goto :FoundStartup
Set StartupFolder=%UserProfile%\Start Menu\Programs\Startup
If Exist "%StartupFolder%" Goto :FoundStartup
Echo Cannot find Startup folder.
Exit /B

:FoundStartup
Copy "MyApp" "%StartupFolder%"

Each line does the following:

  1. Turn off command echoing, making the script look cleaner to the end user.
  2. Set the current directory to wherever this script is located.
  3. Set the Startup folder's path as expected in Windows Vista or later.
  4. If this folder exists, jump to the copying stage.
  5. Set the Startup folder's path as expected in Windows 2000 or later.
  6. If this folder exists, jump to the copying stage.
  7. Report that the Startup folder can't be found.
  8. Exit the batch script.
     
  9. A label that can be jumped to.
  10. Copy "MyApp" from the current folder (USB) to the Startup folder.
三五鸿雁 2024-12-18 23:41:26

我不想将 Hand-E-Food 的答案归功于我,但我弄清楚了为什么他的代码不起作用,而且我无法回复他的答案,所以就在这里。不要在 Copy 行中的 %StartupFolder% 变量周围使用引号,而是在 Set StartupFolder 的路径周围使用引号。因此,代码如下。

@Echo Off
CD /D %~dp0
Set StartupFolder="%AppData%\Microsoft\Windows\Start Menu\Programs\Startup"
If Exist %StartupFolder% Goto :FoundStartup
Set StartupFolder="%UserProfile%\Start Menu\Programs\Startup"
If Exist %StartupFolder% Goto :FoundStartup
Echo Cannot find Startup folder.
Exit /B

:FoundStartup
Copy "MyApp" %StartupFolder%

我发现这一点的唯一原因是因为它也没有为我做任何事情,所以我尝试删除 %StartupFolder% 周围的引号,这导致了错误消息它找不到该文件夹​​,但至少我知道它最后正在做一些事情。一旦我发现它正在寻找错误的文件夹,因为它认为文件夹名称停在其名称中的第一个空格处,我只需添加引号即可,瞧!

I don't want to take credit for Hand-E-Food's answer, but I figured out why his code didn't work and I can't reply to his answer, so here it is. Instead of using quotes around the %StartupFolder% variable in the Copy line, use them around the path for Set StartupFolder. Therefore, the code would be as follows.

@Echo Off
CD /D %~dp0
Set StartupFolder="%AppData%\Microsoft\Windows\Start Menu\Programs\Startup"
If Exist %StartupFolder% Goto :FoundStartup
Set StartupFolder="%UserProfile%\Start Menu\Programs\Startup"
If Exist %StartupFolder% Goto :FoundStartup
Echo Cannot find Startup folder.
Exit /B

:FoundStartup
Copy "MyApp" %StartupFolder%

The only reason I figured this out is because it wasn't doing anything for me either, so I tried removing the quotes around %StartupFolder% and that resulted in an error message that it couldn't find the folder, but at least I knew it was doing something at the end. Once I figured out that it was looking for the wrong folder because it thought the folder name stopped at the first space in its name, I simply added in the quotes and voila!

佞臣 2024-12-18 23:41:26

试试这个(将 app.bat 替换为您实际应用程序的名称)。这应该适用于 Windows 2000 及更高版本。

IF EXIST "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\*.*" COPY APP.BAT "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\"
IF EXIST "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\*.*" COPY APP.BAT "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\"

Try this (replace app.bat with whatever your actual app is called). This should work on Windows 2000 and up.

IF EXIST "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\*.*" COPY APP.BAT "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\"
IF EXIST "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\*.*" COPY APP.BAT "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文