Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / June 2005

Tip: Looking for answers? Try searching our database.

impersonation and Excel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
zino - 24 Jun 2005 21:14 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 ??

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)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.