How do I access a file from a "Windows 8 App" DLL?

352 views Asked by At

I wrote a DLL in Visual Studio Express 2012 for Windows 8. It's just a DLL so there's no app manifest specifying capabilities or anything like that. In the DLL, I'm calling StorageFile.GetFileFromPathAsync(). I'm calling the DLL from a PowerShell script.

When I use that function to access a file in the My Pictures folder, it works fine. When I try to access a file in my user folder, I get Access Denied.

What I really don't get is this: When I try this with the same DLL on another computer running the same operating system (Windows Server 2012), I get Access Denied for any folder, including the My Pictures folder.

So, my question is this: How do I get access to a file in the My Pictures folder on the second computer (as I did on the first), and if that is not possible with a DLL, then how is it working on the first computer?

More details:

Here's the exact code in the DLL:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Foundation;
using Windows.System.UserProfile;

namespace ExactFerret
{
    public class Windows8LockScreen
    {
        public static void SetBackground(string Path)
        {
            SetBackgroundTask(Path).GetAwaiter().GetResult();
        }

        private async static Task SetBackgroundTask(string FilePath)
        {
            StorageFile File = await StorageFile.GetFileFromPathAsync(FilePath);
            await LockScreen.SetImageFileAsync(File);
        }
    }
}

Here's how I'm calling the DLL in PowerShell:

Add-Type -Path .\Windows8.dll
[ExactFerret.Windows8LockScreen]::SetBackground('C:\Users\jigglypuff\Exact Ferret\Pictures\$ef$test.jpg')

Here's the error message I am getting:

Exception calling "SetBackground" with "1" argument(s): "Access is denied.
(Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
At line:1 char:1
+ [ExactFerret.Windows8LockScreen]::SetBackground('C:\Users\jigglypuff\Exact
Ferre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : UnauthorizedAccessException

Thank you!

0

There are 0 answers