微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 外部程序执行模拟模式

我们有一个传统的CRM系统(服务器),它使用映射的网络驱动器.问题是驱动器完全打开以供任何用户修改.

我正在尝试在c#.net控制台应用程序(客户端A)中使用用户模拟.

>客户端A执行.exe程序(控制台应用程序),进行模拟(域,另一个用户,密码).
>然后控制台应用程序将网络文件夹映射到驱动器:


    

NETRESOURCE nr = new NETRESOURCE();
    nr.dwType = ResourceType.RESOURCETYPE_disK;
    nr.lpLocalName = "X:";
    nr.lpRemoteName = @"\\x.x.x.x\folderx";
    nr.lpProvider = null;

    int result = WNetAddConnection2(nr,null,0);

>然后,控制台应用程序尝试打开位于映射网络驱动器中的.exe程序


    

Process ExternalProcess = new Process();
    ExternalProcess.StartInfo.FileName = @"X:\subfolder\APP\app.exe"; // Window application
    ExternalProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
    ExternalProcess.Start();
    ExternalProcess.WaitForExit();

但我得到Win32Exception:


    

UnkNown error (0xfffffffe)
    in System.Diagnostics.Process.StartWithShellExecuteEx(processstartinfo startInfo)
    in System.Diagnostics.Process.Start()
    in SecureApp.Program.Main(String[] args) en \\vmware-host\Shared Folders\Documents\Visual Studio 2010\Projects\SecureApp\SecureApp\Program.cs:línea 142
    in System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String[] args)
    in System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String[] args)
    in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    in System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean ignoreSyncCtx)
    in System.Threading.ExecutionContext.Run(ExecutionContext executionContext,Object state)
    in System.Threading.ThreadHelper.ThreadStart()

文件夹共享属性将模仿中使用的用户作为唯一可以阅读&写.

简而言之,我希望我的外部程序作为模拟用户执行.

编辑

这就是我想要做的事情:

> Windows用户登录
>用户打开一个模拟程序,将网络文件夹映射到驱动器,最后以模拟用户身份调用CRM可执行文件,但是,网络驱动器必须仅在CRM上下文中可用.

我的观点是:我可以将映射的网络驱动器仅用于作为模拟用户执行的程序,但不能用于当前登录的Windows用户吗?

解决方法

您可能希望确保网络位置是可信的:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/e4a65263-24f9-45a6-a2ad-6c26aae36075/how-to-run-net-executable-on-a-network-drive?forum=clr

https://technet.microsoft.com/en-us/library/bb496428.aspx

根据您的具体情况,在本地计算机上缓存可执行文件可能是最佳选择,因为它不太容易受到网络中断的影响,并且您不必担心程序执行时从您下面发生的事情.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐