【发布时间】:2012-12-01 22:12:14
【问题描述】:
我正在尝试从 C# 代码以编程方式启动 SharePoint 命令行管理程序,但当我从“开始”菜单中选择它时,我得到了不同的行为。我尝试了两种不同的方法,结果相同:
尝试 #1:
var startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = true;
startInfo.Verb = "runas";
startInfo.FileName = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\PowerShell.exe";
startInfo.Arguments = "-NoExit \" & 'C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\CONFIG\\POWERSHELL\\Registration\\sharepoint.ps1' \"";
Process.Start(startInfo);
尝试 #2:
var startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = true;
startInfo.Verb = "runas";
startInfo.FileName = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Microsoft SharePoint 2010 Products\\SharePoint 2010 Management Shell.lnk";
Process.Start(startInfo);
这两种方法都会启动一个 PowerShell 窗口并显示以下错误消息:
文件 C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CO NFIG\POWERSHELL\Registration\SharePoint.ps1 不能 加载是因为在此系统上禁用了脚本的执行。 有关更多详细信息,请参阅“get-help about_signing”。在行:1 字符:3 + &
当我从“开始”菜单启动它时,它运行良好。关于为什么这种行为不同的任何想法?在尝试 #1 中,我运行与链接相同的可执行文件和参数。在尝试 #2 中,我尝试运行链接本身。
谢谢!
【问题讨论】:
标签: c# sharepoint powershell