2013-05-16 39 views
0

我想通過運行批處理作業PowerShell腳本,我用下面的代碼,在一個工作順利進行:如何在批處理作業執行腳本使用interopPermission

System.Diagnostics.Process process; 
System.Diagnostics.ProcessStartInfo startInfo; 
; 
process = new System.Diagnostics.Process(); 
startInfo = new System.Diagnostics.ProcessStartInfo(); 
startInfo.set_FileName("powershell.exe"); 
startInfo.set_Arguments("D:\\Documents\\OP3_FTP_Upload.ps1"); 

startInfo.set_UseShellExecute(false); 
startInfo.set_RedirectStandardError(true); 
process.set_StartInfo(startInfo); 
process.Start(); 

當我使用這個代碼一個runbasebatch類,我有以下錯誤:

Failed to request the permission of type 'InteropPermission'. 
Unable to create object 'CLRObject' 

所以我嘗試使用以下方法來解決我的權限問題:

Set    permissionSet; 
InteropPermission interopPermission; 
; 
interopPermission = new InteropPermission(InteropKind::ClrInterop); 
permissionSet = new Set(Types::Class); 
permissionSet.add(interopPermission); 
CodeAccessPermission::assertMultiple(permissionSet); 

...my first code example 

CodeAccessPermission::revertAssert(); 

當我執行我的批處理作業時,我沒有錯誤消息,但沒有任何反應。路徑是正確的,腳本也是(parms糾正基於AOS) 我認爲問題是我的方式來實現permissionSet和interopPermission類,我知道如何使用它的情況下對文件的CRUD操作,但如何使用它在腳本執行的情況?任何人都可以解釋我如何(如果可能)在我的使用情況下管理這些類?

歡迎任何其他想法來解決我的問題。

回答

0

這應該是足夠的(在方法做CLR調用):

new InteropPermission(InteropKind::ClrInterop).assert(); 

否則儘量debug