当尝试通过WIA访问扫描仪时,访问被拒绝(HRESULT的异常:0x80070005(E_ACCESSDENIED))

时间:2019-04-16 05:53:52

标签: c# asp.net websocket wia

我有一个C#Windows应用程序,它带有集成的扫描器,并使用websocketd --port=7777 TarasolEdgeScanner.exe命令与WebSocket一起运行。

我有一个ASP.NET Web应用程序,使用js命令var ws = new WebSocket('ws://127.0.0.1:8085/');打开上述Windows应用程序 该应用程序正常打开。

我正在使用Microsoft Windows Imaging Acquisition(WIA)libray扫描Windows应用程序中的文档。当我单独打开Windows应用程序时,一切正常。但是,当我使用Web socket命令打开它时,出现以下异常:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at TarasolEdgeScanner.ScanForm.StartScan()
at TarasolEdgeScanner.ScanForm.btnScan_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
TarasolEdgeScanner
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/e3247/AppData/Local/Apps/2.0/ZHMO22OM.MEP/QOR9B6AK.G6W/tara..tion_0000000000000000_0001.0000_398fd06fc95c8a15/TarasolEdgeScanner.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Interop.WIA
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/e3247/AppData/Local/Apps/2.0/ZHMO22OM.MEP/QOR9B6AK.G6W/tara..tion_0000000000000000_0001.0000_398fd06fc95c8a15/Interop.WIA.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

我尝试调试,但失败了。这不是调试。请帮忙。

当我在没有ASP.NET表单的情况下单独运行代码时,代码运行良好

// Create a DeviceManager instance
var deviceManager = new DeviceManager();

// Create an empty variable to store the scanner instance
DeviceInfo firstScannerAvailable = null;


// Loop through the list of devices to choose the first available
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++)
{
// Skip the device if it's not a scanner
if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType)
{
continue;
}

firstScannerAvailable = deviceManager.DeviceInfos[i];

break;
}

// Show a message and stop if no connected scanners found
if (firstScannerAvailable == null)
{
MessageBox.Show("No connected scanners found!");
return;
}

// Connect to the first available scanner
var device = firstScannerAvailable.Connect();

// Select the scanner
var scannerItem = device.Items[1];
// Retrieve an image in JPEG format and store it into a variable
//var imageFile = (ImageFile)scannerItem.Transfer(FormatID.wiaFormatJPEG); //This scans without showing progress
CommonDialogClass dlg = new CommonDialogClass(); //To show scanning progress
//The exception raised in below line
object scanResult = dlg.ShowTransfer(scannerItem, WIA.FormatID.wiaFormatJPEG, false);

0 个答案:

没有答案
相关问题