【问题标题】:This operation was canceled by user C#此操作已被用户 C# 取消
【发布时间】:2020-04-17 21:28:54
【问题描述】:

我有一个 Windows 应用程序,它调用服务器上需要域用户登录(用户名和密码)的文件夹的快捷方式。如果我直接运行快捷方式,那么我会得到 Windows 安全登录窗口,默认情况下将域设置为本地计算机,如果我输入凭据为 mydomain\myuser 然后密码然后它会正常打开。但是,当使用下面的代码从我的应用程序调用它时,我收到错误"This operation was canceled by user",并且没有出现 Windows 安全登录窗口。但是,如果我从 Windows 资源管理器运行快捷方式并使用 Windows 安全登录窗口登录,那么我运行我的应用程序,它将直接打开服务器文件夹。所以我想知道如何让我在运行我的应用程序时出现windows安全登录窗口,就像我正常点击快捷方式一样。

        string desktoppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        Process proc2 = new Process();
        proc2.StartInfo.FileName = desktoppath + @"\ServerFolder.lnk";
        proc2.Start();
        proc2.Close();

这是我收到的错误消息:

这是细节:

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

************** Exception Text **************
System.ComponentModel.Win32Exception (0x80004005): The operation was canceled by the user
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at MyApp_ServerConnection.Form1.button1_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.8.4110.0 built by: NET48REL1LAST_B
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
MyApp-ServerConnection
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/MyApp-Connect-Disconnect/MyApp-ServerConnection.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4110.0 built by: NET48REL1LAST_B
    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.8.4110.0 built by: NET48REL1LAST_B
    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.8.3761.0 built by: NET48REL1
    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.8.3761.0 built by: NET48REL1
    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.8.4110.0 built by: NET48REL1LAST_B
    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.8.3761.0 built by: NET48REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.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.

【问题讨论】:

  • 你会提到 UAC。可能是反恶意软件介入,一个看似无处出现的.exe文件,接下来提示输入网络密码当然是一个很大的责任。暂时禁用它,看看是否会改变结果。
  • @HansPassant 我按照此链接中的步骤禁用了 UAC,但仍然存在同样的问题firehousesoftware.com/webhelp/FH/Content/…
  • 否,暂时禁用已安装的反恶意软件产品。
  • @HansPassant 我试过这个但仍然是同样的错误信息。有什么建议吗?
  • @HansPassant 如果我提供了用户名和密码文本框然后以某种方式使用这些凭据访问链接,是否有办法从应用程序本身连接到共享路径?

标签: c# security shortcut windows-security


【解决方案1】:

当您启动进程时,您会立即调用Close() 方法,从而取消用户的操作。您可以调用proc2.WaitForExit() (Link),然后在Exited 事件触发时调用的方法中调用proc2.Close()

有关如何创建活动的更多信息,请参阅Process.Exited

【讨论】:

  • 我试过了,但仍然是同样的错误。我已经用错误的屏幕截图及其详细信息更新了我的问题。
  • 有什么区别?我的意思是,如果用户已经登录,它就可以工作,所以我不确定,但我可以试试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-17
  • 2016-08-04
  • 2014-09-02
  • 2021-09-19
相关资源
最近更新 更多