So I can't find any information on this one and was wondering if anyone has encountered the same issue.
I'm using "c#" , with "Windows.Media.Capture" in a dot net core 3.1 build. When I use the build as an exe, I can communicate with the webcam and acquire images and record video.
However when I bundle the exe into a service( i'm using NSSM), I get an Unauthorized access exception on initialization.
I have changed the camera privacy settings to allow all desktop apps etc to use the camera.
I cannot find an option for services to access the camera. I have also changed the registry setting and created a group policy, but with no luck.
I believe it is a privacy setting of some form as the application works fine when run as a desktop application.
Any help would be greatly appreciated. Thanks Rob
Also here is the initialization code I'm using (straight from the Microsoft website). Just for transparency.
/// <summary>
/// Initializes the MediaCapture, registers events, gets camera device information for mirroring and rotating, starts preview and unlocks the UI
/// </summary>
/// <returns></returns>
private async Task InitializeCameraAsync()
{
Debug.WriteLine("InitializeCameraAsync");
var picturesLibrary = await
StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);
// Fall back to the local app storage if the Pictures Library is not available
_captureFolder = picturesLibrary.SaveFolder ?? ApplicationData.Current.LocalFolder;
if (_mediaCapture == null)
{
// Attempt to get the back camera if one is available, but use any camera device if not
var cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Back);
if (cameraDevice == null)
{
Debug.WriteLine("No camera device found!");
return;
}
// Create MediaCapture and its settings
_mediaCapture = new MediaCapture();
// Register for a notification when video recording has reached the maximum time and when something goes wrong
// _mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded;
// _mediaCapture.Failed += MediaCapture_Failed;
var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Video;
// Initialize MediaCapture
try
{
await _mediaCapture.InitializeAsync(settings);
_isInitialized = true;
}
catch (UnauthorizedAccessException)
{
Debug.WriteLine("The app was denied access to the camera");
throw new Exception("The app was denied access to the camera");
}
}
}