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 ??
thanks
Willy Denoyette [MVP] - 24 Jun 2005 22:12 GMT
The process identity is used to create an instance of the out-proc server
(Excel) what you are trying is not possible.
Willy.
> on window 2000, I'm automating Excel (server side).
>
[quoted text clipped - 38 lines]
>
> thanks
Paul Clement - 28 Jun 2005 15:22 GMT
¤ 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
~~~~
Microsoft MVP (Visual Basic)