Tuesday, November 3, 2009

Impersonation with LogonUser Function

Make sure the version of Windows and OS type of the machine that you are using for the application while implementing the impersonation and LogonUser functions in your application.

I faced this error before :-

"Could not load file or assembly 'System.Transactions......' or one of its dependencies. Either a required impersonation level was not provided or the provided impersonation level is invalid."

My application is installed in a pc with 32-bit OS, Windows Vista, etc. And I used LOGON32_LOGON_NETWORK value as logon type for LogonUser function. Finally I get the error above.

The problem is I used LOGON32_LOGON_NETWORK value as logon type for LogonUser function It is because for Windows Vista, the logon type for LogonUser function is not LOGON32_LOGON_NETWORK. LOGON32_LOGON_NETWORK is for using at machine Windows XP.

Therefore, for Windows Vista, the value for logon type should not be LOGON32_LOGON_NETWORK, and should change it to LOGON32_LOGON_NEW_CREDENTIALS. And it can be used also at machine Windows XP.

Click on LogonUser function here to read more details about it.