【问题标题】:Custom NSSM windows service cannot access webcam, windows,自定义 NSSM windows 服务无法访问网络摄像头、windows、
【发布时间】: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


【解决方案1】:

我认为这是某种形式的隐私设置,因为应用程序在作为桌面应用程序运行时可以正常工作。

可能是用户界面特权隔离或会话 0 隔离。有一些 Vista 时代的黑客可以尝试绕过它们,它们可能适用于 Win10,也可能不适用,但这些黑客从来没有被推荐过,而且这些天肯定会被皱眉。

最好的解决方案可能是将 Win32 服务替换为自动启动的应用程序。如果您绝对需要 Win32 服务,那么您可能需要使用较低级别的 API。

【讨论】:

  • 感谢您的回复。我现在将它作为启动应用程序临时运行。但我以后还得去下一层。
猜你喜欢
  • 1970-01-01
  • 2021-07-22
  • 2018-09-17
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 2011-06-12
  • 1970-01-01
相关资源
最近更新 更多