a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > BAT > 正文

CMD命令行中以管理員權(quán)限啟動(dòng)應(yīng)用程序?qū)崿F(xiàn)方法

2020-06-09 14:25:49
字體:
供稿:網(wǎng)友

很多時(shí)候我們需要管理員權(quán)限來運(yùn)行bat那么就需要結(jié)合vbscript來實(shí)現(xiàn)了

方法一:

%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit

常用

@echo offmode con lines=30 cols=60%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exitcd /d "%~dp0"rem 下面可以寫你的bat代碼了

方法二:

@echo off %1 %2 ver|find "5.">nul&&goto :st mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :st","","runas",1)(window.close)&goto :eof :st copy "%~0" "%windir%/system32/"

原理類似

ShellExecute method

Run a script or application in the Windows Shell.

Syntax
.ShellExecute "application", "parameters", "dir", "verb", window

.ShellExecute 'some program.exe', '"some parameters with spaces"', , "runas", 1
Key
application The file to execute (required)
parameters Arguments for the executable
dir Working directory
verb The operation to execute (runas/open/edit/print)
window View mode application window (normal=1, hide=0, 2=Min, 3=max, 4=restore, 5=current, 7=min/inactive, 10=default)
Note the different (double " and single ' ) quotes that can be used to delimit paths with spaces.

The runas verb is undocumented but can be used to elevate permissions. When a script is run with elevated permissions several aspects of the user environment may change: The current directory, the current TEMP folder and any mapped drives will be disconnected.

runas will fail if you are running in WOW64 (a 32 bit process on 64 bit windows) for example %systemroot%/syswow64/cmd.exe ...

The ShellExecute method is a member of the IShellDispatch2 object.

Examples

Run a batch script with elevated permissions, flag=runas:

Set objShell = CreateObject("Shell.Application")objShell.ShellExecute "E:/demo/batchScript.cmd", "", "", "runas", 1

Run a VBScript with elevated permissions, flag=runas:

Set objShell = CreateObject("Shell.Application")objShell.ShellExecute "cscript", "E:/demo/vbscript.vbs", "", "runas", 1

“If you don't execute your ideas, they die” ~ Roger Von Oech

Related:

Run with elevated permissions - Script to run as Admin
.Exec - Execute command, returning an object
.Run - Run a command
joeware.net - CPAU (Create Process As User) like RunAs but with an options to encrypt the password.
Equivalent CMD command: ShellRunAs - Run a command under a different user account

 批處理文件中的%~dp0表示含義

~是擴(kuò)展的意思,相當(dāng)于把一個(gè)相對(duì)路徑轉(zhuǎn)換絕對(duì)路徑
%0代指批處理文件自身
%1表示批處理文件命令行接收到的第一個(gè)參數(shù),%2表示第二個(gè),以此類推

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 五月婷婷丁香 | 精品欧美一二三区 | www.伊人网 | 国产精品毛片无码 | 日本免费精品 | 最近中文字幕在线视频1 | 在线观看视频一区二区 | 久久久久久久久久久免费 | 日本精品视频在线观看 | 国产91亚洲精品 | 久久精品视频亚洲 | 国产精品一区二区三区在线 | 91色爱| 国产精品久久毛片 | 成人精品一区二区三区 | 日韩不卡一区二区 | 成人精品在线 | 日本一区二区不卡 | av在线二区| 黄色电影天堂 | 亚洲黄色毛片 | 久久久精品一区二区三区 | 黄色大片免费网站 | 国产精品久久久久久久久久久久冷 | 日本精品在线观看 | 免费看黄色的网址 | 亚洲成人精品在线 | 国产在视频一区二区三区吞精 | 欧美精品在线观看 | 欧美成人一区二区三区 | 日韩欧洲亚洲 | 亚洲精品久久久久久久久久久久久 | 国产精品1区2区 | 欧美成人一区二区 | 欧美成人一级片 | 看欧美黄色录像 | 日本天天操 | 国产黄色免费网站 | 黄在线看 | 久久精品91 | 黄网在线免费观看 |