食用方法:
run in dos or dobule click file end by cmd and bat. 不适用,仅作参考,具体问题,具体分析。
cmd 读取文件:
@echo off
rem bat命令读取文件示例
rem 判断文件是否存在
if not exist versions.txt (
echo versions.txt file not exist
goto end
)
rem 读取文件,每次读取一行,默认以空格分隔,默认取第一列
for /f %%i in ('type versions.txt') do (
echo %%i
)
rem tokens用来指定获取的列数
rem tokens=1-2,表示取第1列到第2列的内容
rem tokens=1,2,表示取第1列和第2列的内容
rem tokens=*,表示取整行
for /f "tokens=*" %%i in ('type versions.txt') do (
echo %%i
)
for /f "tokens=1-2" %%i in ('type versions.txt') do (
echo %%i %%j
)
rem 修改分隔符为.号
rem delims=.-,表示以.或者-分隔
for /f "delims=." %%i in ('type versions.txt') do (
echo %%i
)
:end
echo Press any key to continue
cmd管理员运行:
方法1:
@ echo off
%1 %2
ver|find "5.">nul&&goto :Admin
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :Admin","","runas",1)(window.close)&goto :eof
:Admin
//在你的bat开头加上上面的命令即可
//下面是你需要执行的命令
set path=%~dp0
echo install mysql service...
echo %path%
cd %path%in
mysqld.exe --remove mysql
mysqld.exe --install mysql
echo start mysql Serviceo
"%SystemRoot%"system32
et start mysql
方法2:
@echo off
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd /d "%~dp0"
写在bat文件的顶端就可以实现。
方法3:
@ECHO OFF
setlocal EnableDelayedExpansion
color 3e
title 添加服务配置
PUSHD %~DP0 & cd /d "%~dp0"
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :eof
:runas
::填写自己的脚本
echo 执行完毕,任意键退出
pause >nul
exit
方法4:
@echo off&color 17
if exist "%SystemRoot%SysWOW64" path %path%;%windir%SysNative;%SystemRoot%SysWOW64;%~dp0
bcdedit >nul
if '%errorlevel%' NEQ '0' (goto UACPrompt) else (goto UACAdmin)
:UACPrompt
%1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit
exit /B
:UACAdmin
cd /d "%~dp0"
echo 当前运行路径是:%CD%
echo 已获取管理员权限
方法5:
@echo off
>nul 2>&1 "%SYSTEMROOT%system32cacls.exe" "%SYSTEMROOT%system32configsystem"
if '%errorlevel%' NEQ '0' (
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" )
方法6:
适用于无参数
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c "^&chr(34)^&"%~0"^&chr(34)^&" ::","%cd%","runas",1)(window.close)&&exit
适用于一参数
%2 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c "^&chr(34)^&"%~0"^&chr(34)^&" "^&chr(34)^&"%~1"^&chr(34)^&" ::","%cd%","runas",1)(window.close)&&exit
转载此文是出于传递更多信息目的。若来源标注错误或侵犯了您的合法权益,请与本站联系,我们将及时更正、删除、谢谢。
https://www.414w.com/read/378400.html