I've created a VB .Net windows application that generates reports in excel files from a dataset.

I use "New Excel.Application" to create the Excel instance, and push data into it from my dataset. During this process, I do not show the GUI of my instance of Excel to the user, so nobody can tamper with the instance.

Everything works as expected.

Except in one case: When the automation is in progress, if the user opens some other excel file, it opens as a workbook within the Excel instance being used in my application, instead of creating a new Excel instance for the same. In such cases, the automation is exposed, and fails with random exceptions depending on what the user does with it.

So when the automation is in progress, I would like to prevent the user from opening the instance of Excel that I use in my VB application.

How can I prevent this? Is it possible to make my instance of Excel application exclusive to my application alone?

lolafuertes might be right, but the fact of the matter is that Excel isn't designed to do what you're trying to do. Basically, that will put the app into a different context than the current user, but that introduces a whole other level of issue with impersonation, and running the app with the right permissions...

This article has been dead for over six months. Start a new discussion instead.