I am trying to copy a file (any) from Windows\System32\Draivers using a Windows API function:
CopyFile('C:\Windows\System32\drivers\1394bus.sys', 'c:\1394bus.sys', False);
But it is not working,
The same function works for any other file from any folder.
Do I need to set any access privilege?
Any suggestion or help is appreciated.
Thnaks
Saeed Shekari
This code can set the access privilege for a few purposes; I tried calling this function with different parameters before copying, but all failed.
- Code: Select all
Function SetAccessPrivilege(Const PrivilegeStr : String; State : Integer):Integer;
Var
hToken : THandle;
aluid : TLargeInteger;
cbPrevTP : DWORD;
tp, fPrevTP : PTokenPrivileges;
Begin
result := 0;
If OpenProcessToken (GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES Or
TOKEN_QUERY, hToken) Then
Try
LookupPrivilegeValue (Nil, PChar (PrivilegeStr), aluid);
cbPrevTP := SizeOf (TTokenPrivileges) + sizeof (TLUIDAndAttributes);
GetMem (tp, cbPrevTP);
GetMem (fPrevTP, cbPrevTP);
Try
tp^.PrivilegeCount := 1;
tp^.Privileges [0].Luid := aLuid;
tp^.Privileges [0].Attributes := State;
If Not AdjustTokenPrivileges (hToken, False, tp^, cbPrevTP, fPrevTP^, cbPrevTP) Then
RaiseLastWin32Error;
Result := fPrevTP^.Privileges [0].Attributes;
Finally
FreeMem (fPrevTP);
FreeMem (tp);
End
Finally
CloseHandle (hToken);
End
End;
// Example for calling above function
//
// Procedure ChangeDateTime( SysDateTime: SYSTEMTIME);
// Begin
// SetAccessPrivilege('wbemPrivilegeSystemtime',SE_PRIVILEGE_ENABLED);
// SetLocalTime(SysDateTime);
// End;
// Function BackupRegistry(R: TRegistry; RegKey, FileName: String): Boolean;
// Begin
// SetAccessPrivilege('SeBackupPrivilege', SE_PRIVILEGE_ENABLED);
// Result:= R.SaveKey(RegKey, FileName);
// End;
(*
ACCESS PRIVILEDGE FOR NT
wbemPrivilegeCreateToken Required to create a primary token.
SeAssignPrimaryTokenPrivilege
2 wbemPrivilegePrimaryToken Required to assign the primary token of a process.
SeLockMemoryPrivilege
3 wbemPrivilegeLockMemory Required to lock physical pages in memory.
SeIncreaseQuotaPrivilege
4 wbemPrivilegeIncreaseQuota Required to increase the quota assigned to a process.
SeMachineAccountPrivilege
5 wbemPrivilegeMachineAccount Required to create a computer account.
SeTcbPrivilege
6 wbemPrivilegeTcb Identifies its holder as part of the trusted computer base. Some trusted, protected subsystems
are granted this privilege.
SeSecurityPrivilege
7 wbemPrivilegeSecurity Required to perform a number of security-related functions, such as controlling and
viewing audit messages. This privilege identifies its holder as a security operator.
SeTakeOwnershipPrivilege
8 wbemPrivilegeTakeOwnership Required to take ownership of an object without being granted discretionary access.
This privilege allows the owner value to be set only to those values that the holder may legitimately assign as
the owner of an object.
SeLoadDriverPrivilege
9 wbemPrivilegeLoadDriver Required to load or unload a device driver.
SeSystemProfilePrivilege
10 wbemPrivilegeSystemProfile Required to gather profiling information for the entire system.
SeSystemtimePrivilege
11 wbemPrivilegeSystemtime Required to modify the system time.
SeProfileSingleProcessPrivilege
12 wbemPrivilegeProfileSingleProcess Required to gather profiling information for a single process.
SeIncreaseBasePriorityPrivilege
13 wbemPrivilegeIncreaseBasePriority Required to increase the base priority of a process.
SeCreatePagefilePrivilege
14 wbemPrivilegeCreatePagefile Required to create a paging file.
SeCreatePermanentPrivilege
15 wbemPrivilegeCreatePermanent Required to create a permanent object.
SeBackupPrivilege
16 wbemPrivilegeBackup Required to perform backup operations.
SeRestorePrivilege
17 wbemPrivilegeRestore Required to perform restore operations. This privilege enables you to set any valid user
or group SID as the owner of an object.
SeShutdownPrivilege
18 wbemPrivilegeShutdown Required to shut down a local system.
SeDebugPrivilege
19 wbemPrivilegeDebug Required to debug a process.
SeAuditPrivilege
20 wbemPrivilegeAudit Required to generate audit-log entries.
SeSystemEnvironmentPrivilege
21 wbemPrivilegeSystemEnvironment
Required to modify the nonvolatile RAM of systems that use this type of memory
to store configuration information.
SeChangeNotifyPrivilege
22 wbemPrivilegeChangeNotify Required to receive notifications of changes to files or directories.
This privilege also causes the system to skip all traversal access checks. It is enabled by default for all users.
SeRemoteShutdownPrivilege
23 wbemPrivilegeRemoteShutdown Required to shut down a system using a network request.
SeUndockPrivilege
24 wbemPrivilegeUndock Required to remove computer from docking station.
SeSyncAgentPrivilege
25 wbemPrivilegeSyncAgent Required to synchronize directory service data.
SeEnableDelegationPrivilege
26 wbemPrivilegeEnableDelegation Required to enable computer and user accounts to be trusted for delegation.
*)