Windows 指定批处理文件中需要绝对值的相对路径
我有以下批处理文件:Windows 指定批处理文件中需要绝对值的相对路径,windows,batch-file,relative-path,absolute-path,Windows,Batch File,Relative Path,Absolute Path,我有以下批处理文件: "C:\TapTest\PsExec.exe" /accepteula -i -s "C:\TapTest\tapinstall.exe" -> install "C:\TapTest\driver\OemWin2k.inf" tap0901 批处理文件的位置为: c:\TapTest\TapInstall.bat 我希望能够执行以下操作(使用相对路径): 但是tapinstall.exe需要一个绝对路径作为参数。如何让批处理文件给出绝对路径而不进行硬
"C:\TapTest\PsExec.exe" /accepteula -i -s "C:\TapTest\tapinstall.exe"
-> install "C:\TapTest\driver\OemWin2k.inf" tap0901
批处理文件的位置为:
c:\TapTest\TapInstall.bat
我希望能够执行以下操作(使用相对路径):
但是tapinstall.exe需要一个绝对路径作为参数。如何让批处理文件给出绝对路径而不进行硬编码
"PsExec.exe" /accepteula -i -s "%~dp0tapinstall.exe" install "%~dp0driver\OemWin2k.inf" tap0901
%0
=对当前批处理文件的引用
%~dp0
=批处理文件所在的驱动器和路径
谢谢你。我编辑了您的答案,将
%~dp0
也添加到tapinstall.exe
中。它正在等待审核。@MC ND:如何在PowerShell中实现它..???@Koder101$ScriptDirectory=Split Path$script:MyInvocation.MyCommand.Path
"PsExec.exe" /accepteula -i -s "%~dp0tapinstall.exe" install "%~dp0driver\OemWin2k.inf" tap0901