none
How do I check if an Excel AddIn has permissions? RRS feed

  • Question

  • I'm writing configuration settings to the disk for my Excel AddIn. The user can independently navigate to the folder and create / open a file. My Excel Add-In can write the file to the same folder, but it cannot find the very same file to read the configuration. The configuration file itself has been confirmed to be in the folder, and the contents its contents are complete.

    I have verified that the folder being written to is on the list of trusted locations in Trust Center Settings under Options. I'm running Microsoft Office Professional Plus 2010. I'm using Visual Studio 2010 Ultimate to develop the Excel Add-In.

    Wednesday, January 29, 2014 5:07 PM

Answers

All replies

  • Hello Topstrok,

    You may treat a VSTO based add-in like a regular .Net application. Please read more about them in the Configuration Files section in MSDN.

    Where do you store a configuration file?

    Wednesday, January 29, 2014 5:36 PM
  • The VTSO add-in is not acting like a regular .Net application. My other .Net applications can both read and right to this same folder. The VTSO add-in cannot. This code works on my machine, but will always returns a false a non-admin machine.

    if (!File.Exists(the_setup_choices_file))
    {
        return false;
    }

    Is there a way to programatically check to see if sufficient permissions exist to to IO operations to the folder directory?

    Wednesday, January 29, 2014 5:52 PM
  • It looks like you missed my previous question to you. Where do you store a configuration file? What does the the_setup_choices_file stand for?

    Wednesday, January 29, 2014 6:23 PM
  • I store it on C:\adhe\configuration. This same folder is created in another .Net application of mine. The desire is to keep everything having to do with these projects under C:\adhe. The other .Net projects read and write to these folders with no problem. I'm not even able to test successfully for the presence of a file with the Excel AddIn. The Excel AddIn works on my machine, and can also find the file, and also works on my virtual machine. I need to be able to also look at other files of interest from the Excel Add-In also under the folder C:\adhe\configuration?

    I'm thinking it's a permissions thing.

    Wednesday, January 29, 2014 6:39 PM
  • The C:\ drive requires administrative permissions. Most probably a standalone .Net application was run with elevated permissions. Please check UAC settings on your machines.

    User Account Control (UAC) is a security component that enables users to perform common tasks as non-administrators (called standard users). User accounts that are members of the local Administrators group run most applications as a standard user. By separating user and administrator functions, UAC helps users move toward using standard user rights by default. So, the code can be run with different permissions.


    • Edited by Eugene Astafiev Wednesday, January 29, 2014 6:55 PM a link is added
    Wednesday, January 29, 2014 6:55 PM
  • I'm looking at the UAC link you gave under the section "Scenario 2: Configure an application to always run elevated." The suggestions are straightforward enough for a standalone location, but the Add-In is hosted by Excel. How can Excel be directed to run this Add-In with elevated privileges? Or should Excel itself be run with elevated privileges?

    Wednesday, January 29, 2014 7:07 PM
  • You can try to run Excel as an administrator. Does it help?

    Wednesday, January 29, 2014 8:25 PM
  • Running as administrator should have helped. This is one of two Add-Ins, and the other does not have a problem. The other Add-In is able to read and write to the folder -- and is also an Excel Add-In.

    The project itself appears to be corrupt and probably a new project needs to be created to house the code. From what has been stated, it should not be behaving the way its behaving.

    Friday, January 31, 2014 3:33 PM
  • Thank you for letting us know the results.
    Friday, January 31, 2014 4:02 PM
  • I rebuilt the project, and it was in fact corrupted. 

    Thanks for your help and have a good day.

    Friday, January 31, 2014 8:37 PM