HRESULT: 0x800736B1



So, I need to call AdjustTokenPrivileges because I'm writing a file backup
application. This is Win32 code that interfaces with a COM component,
complete with HRESULTs and all that. The DLL that I make requires that I
name Advapi32.lib as a linker input dependency.

Uaing P/Invoke, I call into the DLL from C#. This works great on the
development machine.

The problem is that when I publish the C# application (using the Publish
menu item of Visual Studio), news about the DLL doesn't get put into the
manifest. Apparently, this has something to do with with the Advapi32.lib
dependency and something missing from the target machine's WinSxS folder.
The application fails on the target machine with a miserable, uninformative
message, as follows:

Unable to load DLL <name-of-DLL>; This application has failed to start
because the application configuration is incorrect. Reinstalling the
application may fix this problem. (Exception from HRESULT: 0x800736B1)

This is hair pulling time.

Here is the DLL that fails to load:

/*

Required to perform backup operations.

This privilege causes the system to grant all read access control to any
file,

regardless of the access control list (ACL) specified for the file.

Any access request other than read is still evaluated with the ACL. \

This privilege is required by the RegSaveKey and RegSaveKeyExfunctions.

The following access rights are granted if this privilege is held:

READ_CONTROL

ACCESS_SYSTEM_SECURITY

FILE_GENERIC_READ

FILE_TRAVERSE

User Right: Back up files and directories.

*/

// This is the main DLL file.









#include <windows.h>

#include <stdio.h>

// The following example can be used to enable or disable the

// backup privilege. By making the indicated substitutions, you can

// also use this example to enable or disable the restore privilege

// Use the following statement to enable the privilege:

// hr = ModifyPrivilege(SE_BACKUP_NAME, TRUE);

// Use the following statement to disable the privilege:

// hr = ModifyPrivilege(SE_BACKUP_NAME, FALSE);

// Use SE_RESTORE_NAME for the restore privilege.

// The main function in this example enables the backup privilege.







HRESULT _stdcall ModifyPrivilege(

IN LPCTSTR szPrivilege,

IN BOOL fEnable)

{

HRESULT hr = S_OK;

TOKEN_PRIVILEGES NewState;

LUID luid;

HANDLE hToken = NULL;

// Open the process token for this process.

if (!OpenProcessToken(GetCurrentProcess(),

TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,

&hToken ))

{

printf("Failed OpenProcessToken\n");

return ERROR_FUNCTION_FAILED;

}

// Get the local unique ID for the privilege.

if ( !LookupPrivilegeValue( NULL,

szPrivilege,

&luid ))

{

CloseHandle( hToken );

printf("Failed LookupPrivilegeValue\n");

return ERROR_FUNCTION_FAILED;

}

// Assign values to the TOKEN_PRIVILEGE structure.

NewState.PrivilegeCount = 1;

NewState.Privileges[0].Luid = luid;

NewState.Privileges[0].Attributes =

(fEnable ? SE_PRIVILEGE_ENABLED : 0);

// Adjust the token privilege.

if (!AdjustTokenPrivileges(hToken,

FALSE,

&NewState,

0,

NULL,

NULL))

{

printf("Failed AdjustTokenPrivileges\n");

hr = ERROR_FUNCTION_FAILED;

}

// Close the handle.

CloseHandle(hToken);

return hr;

}

extern "C" _declspec(dllexport) int _stdcall
GetBackupPrivilForSystemBackup(int togglePosition)

{

HRESULT hr;

BOOL arg;

if (togglePosition!=0)

arg = TRUE;

else

arg = FALSE;

hr = ModifyPrivilege(SE_BACKUP_NAME, arg);

if (!SUCCEEDED(hr))

return 0;

else

return 1;

}


.



Relevant Pages

  • Where is the head and tail?
    ... Backup Management - How regularly backup is taken, ... Privilege Management - What privilege levels are defined, ... define workflows within dept. of accounting? ... Arm your enterprise with BigFix, the single converged IT security and operations engine. ...
    (Security-Basics)
  • Re: Ubuntu CD-Rs ?
    ... privilege is removed. ... CD/DVD does adopt the user who mounted it, to be the owner of the files on it. ... To avoid this (for your next backup) you should make a tarball of what ...
    (alt.linux)
  • Re: Willing to bet this is Windows at its best
    ... But doesn't the operator need write privilege if the backup has a /RECORD ... READALL Privilege (Objects) ... See the HP OpenVMS System Management Utilities Reference Manual ...
    (comp.os.vms)
  • Re: FILE_FLAG_BACKUP_SEMANTICS
    ... I have a data backup program which I'm trying to modify to allow backing up ... SE_BACKUP_NAME privilege, ... HRESULT ModifyPrivilege(IN LPCTSTR szPrivilege, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Block (or Hide) Control Panel
    ... Only a few apps run with LocalSystem. ... userID in the Backup Operator group. ... And given some of the privilege escalation attacks you can create that ... Vista addresses this by running each app at the lowest possible security ...
    (microsoft.public.vc.mfc)

Loading