Pinvoke and Win32 level API permissions

R

r

I have a console based .net 2.0 C# application that fails on a PInvoke
call to the HrESEBackupPrepare() function in the Exchange backup API.

How can I determine if the failure is due to .NET 2.0 or Windows 2003
server restricting the permissions of the application?

HrESEBackupPrepare() returns 5
GetLastError() returns 1008 (0x000003F0)
FormatMessage returns
"An attempt was made to reference a token that does not exist"
1008 is windows error "ERROR_NO_TOKEN"

Windows Server 2003
Exchange 2003

I am logged into the machine as a domain administrator and that domain
administrator is a member of the local backup operators group.

The online doucmentation for HrESEBackupPrepare() doesn't help much
because it does not explain how to correct this error.

It only lists three lines for errors:

S_OK - no error
ESE specific error code - see esebkmsg.h from the Exchange SDK
Other - a Win32 API or RPC error

Google groups contains many questions asking why this api fails but
almost no responses.
 
W

Willy Denoyette [MVP]

You should not call GetLastError when using PInvoke, the error returned
(1008) is probably not the 'real' value but an intermediate. Use
Marshal.GetLastWin32Error instead.

Willy.


|
| I have a console based .net 2.0 C# application that fails on a PInvoke
| call to the HrESEBackupPrepare() function in the Exchange backup API.
|
| How can I determine if the failure is due to .NET 2.0 or Windows 2003
| server restricting the permissions of the application?
|
| HrESEBackupPrepare() returns 5
| GetLastError() returns 1008 (0x000003F0)
| FormatMessage returns
| "An attempt was made to reference a token that does not exist"
| 1008 is windows error "ERROR_NO_TOKEN"
|
| Windows Server 2003
| Exchange 2003
|
| I am logged into the machine as a domain administrator and that domain
| administrator is a member of the local backup operators group.
|
| The online doucmentation for HrESEBackupPrepare() doesn't help much
| because it does not explain how to correct this error.
|
| It only lists three lines for errors:
|
| S_OK - no error
| ESE specific error code - see esebkmsg.h from the Exchange SDK
| Other - a Win32 API or RPC error
|
| Google groups contains many questions asking why this api fails but
| almost no responses.
|
 
R

r

I use Marshal.GetLastWin32Error() to get the last win32
error.

I have "SetLastError=true" for the DLLImportAttribute() and use
the following code to get the error string (this is easier than
directly calling FormatMessage() win32 api)

e = Marshal.GetLastWin32Error();

System.ComponentModel.Win32Exception t = new System.ComponentModel.Win32Exception(e);

Console.WriteLine(t.Message); //easier than
//importing and calling FormatMessage() win32 API call

Is there some .NET application setting or windows setting that I
need to do so that the .NET application runs using the the user
I am logged in as (a domain administrator)?

Thank you for your earlier reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top