【发布时间】:2015-06-26 09:42:25
【问题描述】:
我的 .bat 文件如下所示:
@echo off
CD /D "%~dp0"
if [%2]==[] (
set user=%USERNAME%
) else (
set user=%2%
)
:getFile
if [%1]==[] (
set /p file=Enter file name :
) else (
set file=%~f1
echo File name: %~f1
)
:checkFile
for /f "useback tokens=*" %%a in ('%file%') do set file=%%~a
if not exist "%file%" (
echo Error: Could not find file: %file%
echo.
)
:: Check for admin permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' == '0' (
goto gotAdmin
)
:: Rerun this batch with admin rights
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "cmd", "/c """"%~f0"" ""%file%"" ""%user%""""", "%CD%", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
echo.
:eof
pause
exit /B
我有这两个测试文件:
- C:\Test\Folder\ファイル.txt
- C:\Test\フォルダ\File.txt
当我运行上面的批处理文件并将 1 拖到 cmd 窗口上时,我得到:
,这很好。
当我对 2 做同样的事情时,我得到:
当我调用 UAC.ShellExecute 时,%file% 未正确传递。
我怎样才能解决这个问题?
【问题讨论】:
-
set user=%2%在批处理代码的第 8 行应为set user=%2,末尾没有百分号。
标签: windows batch-file unicode dos