如何在批处理作业脚本执行上使用interopPermission

时间:2013-05-16 14:35:27

标签: batch-file permissions axapta dynamics-ax-2009

我正在尝试通过批处理作业运行powershell脚本,我使用以下代码在作业中正常工作:

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操作中使用它,但如果在脚本执行的情况下如何使用它?任何人都可以解释我如何(如果可能的话)在我使用的情况下管理这些类吗?

欢迎任何其他解决我问题的想法。

1 个答案:

答案 0 :(得分:1)

这应该足够了(在进行CLR调用的方法中):

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

否则请尝试debug