[英]How to set texts in a hosts file (found in C:/windows/system32/drivers/etc folder) using command prompt or a batch file?
[英]Copying a file from local folder to “C:\Windows\System32\” using batch file
我正在编写一个使用批处理文件将一些文件复制到另一个位置的应用程序。 我使用的是64位Windows 7。
我使用以下代码也要求管理员权限:
获取ADMIN权限的代码块 :
@echo off
:: BatchGotAdmin (Run as Admin code starts)
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
)
else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "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"
:: BatchGotAdmin (Run as Admin code ends)
:: Your codes should start from the following line
将文件复制到system32文件夹的代码 :
copy /d /Y "D:\opt\optPath.txt" "C:\Windows\System32\"
复制操作中没有错误,但文件会自动复制到“ C:\\ Windows \\ SysWOW64 ”位置。 需要帮忙。
尝试使用:
@echo off
:: Batch-Admin API
net file>nul 2>&1&&if "%~1"=="64" (goto:GotAdmin) else (if exist "%windir%\Sysnative\" (call start %windir%\Sysnative\cmd /c "%~0" 64&exit) else (goto:GotAdmin))
echo Requesting administrative privileges...
(echo Set UAC = CreateObject^("Shell.Application"^)
echo UAC.ShellExecute "%~s0", "ELEV","", "runas", 0 ) > "%temp%\admin.vbs"
cscript /Nologo "%temp%\admin.vbs"&exit
:GotAdmin
:: Place ADMIN tasks below
copy /d /Y "D:\opt\optPath.txt" "C:\Windows\System32\"
pause
exit
一世 改性 将您的脚本重写为:
net file && echo Admin || echo No-admin
net file && echo Admin || echo No-admin
VBScript
将所有内容启动为32-bit
(将C:\\Windows\\System32
重定向到C:\\Windows\\SysWOW64
)。 64位启动器: call start %WinDir%\\SysNative\\cmd /c %0
(隐藏此窗口)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.