【发布时间】:2021-07-03 01:09:11
【问题描述】:
所以我找不到关于这个的任何信息,想知道是否有人遇到过同样的问题。
我在 dot net core 3.1 版本中使用 "c#" 和 "Windows.Media.Capture"。 当我将构建用作 exe 时,我可以与网络摄像头通信并获取图像并录制视频。
但是,当我将 exe 捆绑到服务中时(我正在使用 NSSM),我在初始化时遇到未经授权的访问异常。
我已更改相机隐私设置以允许所有桌面应用等使用相机。
我找不到访问相机的服务选项。我还更改了注册表设置并创建了组策略,但没有运气。
我认为这是某种形式的隐私设置,因为应用程序在作为桌面应用程序运行时可以正常工作。
任何帮助将不胜感激。 谢谢 抢
这也是我正在使用的初始化代码(直接来自 Microsoft 网站)。只是为了透明。
/// <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");
}
}
}
【问题讨论】:
-
我也试过在用户账户、管理员账户和本地系统账户下运行服务。
标签: c# windows webcam privacy privacy-policy