启动时无需“管理员”特权,但希望执行某个功能时,能动态提升到“管理员”特权级别。请教前辈:如何实现之?

解决方案 »

  1.   

    没法在程序已运行状态改变特权。重新把自己再启动一遍。启动方式:#include "stdafx.h"
    #include "windows.h"
    #include "shellapi.h"
    int _tmain(int argc, _TCHAR* argv[])
    {
          SHELLEXECUTEINFO shExecInfo;      shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);      shExecInfo.fMask = NULL;
          shExecInfo.hwnd = NULL;
          shExecInfo.lpVerb = L"runas";
          shExecInfo.lpFile = L"notepad.exe";
          shExecInfo.lpParameters = NULL;
          shExecInfo.lpDirectory = NULL;
          shExecInfo.nShow = SW_MAXIMIZE;
          shExecInfo.hInstApp = NULL;      ShellExecuteEx(&shExecInfo);      return 0;
    }
      

  2.   

    动态提权没见过,这个是直接提权的。
    VC编译出来的应用程序在vista下运行,有可能因为权限问题,不能成功运行。用以下办法,给应用程序添加一个manifest文件,程序运行时系统就会跳出UAC对话框,获得管理权限。1.打开应用程序的源代码工程2.添加一个“custom”资源,"resource type"填24,把资源ID改为1,然后把以下内容复制到资源内容中保存<?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="mulitray.exe.manifest"
        type="win32"
    />
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
    </assembly>3.重新编译应用程序,此时会发现,广用程序的图标在vista下会多出一个小盾标志。 就是System令牌
      

  3.   

    Vista中,进程无法动态提升到管理员权,windows via c++里面有说到,并且给了一个解决办法。
      

  4.   


    windows via c/c++里的一种方法, 另外可以通过SetProcessPriorityBoost 允许或禁止系统提升一个进程的优先级, 而SetThreadPriorityBoost则 允许或禁止提升某个线程的优先级。