By modifying the project Settings make program in accordance with the administrator privileges to run, directly within the program created by the CreateProcess process whether have administrator permissions?
CodePudding user response:
CodePudding user response:
CreateProcessAsUserCodePudding user response:
three methods to carry process right
Method one:
C/C + + code
Bool EnableDebugPrivilege ()
{
HANDLE hToken;
LUID sedebugnameValue;
The TOKEN_PRIVILEGES TKP;
if (! OpenProcessToken (GetCurrentProcess (), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, & amp; HToken))
{
Return FALSE;
}
if (! LookupPrivilegeValue (NULL, SE_DEBUG_NAME, & amp; SedebugnameValue))
{
The CloseHandle (hToken);
return false;
}
TKP. PrivilegeCount=1;
TKP. Privileges [0]. Luid=sedebugnameValue;
TKP. Privileges [0]. Attributes=SE_PRIVILEGE_ENABLED;
if (! AdjustTokenPrivileges (hToken, FALSE, & amp; TKP, sizeof (TKP), NULL, NULL))
{
The CloseHandle (hToken);
return false;
}
return true;
}
Method 2:
C/C + + code
Bool UpPrivilege ()
{
HANDLE hToken;//handle to the process token
The TOKEN_PRIVILEGES TKP;//pointer to token structure
Bool result=OpenProcessToken (GetCurrentProcess (),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
& HToken);
if(! The result)//open the process error
return result;
Result=LookupPrivilegeValue (NULL,
SE_DEBUG_NAME,
& TKP. Privileges [0]. Luid);
if(! Result)//view process authority error
Return the result.
TKP. PrivilegeCount=1;//one privilege to set
TKP. Privileges [0]. Attributes=SE_PRIVILEGE_ENABLED;
Result=AdjustTokenPrivileges (hToken,
FALSE,
& TKP,
Sizeof (TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);
Return the result.
}
Method 3:
C/C + + code
# define SE_CREATE_TOKEN_NAME TEXT (" SeCreateTokenPrivilege ")
# define SE_ASSIGNPRIMARYTOKEN_NAME TEXT (" SeAssignPrimaryTokenPrivilege ")
# define SE_LOCK_MEMORY_NAME TEXT (" SeLockMemoryPrivilege ")
# define SE_INCREASE_QUOTA_NAME TEXT (" SeIncreaseQuotaPrivilege ")
# define SE_UNSOLICITED_INPUT_NAME TEXT (" SeUnsolicitedInputPrivilege ")
# define SE_MACHINE_ACCOUNT_NAME TEXT (" SeMachineAccountPrivilege ")
# define SE_TCB_NAME TEXT (" SeTcbPrivilege ")
# define SE_SECURITY_NAME TEXT (" SeSecurityPrivilege ")
# define SE_TAKE_OWNERSHIP_NAME TEXT (" SeTakeOwnershipPrivilege ")
# define SE_LOAD_DRIVER_NAME TEXT (" SeLoadDriverPrivilege ")
# define SE_SYSTEM_PROFILE_NAME TEXT (" SeSystemProfilePrivilege ")
# define SE_SYSTEMTIME_NAME TEXT (" SeSystemtimePrivilege ")
# define SE_PROF_SINGLE_PROCESS_NAME TEXT (" SeProfileSingleProcessPrivilege ")
# define SE_INC_BASE_PRIORITY_NAME TEXT (" SeIncreaseBasePriorityPrivilege ")
# define SE_CREATE_PAGEFILE_NAME TEXT (" SeCreatePagefilePrivilege ")
# define SE_CREATE_PERMANENT_NAME TEXT (" SeCreatePermanentPrivilege ")
# define SE_BACKUP_NAME TEXT (" SeBackupPrivilege ")
# define SE_RESTORE_NAME TEXT (" SeRestorePrivilege ")
# define SE_SHUTDOWN_NAME TEXT (" SeShutdownPrivilege ")
# define SE_DEBUG_NAME TEXT (" SeDebugPrivilege ")
# define SE_AUDIT_NAME TEXT (" SeAuditPrivilege ")
# define SE_SYSTEM_ENVIRONMENT_NAME TEXT (" SeSystemEnvironmentPrivilege ")
# define SE_CHANGE_NOTIFY_NAME TEXT (" SeChangeNotifyPrivilege ")
# define SE_REMOTE_SHUTDOWN_NAME TEXT (" SeRemoteShutdownPrivilege ")
# define SE_UNDOCK_NAME TEXT (" SeUndockPrivilege ")
# define SE_SYNC_AGENT_NAME TEXT (" SeSyncAgentPrivilege ")
# define SE_ENABLE_DELEGATION_NAME TEXT (" SeEnableDelegationPrivilege ")
# define SE_MANAGE_VOLUME_NAME TEXT (" SeManageVolumePrivilege ")
BOOL EnablePrivilege (LPCTSTR lpszPrivilegeName, BOOL bEnable)
{
HANDLE hToken;
The TOKEN_PRIVILEGES tp;
LUID LUID;
if(! OpenProcessToken (GetCurrentProcess (), TOKEN_ADJUST_PRIVILEGES |
TOKEN_QUERY | TOKEN_READ, & amp; HToken))
Return FALSE;
if(! LookupPrivilegeValue (NULL, lpszPrivilegeName, & amp; Luid))
Return TRUE;
Tp. PrivilegeCount=1;
Tp. Privileges [0]. Luid=Luid;
Tp. Privileges [0]. Attributes=(bEnable)? SE_PRIVILEGE_ENABLED: 0;
AdjustTokenPrivileges (hToken, FALSE, & amp; Tp, NULL, NULL, NULL);
The CloseHandle (hToken);
Return (GetLastError ()==ERROR_SUCCESS);
}
Need to ask rightnullnullnullnullnullnullnullnullnullnullnullnullnull