简体   繁体   English

将system32中的批处理文件目录更改为CMD命令执行点

[英]Change batch file directory in system32 to CMD command execution point

So basically I have a .bat that is inside my System32 folder. 所以基本上我在System32文件夹中有一个.bat。 This batch file accepts a parameter input, this input is a file. 此批处理文件接受参数输入,此输入是文件。 I wanted it to be that I could open my Command Prompt, and for example do 我希望我可以打开命令提示符,例如

batchfile text.txt

And it would pass test.txt into batchfile.bat. 然后它将test.txt传递到batchfile.bat中。 Obviously for my terminal to do this it needs to be in System32. 显然,对于我的终端而言,它必须位于System32中。 That is where my issue is. 那是我的问题所在。 Because the batch file is in System32, when executing the command, it changes my directory to System32. 因为批处理文件在System32中,所以在执行命令时,它将目录更改为System32。

However the parameter I give it is a file. 但是我给它的参数是一个文件。 And when the command is executed and it changes the directory to System32, obviously it can no longer access the file. 并且,当执行该命令并将目录更改为System32时,很显然它将不再能够访问该文件。

How can I get around this? 我该如何解决?

Before you change directories, expand the filename to its fully-qualified filename and then reference it that way: 在更改目录之前,将文件名扩展为其完全限定的文件名,然后以这种方式引用它:

@echo off
for %%F in (%1) do set USR_REQFNM=%%~dpnxF
C:
cd \Windows\System32
echo The requested file is "%USR_REQFNM%"
goto ENDIT

REM Cleanup
:ENDIT
set USR_REQFNM=

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ruby-system32中没有此类文件或目录 - Ruby - No such file or directory in system32 从任务计划程序启动批处理文件指向 C:\Windows\system32 - Starting batch file from Task scheduler point to C:\Windows\system32 如何使用命令提示符或批处理文件在主机文件(位于C:/ windows / system32 / drivers / etc文件夹中)中设置文本? - How to set texts in a hosts file (found in C:/windows/system32/drivers/etc folder) using command prompt or a batch file? System32是Windows中的当前工作目录? - System32 is current working directory in Windows? 在内核中获取System32目录 - Get System32 directory in kernel 使用键盘快捷键时:从 C:\\Windows\\system32 而不是当前目录调用命令 - When using Keyboard Shortcut : Command is being invoked from C:\Windows\system32 instead of Current Directory 如何将 Anaconda 管理员(提升的)命令控制台启动到 Windows 10 UserProfile 目录,而不是“c:\Windows\System32” - How to launch Anaconda Administrator (elevated) Command Console into the Windows 10 UserProfile directory, NOT "c:\Windows\System32" 使用批处理文件将文件从本地文件夹复制到“C:\\ Windows \\ System32 \\” - Copying a file from local folder to “C:\Windows\System32\” using batch file 通过psexec运行位于其他路径(不是System32)上的批处理文件 - Run a batch file located on another path (other than System32) via psexec 复制到system32后文件将被更改 - File will be changed after copying to system32
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM