2016-04-25 117 views
4

我們有一個使用映射網絡驅動器的傳統CRM系統(服務器)。問題是驅動器完全打開以供任何用戶修改。外部程序執行模擬模式

我想在c#.net控制檯應用程序(客戶端A)中使用用戶模擬。

  1. 客戶端A執行一個.exe程序(控制檯應用程序),這使得模擬(域,另一個用戶,密碼)。

  2. 然後控制檯應用程序的網絡文件夾映射到一個驅動:

 

    
    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, 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, ContextCallback callback, Object state) 
        in System.Threading.ThreadHelper.ThreadStart() 
     
    
    

    文件夾共享屬性具有在模擬中使用的用戶作爲唯一可以讀取&寫入的用戶。

    總之,我希望我的外部程序作爲模擬用戶執行。

    編輯

    這裏有一個我想要真正做到:

    1. Windows用戶登錄到域
    2. 用戶打開一個程序,使模擬,映射網絡文件夾,驅動器和最後將CRM可執行文件作爲模擬用戶調用,但是,網絡驅動器必須僅在CRM上下文中可用。

    我的觀點是:我可以映射的網絡驅動器僅適用於以模擬用戶身份執行的程序,但不適用於當前登錄的Windows用戶?

    +0

    您是否已驗證相關帳戶對目標文件夾具有讀取和執行權限,而不僅僅是讀取權限?另外,您使用的是哪個版本的.Net框架? – Robert

    +0

    是的,羅伯特。該帳戶具有完整的讀取和寫入權限。框架版本是4. – Kingslayerpy

    +0

    如果可執行文件存儲在本地,程序是否工作?此外,當您嘗試此操作時會發生什麼情況:ExternalProcess.StartInfo.FileName = @「\\ x.x.x.x \ folderx \ subfolder \ APP \ app。exe「 – Robert

    回答