批处理文件更改(适用于Vista) [英] batch file changes (for Vista)

查看:64
本文介绍了批处理文件更改(适用于Vista)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我直到现在,并且在WinXP上工作正常以下:
- 进入我的应用程序目录,C:\Program Files \ MyAppApp a second_app.exe需要管理员权限来运行
- 进入我的同一个目录:MyTrace.bat包含以下行:
second_app.exe> MyTrace.txt
second_app.exe>> MyTrace.txt
- 当用户遇到一个非常具体的问题(意味着很少)时,他必须双击MyTrace.bat,这将在同一个目录中生成MyTrace.txt,然后应该发送在某个地方。

现在,这种情况在Vista b / c上不起作用:
- 如果我双击MyTrace.bat,MyTrace.txt的创建将失败,因为它在Program Files中控制台的">"和">>"将失败
- 如果我右键单击该批次并说"以管理员身份运行"控制台实际上会提示系统32,因此不会发现second_app.exe被运行

我当然知道我可以将.bat更改为:
second_app.exe> %TEMP%\ MyTrace.txt
second_app.exe>> %TEMP%\ MyTy.txt
它会工作,但我想找到一个方法,以便在MyTrace.bat所在的同一目录中生成MyTrace.txt。有没有办法做到这一点? (例如,如果在批处理文件的最开始,我可以以某种方式将目录更改为此批处理文件所在的目录(不知道如何操作),然后批处理可以使用"以管理员身份运行"运行;)。

谢谢,
Viv

推荐答案

所以在前面添加一个%~dp0您在批处理文件中执行的操作可以为您提供位置独立性,而无需执行硬编码路径或许多  ..到处都是。因此,以下将始终找到"sometool.exe"。无论在哪里运行,都会坐在
批处理文件的旁边。

So adding a %~dp0 in front of things you do in the batch file give you location independence without having to do hard-coded paths or a lot of  ..\..'s all over the place. So the following will always find the "sometool.exe" sitting right next to the batch file no matter where it's run from.

注意:最佳做法是,加上引号"%~dp0sometool.exe"

这可以确保解释带有空格的路径。

Note: As a best practice, include the quotes "%~dp0sometool.exe"
this ensures that paths with spaces in them will be interpreted.

使用您的批处理文件,例如......

Using your batch file for example...

   "%〜dp0second_app.exe" > "% - dp0MyTrace.txt"

   "%〜dp0second_app.exe" >> " %% dp0MyTrace.txt"

   "%~dp0second_app.exe" > "%~dp0MyTrace.txt"
   "%~dp0second_app.exe" >> "%~dp0MyTrace.txt"

这应该可以在与second_app.exe相同的文件夹中创建输出MyTrace.txt

This should work to create the output MyTrace.txt in the same folder as the second_app.exe

希望这会有所帮助,

GC


这篇关于批处理文件更改(适用于Vista)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆