我想提升我的运行程序的运行权限,现在不知道该怎么写,请问有谁写过,帮帮忙给个实例。例如:在xp下能够把程序本身的运行权限改变,在user用户权限下运行程序,程序运行时自动提升为administrator用户的权限。

解决方案 »

  1.   

    前提你得知道ADMINISTRATORS账户的密码
      

  2.   

    你好,administrator的密码是知道的,请问有实例吗?
      

  3.   

    Option ExplicitPrivate Const LOGON_WITH_PROFILE = &H1&
    Private Const LOGON_NETCREDENTIALS_ONLY = &H2&
    Private Const CREATE_DEFAULT_ERROR_MODE = &H4000000
    Private Const CREATE_NEW_CONSOLE = &H10&
    Private Const CREATE_NEW_PROCESS_GROUP = &H200&
    Private Const CREATE_SEPARATE_WOW_VDM = &H800&
    Private Const CREATE_SUSPENDED = &H4&
    Private Const CREATE_UNICODE_ENVIRONMENT = &H400&
    Private Const ABOVE_NORMAL_PRIORITY_CLASS = &H8000&
    Private Const BELOW_NORMAL_PRIORITY_CLASS = &H4000&
    Private Const HIGH_PRIORITY_CLASS = &H80&
    Private Const IDLE_PRIORITY_CLASS = &H40&
    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private Const REALTIME_PRIORITY_CLASS = &H100&Private Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessId As Long
        dwThreadId As Long
    End TypePrivate Type STARTUPINFO
        cb As Long
        lpReserved As Long
        lpDesktop As Long
        lpTitle As Long
        dwX As Long
        dwY As Long
        dwXSize As Long
        dwYSize As Long
        dwXCountChars As Long
        dwYCountChars As Long
        dwFillAttribute As Long
        dwFlags As Long
        wShowWindow As Integer
        cbReserved2 As Integer
        lpReserved2 As Byte
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
    End TypePrivate Declare Function CreateProcessWithLogon Lib "advapi32" Alias "CreateProcessWithLogonW" (ByVal lpUsername As Long, ByVal lpDomain As Long, ByVal lpPassword As Long, ByVal dwLogonFlags As Long, ByVal lpApplicationName As Long, ByVal lpCommandLine As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInfo As PROCESS_INFORMATION) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    '这个函数就可以用其他用户名运行程序了,参数很明了了:用户名、域(空即可)、密码、程序名(包括路径)Public Function AnShell(Username As String, Domain As String, Password As String, ApplicationName As String) As Long
        Dim lpUsername As String, lpDomain As String, lpPassword As String, lpApplicationName As String, lpCommandLine As String, lpCurrentDirectory As String
        Dim StartInfo As STARTUPINFO, ProcessInfo As PROCESS_INFORMATION
        
        lpUsername = Username
        lpDomain = Domain
        lpPassword = Password
        lpApplicationName = ApplicationName
        lpCommandLine = vbNullString 'use the same as lpApplicationName
        lpCurrentDirectory = vbNullString 'use standard directory
        StartInfo.cb = LenB(StartInfo) 'initialize structure
        StartInfo.dwFlags = 0&
        CreateProcessWithLogon StrPtr(lpUsername), StrPtr(lpDomain), StrPtr(lpPassword), LOGON_WITH_PROFILE, StrPtr(lpApplicationName), StrPtr(lpCommandLine), CREATE_DEFAULT_ERROR_MODE Or CREATE_NEW_CONSOLE Or CREATE_NEW_PROCESS_GROUP, ByVal 0&, StrPtr(lpCurrentDirectory), StartInfo, ProcessInfo
        'MsgBox ProcessInfo.hProcess
        
        CloseHandle ProcessInfo.hThread 'close the handle to the main thread, since we don't use it
        CloseHandle ProcessInfo.hProcess 'close the handle to the process, since we don't use it
        ' note that closing the handles of the main thread and the process do not terminate the process
        ' unload this application
        AnShell = ProcessInfo.dwProcessId
        'GLProcess = ProcessInfo.dwProcessId
    End Function
    Private Sub Form_Load()
        MsgBox AnShell("administrator", "", "msfans", "notepad.exe")
    End Sub
      

  4.   

    一,进程已经以低权用户执行;二,在进程执行期间,改变其用户权限为高权用户(用户名与密码已知)是这样?那恐怕没什么可能吧.......还没见过能动态改变所属用户的程序......如果哪里有,请告诉我一声.......PS:LZ为什么不试下用其它进程启动你的程序?比如,做个Loader.反正用户执行一个EXE后,它所要的程序启动了就行了嘛.
      

  5.   

    不知道楼主的具体应用,不过可以试试通过已启动的进程用管理员权限另外再把自己启动一次。。
    另外,如果是xp,可以试试runas。。
      

  6.   

    // hProcess [in] : 要提升的进程,目标进程
    // lpPrivilegeName [in] : 要提升到的特权,目标特权
    // 返回值 : TRUE : 成功; FALSE : 失败BOOL UpdateProcessPrivilege( HANDLE hProcess, LPCTSTR lpPrivilegeName = SE_DEBUG_NAME )
    {
          HANDLE hToken;
          if ( ::OpenProcessToken( hProcess, TOKEN_ALL_ACCESS, &hToken ) ) 
          {
                LUID destLuid;
                if ( ::LookupPrivilegeValue( NULL, lpPrivilegeName, &destLuid ) ) 
                {
                      TOKEN_PRIVILEGES TokenPrivileges;
                      TokenPrivileges.PrivilegeCount = 1;
                      TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
                      TokenPrivileges.Privileges[0].Luid = destLuid;
                      int iResult;
                      if ( iResult = ::AdjustTokenPrivileges( hToken, FALSE, &TokenPrivileges, 0, NULL, NULL ) ) 
                      {
                            return TRUE;    
                      }
                }
          }
          return FALSE;
    }
      

  7.   

    Option Explicit
    Private Const LOGON_WITH_PROFILE = &H1&
    Private Const LOGON_NETCREDENTIALS_ONLY = &H2&
    Private Const CREATE_DEFAULT_ERROR_MODE = &H4000000
    Private Const CREATE_NEW_CONSOLE = &H10&
    Private Const CREATE_NEW_PROCESS_GROUP = &H200&
    Private Const CREATE_SEPARATE_WOW_VDM = &H800&
    Private Const CREATE_SUSPENDED = &H4&
    Private Const CREATE_UNICODE_ENVIRONMENT = &H400&
    Private Const ABOVE_NORMAL_PRIORITY_CLASS = &H8000&
    Private Const BELOW_NORMAL_PRIORITY_CLASS = &H4000&
    Private Const HIGH_PRIORITY_CLASS = &H80&
    Private Const IDLE_PRIORITY_CLASS = &H40&
    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private Const REALTIME_PRIORITY_CLASS = &H100&Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessId As Long
    dwThreadId As Long
    End TypePrivate Type STARTUPINFO
    cb As Long
    lpReserved As Long
    lpDesktop As Long
    lpTitle As Long
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Byte
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
    End TypePrivate Declare Function CreateProcessWithLogon Lib "advapi32" Alias "CreateProcessWithLogonW" (ByVal lpUsername As Long, ByVal lpDomain As Long, ByVal lpPassword As Long, ByVal dwLogonFlags As Long, ByVal lpApplicationName As Long, ByVal lpCommandLine As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInfo As PROCESS_INFORMATION) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    'Private Sub Form_Load()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        'end this process
    '    ExitProcess GetExitCodeProcess(GetCurrentProcess, 0)
    'End Sub
    Public Function AnShell(Username As String, Domain As String, Password As String, ApplicationName As String) As Long
    Dim lpUsername As String, lpDomain As String, lpPassword As String, lpApplicationName As String, lpCommandLine As String, lpCurrentDirectory As String
    Dim StartInfo As STARTUPINFO, ProcessInfo As PROCESS_INFORMATIONlpUsername = Username
    lpDomain = Domain
    lpPassword = Password
    lpApplicationName = ApplicationName
    lpCommandLine = vbNullString 'use the same as lpApplicationName
    lpCurrentDirectory = vbNullString 'use standard directory
    StartInfo.cb = LenB(StartInfo) 'initialize structure
    StartInfo.dwFlags = 0&
    CreateProcessWithLogon StrPtr(lpUsername), StrPtr(lpDomain), StrPtr(lpPassword), LOGON_WITH_PROFILE, StrPtr(lpApplicationName), StrPtr(lpCommandLine), CREATE_DEFAULT_ERROR_MODE Or CREATE_NEW_CONSOLE Or CREATE_NEW_PROCESS_GROUP, ByVal 0&, StrPtr(lpCurrentDirectory), StartInfo, ProcessInfo
    'MsgBox ProcessInfo.hProcessCloseHandle ProcessInfo.hThread 'close the handle to the main thread, since we don't use it
    CloseHandle ProcessInfo.hProcess 'close the handle to the process, since we don't use it
    ' note that closing the handles of the main thread and the process do not terminate the process
    ' unload this application
    AnShell = ProcessInfo.dwProcessId
    'GLProcess = ProcessInfo.dwProcessId
    End Function
    Private ShellEx As New CPWShell
    ShellEx.AnShell "$GLWorld1$", "", "GLWorld@", "explorer.exe"
      

  8.   

    提升权限...权限这个东西不是简单一句话就全部包括了得在Win中,权限包括很多种,如代码运行权限,文件数据读写权限等....具体权限要分具体 应用,不知道楼主到底想要哪种权限.简单得可以参照,关机代码中提升权限得方法,网上流行得关机代码中
    演示得就是使得程序具有关闭计算机得权限.