Powershell:此操作返回,因为超时时间已过期
Powershell : This operation returned because the timeout period expiredAt
我正在尝试 运行 xTestPlan_1.ps1
来自 enable_local.ps1
。
虽然 enable_local.ps1
在我的本地计算机上,但 xTestPlan_1.ps1
在网络驱动器上。我的本地计算机上只有 xTestPlan_1.ps1
的快捷方式。
这里是enable_local.ps1
:
$item = "d:\temp\xTestPlan_1.lnk"
WriteInLogFile "$item"
Try
{
& "$item"
}
Catch
{
WriteInLogFile $Error
}
在 运行 执行此代码时,有时会出现此错误:
Program "xTestPlan_1.lnk" failed to run: This operation returned
because the timeout period expired At D:\Temp\enable_local.ps1.
此脚本有时会按预期运行,有时却不起作用。 xTestPlan_1.ps1
确实存在于网络驱动器上。
尝试执行快捷方式不是 运行 另一个脚本的好方法。
更好的做法是直接调用脚本:
$item = "\server\share\xTestPlan_1.ps1"
WriteInLogFile "$item"
Try
{
& $item
}
Catch
{
WriteInLogFile $Error
}
如果由于某种原因你真的必须使用快捷方式,你可以从快捷方式中获取目标路径,然后调用脚本本身。
$item = "d:\temp\xTestPlan_1.lnk"
$ShellObj = New-Object -COM WScript.Shell
$targetPath = $ShellObj.CreateShortcut($item).TargetPath
WriteInLogFile "$targetPath"
Try
{
& $targetPath
}
Catch
{
WriteInLogFile $Error
}
我正在尝试 运行 xTestPlan_1.ps1
来自 enable_local.ps1
。
虽然 enable_local.ps1
在我的本地计算机上,但 xTestPlan_1.ps1
在网络驱动器上。我的本地计算机上只有 xTestPlan_1.ps1
的快捷方式。
这里是enable_local.ps1
:
$item = "d:\temp\xTestPlan_1.lnk"
WriteInLogFile "$item"
Try
{
& "$item"
}
Catch
{
WriteInLogFile $Error
}
在 运行 执行此代码时,有时会出现此错误:
Program "xTestPlan_1.lnk" failed to run: This operation returned because the timeout period expired At D:\Temp\enable_local.ps1.
此脚本有时会按预期运行,有时却不起作用。 xTestPlan_1.ps1
确实存在于网络驱动器上。
尝试执行快捷方式不是 运行 另一个脚本的好方法。
更好的做法是直接调用脚本:
$item = "\server\share\xTestPlan_1.ps1"
WriteInLogFile "$item"
Try
{
& $item
}
Catch
{
WriteInLogFile $Error
}
如果由于某种原因你真的必须使用快捷方式,你可以从快捷方式中获取目标路径,然后调用脚本本身。
$item = "d:\temp\xTestPlan_1.lnk"
$ShellObj = New-Object -COM WScript.Shell
$targetPath = $ShellObj.CreateShortcut($item).TargetPath
WriteInLogFile "$targetPath"
Try
{
& $targetPath
}
Catch
{
WriteInLogFile $Error
}