通过下面提到的 C#代码执行Powershell查询Get-Content "C:\Windows\System32\Tasks\<file-name>"
,只返回Powershell控制台中返回数据的相同查询。请帮帮我。
注意:我正在使用 管理员 权限运行Visual Studio。
C#代码:
string Query = @"Get-Content 'C:\Windows\System32\Tasks\Adobe Acrobat Update Task'";
PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
ps.AddScript(Query);
var results = ps.Invoke();
错误消息:
"System.Management.Automation.ItemNotFoundException: Cannot find path 'C:\\Windows\\System32\\Tasks\\Adobe Acrobat Update Task' because it does not exist.\r\n at System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path, Boolean allowNonexistingPaths, PSDriveInfo drive, ContainerCmdletProvider provider, CmdletProviderContext context)\r\n at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(String path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletProvider& providerInstance)\r\n at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, CmdletProvider& providerInstance)\r\n at Microsoft.PowerShell.Commands.ContentCommandBase.ResolvePaths(String[] pathsToResolve, Boolean allowNonexistingPaths, Boolean allowEmptyResult, CmdletProviderContext currentCommandContext)"