locked
LockScreen.SetImageFileAsync(…) throws UnauthorizedAccessException RRS feed

  • Question

  • I'm trying to set background image on lock screen in my WinRT app. But when this code is being executed i get an UnauthorizedAccessException with message:

    "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

    The code was taken from MSDN and looks like OK.

    private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var imagePicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                FileTypeFilter = { ".jpg", ".jpeg", ".png", ".bmp" },
            };
    
            var imageFile = await imagePicker.PickSingleFileAsync();
    
            if (imageFile != null)
            {
                await LockScreen.SetImageFileAsync(imageFile);
            }
        }

    The exception described below is thrown in this line of code:

    await LockScreen.SetImageFileAsync(imageFile);

    By the way, i've tried to install some applications which can change your background on lock screen, but all of them show error or just crash. Maybe something is wrong with my OS version?

    Does anyone know how to solve this problem? Please help!

    Friday, September 27, 2013 4:06 PM

Answers

  • In that case, I would recommend that you use Process Monitor tool: http://technet.microsoft.com/en-us/sysinternals/bb896645 to collect a trace while running the sample application and check for any registry/ file locations for which you get an "ACCESS DENIED" error. It sounds like some registry/ file location is giving you an access denied leading to the exception.

    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    • Marked as answer by Anne Jing Monday, October 7, 2013 2:10 AM
    Monday, September 30, 2013 8:56 PM
    Moderator

All replies

  • Can you apply a new background using the PC Settings --> Personalize option from Windows? Or is it just failing programmatically? Can you run the Lock Screen Personalization sample or does it give you the same issue?

    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    Friday, September 27, 2013 10:43 PM
    Moderator
  • I can set it by PC settings, everything is fine. But sample doesn't work, gives the same exception...
    Sunday, September 29, 2013 7:15 PM
  • In that case, I would recommend that you use Process Monitor tool: http://technet.microsoft.com/en-us/sysinternals/bb896645 to collect a trace while running the sample application and check for any registry/ file locations for which you get an "ACCESS DENIED" error. It sounds like some registry/ file location is giving you an access denied leading to the exception.

    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    • Marked as answer by Anne Jing Monday, October 7, 2013 2:10 AM
    Monday, September 30, 2013 8:56 PM
    Moderator