cookielib
pip install wmi 

_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE', 0, _winreg.KEY_ALL_ACCESS)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
WindowsError: [Error 5]

将KEY_ALL_ACCESS改为KEY_QUERY_VALUE

静默提权到UAC

runas /user:Administrator "python your_script.py"

runas /?
RUNAS 用法:

RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]
        /user:<UserName> program

RUNAS [ [/noprofile | /profile] [/env] [/savecred] ]
        /smartcard [/user:<UserName>] program

RUNAS /trustlevel:<TrustLevel> program

/noprofile        指定不应该加载用户的配置文件。
                     这会加速应用程序加载,但
                     可能会造成一些应用程序运行不正常。
   /profile          指定应该加载用户的配置文件。
                     这是默认值。
   /env              要使用当前环境,而不是用户的环境。
   /netonly          只在指定的凭据限于远程访问的情况下才使用。
   /savecred         用用户以前保存的凭据。
   /smartcard        如果凭据是智能卡提供的,则使用这个选项。
   /user             <UserName> 应使用 USER@DOMAIN 或 DOMAIN\USER 形式
   /showtrustlevels  显示可以用作 /trustlevel 的参数的
                     信任级别。
   /trustlevel       <Level> 应该是在 /showtrustlevels 中枚举
                     的一个级别。
   program           EXE 的命令行。请参阅下面的例子

示例:
> runas /noprofile /user:mymachine\administrator cmd
> runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc"
> runas /env /user:user@domain.microsoft.com "notepad \"my file.txt\""

注意:  只在得到提示时才输入用户的密码。
注意:  /profile 跟 /netonly 不兼容。
注意:  /savecred 跟 /smartcard 不兼容。

It seems there's no way to elevate the application privileges for a while for you to perform a particular task. Windows needs to know at the start of the program whether the application requires certain privileges, and will ask the user to confirm when the application performs any tasks that need those privileges. There are two ways to do this:

  1. Write a manifest file that tells Windows the application might require some privileges

  2. Run the application with elevated privileges from inside another program

This two articles explain in much more detail how this works.

What I'd do, if you don't want to write a nasty ctypes wrapper for the CreateElevatedProcess API, is use the ShellExecuteEx trick explained in the Code Project article (Pywin32 comes with a wrapper for ShellExecute). How? Something like this:

When your program starts, it checks if it has Administrator privileges, if it doesn't it runs itself using the ShellExecute trick and exits immediately, if it does, it performs the task at hand.

As you describe your program as a "script", I suppose that's enough for your needs.

Cheers.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86" name="AdminApp" type="win32"/>
<description>Description of your application</description>
<!-- Identify the application security requirements. -->
<ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
<ms_asmv2:security>
<ms_asmv2:requestedPrivileges>
<ms_asmv2:requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</ms_asmv2:requestedPrivileges>
</ms_asmv2:security>
</ms_asmv2:trustInfo>
</assembly>
#define MANIFEST_RESOURCE_ID 1
MANIFEST_RESOURCE_ID RT_MANIFEST "AdminApp.exe.manifest"
 
32位程序安装信息的注册表位置:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
64位程序安装信息的注册表位置:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

RUNAS UAC的更多相关文章

  1. vista下开机启动 简单绕过UAC的方法(自己使用runas参数重新启动自己,有点意思)

    背景      vista下,如果不开启UAC,那就没有我下面要说的问题了,呵呵.下面说的都是在vista开启UAC的前提下说的,win7也适用.      在vista下,系统开启了UAC,如果你的 ...

  2. .NET中提升UAC权限的方法总结

    [题外话] 从Vista开始,由于增加了UAC(用户账户控制,User Account Control)功能,使得管理员用户平时不再拥有能控制所有功能的管理员权限了,所以在调用很多比较重要的功能时需要 ...

  3. JAVA “Run as administrator” “UAC disabled” alternative solution

    Technorati 标签: psexec,run as administrator,UAC java.io.IOException: Cannot run program "psexec. ...

  4. [转]Win7 UAC的安全、兼容及权限

    [转]Win7 UAC的安全.兼容及权限 http://www.cnblogs.com/mydomain/archive/2010/11/24/1887132.html 网上关于这个问题讨论较多,但也 ...

  5. UAC新解(有非正常手段可以绕过)

    360第一次注册是需要弹,可是以后就不弹了开机自启动不弹框,开机自启动不弹框 服务是system权限再说一句,一般程序也不需要过UAC系统启动项白名单.UAC有一个白名单机制.还有UAC也可以通过wu ...

  6. QT使用UAC(经过验证)

    网上有很多manifest的版本,mingw与vs系列也有不同的解决方案,不管那么多,我是使用这篇文章解决这个问题的: So it turns out that I had another bug t ...

  7. win7中的Uac与开机自动启动(好几种办法,特别是用不带UAC的程序启动UAC程序是一个简单的好办法,写驱动自启动更是了不得)

    在另一篇文章中已经介绍了给Exe加上Uac的方法,在使用的过程中我们会发现,如果把带Uac的Exe写入注册表的Run中,是无法实现开机自动启动的,原因就是带Uac的exe需要申请管理员权限,以便运行执 ...

  8. UAC权限

    .NET中提升UAC权限的方法总结   [题外话] 从Vista开始,由于增加了UAC(用户账户控制,User Account Control)功能,使得管理员用户平时不再拥有能控制所有功能的管理员权 ...

  9. UAC下的程序权限提升

    来源:http://blog.kingsamchen.com/archives/801 UAC是微软为了提高Windows的安全性,自Windows Vista开始引入的新安全机制. 传统的NT内核系 ...

随机推荐

  1. select into from 和 insert into select

    select into from 和 insert into select都是用来复制表, 两者的主要区别为: select into from 要求目标表不存在,因为在插入时会自动创建. inser ...

  2. PHP.31-TP框架商城应用实例-后台7-商品会员修改-页面优化,多表数据更新

    商品表修改功能 1.页面优化,类似添加页面 <layout name="layout" /> <div class="tab-div"> ...

  3. vue命令集合

    创建vuecli脚手架:npm install -g @vue/cli拉取2的版本:npm install -g @vue/cli-init 创建webpack:npm i webpack@3.12. ...

  4. 常见排序算法题(java版)

    常见排序算法题(java版) //插入排序:   package org.rut.util.algorithm.support;   import org.rut.util.algorithm.Sor ...

  5. 剑指Offer - 九度1356 - 孩子们的游戏(圆圈中最后剩下的数)

    剑指Offer - 九度1356 - 孩子们的游戏(圆圈中最后剩下的数)2014-02-05 19:37 题目描述: 每年六一儿童节,JOBDU都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此.H ...

  6. 《Cracking the Coding Interview》——第1章:数组和字符串——题目3

    2014-03-18 01:32 题目:对于两个字符串,判断它们是否是Anagrams. 解法:统计俩单词字母构成是否相同即可. 代码: // 1.3 Given two strings, write ...

  7. linux部署环境配置

    https://blog.csdn.net/dsczxcc/article/details/78728330

  8. day06_07 字典操作02

    1.0 删_del dic5 = {'age':18,'name':'alex','hobby':'girl'} del dic5['name'] #删除键值对 print(dic5) #>&g ...

  9. Java 复习计划

    前言 打算下学期开学,也就是九月份,去找实习,现在还有三个月时间.(然而还在天天玩 Python..) 定个复习计划. 1. 基础 并发:Java并发编程实战 [ x ] SQL:MySQL,看看书, ...

  10. nyoj 题目61 传纸条

    传纸条(一) 时间限制:2000 ms  |  内存限制:65535 KB 难度:5   描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行 ...