windows 以管理员身份运行 代码
1 // 以管理员身份运行本进程
2 // 1 获取本进程的文件路径.
3 TCHAR path[MAX_PATH] = { 0 }; // 需要初始化
4 DWORD dwPathSize = MAX_PATH;
5 QueryFullProcessImageName(GetCurrentProcess(), 0,
6 path,
7 &dwPathSize);
8
9 // 2 调用创建进程的API运行本进程.
10 ShellExecute(NULL, // 窗口句柄,没有则填NULL
11 _T("runas"), // 以管理员身份运行的重要参数
12 path, // 所有运行的程序的路径(这里是本进程)
13 NULL, // 命令行参数
14 NULL, // 新进程的工作目录的路径
15 SW_SHOW // 创建后的显示标志(最小化,最大化, 显示,隐藏等)
16 );
17
18 // 退出本进程
19 ExitProcess(0);
参考:
windows权限管理 https://www.jianshu.com/p/d3efa5598596
windows 以管理员身份运行 代码的更多相关文章
- WinForm 代码实现以管理员身份运行
[STAThread] static void Main(string[] Args) { //获得当前登录的Windows用户标示 System.Security.Principal.Windows ...
- Windows 10 上强制Visual Studio以管理员身份运行
Windows 10 的一个既安全又蛋疼之处是UAC的行为被改变了.以往在Windows 7中,只要关闭了UAC,自己的帐号又是本机管理员组的,任何程序都会以管理员身份启动.然而,在Windows 8 ...
- 【CITE】C#默认以管理员身份运行程序实现代码
//用于一种情况:C#软件打包后,在读写C盘文件时,会出现权限问题.使用管理员身份才可以运行 using System; using System.Collections.Generic; using ...
- Windows 8上强制Visual Studio以管理员身份运行
原文链接:http://edi.wang/post/2013/2/28/force-visual-studio-always-run-as-admin-on-windows-8 Windows 8的一 ...
- 转:Windows 8上强制Visual Studio以管理员身份运行
Windows 8的一个既安全又蛋疼之处是UAC的行为被改变了.以往在Windows 7中,只要关闭了UAC,自己的帐号又是本机管理员组的,任何程序都会以管理员身份启动.然而,在Windows 8上, ...
- C#默认以管理员身份运行程序实现代码
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; names ...
- windows中以管理员身份运行cmd
开始->所有程序->附件->命令提示符->右键,以管理员身份运行(win10可以直接搜索cmd,右键,以管理员身份运行)
- C# 管理员身份运行程序
在使用winform程序获取调用cmd命令提示符时,如果是win7以上的操作系统,会需要必须以管理员身份运行才会执行成功,否则无效果或提示错误. 比如在通过winform程序执行cmd命令时,某些情况 ...
- Win7下判断当前进程是否以管理员身份运行
判断当前程序是否以管理员身份运行,代码如下: #include <iostream> #include <windows.h> using namespace std; // ...
随机推荐
- js map & Number
js map & Number const regionIds = `1,2,3`; // "1,2,3" regionIds.split(',').map(Number) ...
- 末日余晖 PC 版 下载
末日余晖 PC 版 下载 <末日余晖>(英文名:Farlight 84)一款废土题材的射击游戏 Farlight 84 Official Trailer Farlight 84 官方预告片 ...
- convert URL Query String to Object All In One
convert URL Query String to Object All In One URL / query string / paramas query string to object le ...
- auto embedded component in an online code editor
auto embedded component in an online code editor how to auto open a component in the third parts onl ...
- nodejs 查看进程表
psaux tasklist system-tasks const { exec } = require("child_process"); const isWindows = p ...
- 黑马来袭!NGK生态所二月上线!
日前,加密货币交易所Coinbase Global Inc,向美国证券交易委员会申请首次公开募股,成为首家公开上市的加密货币交易所."Coinbase上市,给行业带来更多的是信心.让大家看到 ...
- vue最好的ssr服务器渲染框架
vue和angular js.react三大框架非常好用,现在大部分人都使用了这三大框架进行开发. 但是vue这些框架到目前位置,大部分还是用来做管理后台,用来做移动端.而官网网站却很少用他们来开发. ...
- Java并发包源码学习系列:同步组件CountDownLatch源码解析
目录 CountDownLatch概述 使用案例与基本思路 类图与基本结构 void await() boolean await(long timeout, TimeUnit unit) void c ...
- git设置、查看、取消代理
设置代理: git config --global http.proxy 'socks5://127.0.0.1:1080' git config --global https.proxy 'sock ...
- redux-devtools-extend
如果不打算用redux-thunk import { createStore, compose} from 'redux'; import reducer from './reducer' const ...