all groups > dotnet interop > june 2005 >
You're in the

dotnet interop

group:

impersonation and Excel


impersonation and Excel zino
6/24/2005 1:14:04 PM
dotnet interop:
on window 2000, I'm automating Excel (server side).

If I set the impersonation in the webConfig file as:
<authentication mode="Windows" />
<identity impersonate="true" userName="myDomain\myUserID"
password="myPassword" />
and run this code :
Dim xl As Object
xl = CreateObject("Excel.Application")
it runs fine and no error is thrown


but I need to impersonate the user in code, so what I did is:
in the web config I set the authentication as:
<authentication mode="Windows" />
<authorization>
<allow users="myDomain\myUserID"/> 'the same user credentiels as above
<deny users="*"/>
</authorization>

in the Global file as :
Dim impersonationContext As
System.Security.Principal.WindowsImpersonationContext

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
currentWindowsIdentity = CType(User.Identity,
System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()
End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
impersonationContext.Undo()
End Sub


but when this code runs;
Dim xl As Object
xl = CreateObject("Excel.Application")
it generate an error: "Cannot create Active X component"

What am I doing wrong ??

Re: impersonation and Excel Willy Denoyette [MVP]
6/24/2005 11:12:18 PM
The process identity is used to create an instance of the out-proc server
(Excel) what you are trying is not possible.

Willy.

[quoted text, click to view]

Re: impersonation and Excel Paul Clement
6/28/2005 9:22:09 AM
[quoted text, click to view]

¤ on window 2000, I'm automating Excel (server side).
¤
¤ If I set the impersonation in the webConfig file as:
¤ <authentication mode="Windows" />
¤ <identity impersonate="true" userName="myDomain\myUserID"
¤ password="myPassword" />
¤ and run this code :
¤ Dim xl As Object
¤ xl = CreateObject("Excel.Application")
¤ it runs fine and no error is thrown
¤
¤
¤ but I need to impersonate the user in code, so what I did is:
¤ in the web config I set the authentication as:
¤ <authentication mode="Windows" />
¤ <authorization>
¤ <allow users="myDomain\myUserID"/> 'the same user credentiels as above
¤ <deny users="*"/>
¤ </authorization>
¤
¤ in the Global file as :
¤ Dim impersonationContext As
¤ System.Security.Principal.WindowsImpersonationContext
¤
¤ Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
¤ Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
¤ currentWindowsIdentity = CType(User.Identity,
¤ System.Security.Principal.WindowsIdentity)
¤ impersonationContext = currentWindowsIdentity.Impersonate()
¤ End Sub
¤
¤ Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
¤ impersonationContext.Undo()
¤ End Sub
¤
¤
¤ but when this code runs;
¤ Dim xl As Object
¤ xl = CreateObject("Excel.Application")
¤ it generate an error: "Cannot create Active X component"
¤
¤ What am I doing wrong ??

See the following:

INFO: Considerations for Server-Side Automation of Office
http://support.microsoft.com/default.aspx?scid=kb;en-us;257757


Paul
~~~~
AddThis Social Bookmark Button