首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell "Start-process“未按计划任务运行

Powershell "Start-process“未按计划任务运行
EN

Stack Overflow用户
提问于 2014-04-18 02:20:01
回答 2查看 2.4K关注 0票数 1

我在XP中编辑了两个powershell脚本,以便在Win Server2k8 R2中运行。

它们在powershell中手动执行时运行良好,但如果计划并以域管理员身份运行,它们会执行所有应该执行的文件操作;只是它们不会执行将文件发送到需要转到的SFTP站点的启动进程。

它们是通过运行带有如下参数的powershell.exe启动的:

代码语言:javascript
复制
-noprofile -ExecutionPolicy Bypass -file C:\Users\administrator\Documents\script1.ps1

同样,正如我前面提到的,如果您手动运行它们,它们运行良好,并根据请求启动start-process,并且仅在文件操作被调度时才运行它们,并跳过启动过程。

start-process如下:

代码语言:javascript
复制
start-process -FilePath "c:\Program Files (x86)\Tumbleweed\STClient\stclient.exe" -ArgumentList "httpsu://www.securesiteexample.org/incoming/ $filename /prefNoAskSched /hidden /log /Remote-Site return /quitWhenDone"

我遗漏了什么?

EN

回答 2

Stack Overflow用户

发布于 2014-04-18 04:07:45

添加一些代码进行检查,以确保进程正在启动。

代码语言:javascript
复制
$FileName = 'c:\test\test.txt';
$ArgumentList = "httpsu://www.securesiteexample.org/incoming/ $filename /prefNoAskSched /hidden /log /Remote-Site return /quitWhenDone";
$ExePath = 'c:\Program Files (x86)\Tumbleweed\STClient\stclient.exe';

$Process = Start-Process -FilePath $ExePath -ArgumentList $ArgumentList -PassThru;

# If $Process variable is null, then something went wrong ...
if (!$Process) {
    # Process did not start correctly! Write the most recent error to a file
    Add-Content -Path $env:windir\temp\sftp.log -Value $Error[0];
}
票数 0
EN

Stack Overflow用户

发布于 2014-04-18 16:08:37

在Task中,转到Actions窗格,编辑并删除start In字段中的所有内容。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23140588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档