国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > BAT > 正文

CMD命令行中以管理員權限啟動應用程序實現方法

2020-06-09 14:25:49
字體:
來源:轉載
供稿:網友

很多時候我們需要管理員權限來運行bat那么就需要結合vbscript來實現了

方法一:

%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表示含義

~是擴展的意思,相當于把一個相對路徑轉換絕對路徑
%0代指批處理文件自身
%1表示批處理文件命令行接收到的第一個參數,%2表示第二個,以此類推

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东辽县| 武安市| 南江县| 亚东县| 罗城| 东港市| 隆德县| 云龙县| 准格尔旗| 辽阳市| 繁昌县| 库车县| 邮箱| 双辽市| 阿拉尔市| 治多县| 惠东县| 阳原县| 天水市| 徐闻县| 佳木斯市| 延寿县| 台江县| 册亨县| 蒲江县| 扬州市| 教育| 济宁市| 崇左市| 汝阳县| 资阳市| 秦皇岛市| 涟源市| 望谟县| 民权县| 德阳市| 普陀区| 赞皇县| 西峡县| 灵武市| 荥经县|