zoukankan      html  css  js  c++  java
  • RUNAS UAC

    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 或 DOMAINUSER 形式
       /showtrustlevels  显示可以用作 /trustlevel 的参数的
                         信任级别。
       /trustlevel       <Level> 应该是在 /showtrustlevels 中枚举
                         的一个级别。
       program           EXE 的命令行。请参阅下面的例子

    示例:
    > runas /noprofile /user:mymachineadministrator cmd
    > runas /profile /env /user:mydomainadmin "mmc %windir%system32dsa.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_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall
    64位程序安装信息的注册表位置:
    HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall

  • 相关阅读:
    C# DataGridView的初始化
    DataGridView固定了列名,怎样将数据内容绑定在列上
    struts2 中的 addActionError 、addFieldError、addActionMessage方法的区别添加错误信息
    <s:iterator>标签迭代数据不显示
    org.hibernate.hql.ast.QuerySyntaxException: tb_voteoption is not mapped [from tb_voteoption where voteID=?]
    struts2导入多个xml引入报错<include>
    没有找到<context:component-scan base-package="">标签
    hibernate.hbm.xml配置文件解析
    Struts2 中#、@、%和$符号的用途
    Some projects cannot be imported because they already exist in the workspace
  • 原文地址:https://www.cnblogs.com/zhang-pengcheng/p/4231516.html
Copyright © 2011-2022 走看看