gpt4 book ai didi

powershell - 调用项目未从计划任务执行

转载 作者:行者123 更新时间:2023-12-02 23:58:09 25 4
gpt4 key购买 nike

我想知道是否有人可以指出为什么脚本的最后一行没有通过预定任务运行,该任务在登录时以系统帐户身份运行。
当我手动运行时,该行运行

我也尝试过start-process而不是invoke-item

$username = Get-WmiObject -class Win32_ComputerSystem | select-object   -ExpandProperty username 
$username = $username.replace(Domainname\', '')

$FaxClientService = 'printclient'
$FaxClientexec = 'C:\program files (x86)\fax\client\bin\printclient.exe'

$WantFile = "c:\users\'+$username+'\appdata\roaming\fax\client\PrintToFaxUserSettings.xml"
$FileExists = Test-Path $WantFile
If ($FileExists -eq $true)
{
exit
}

Else
{
# Insert username into XML
$xml = new-object XML
$xml.PreserveWhiteSpace = $true
$xml.load("C:\temp\faxprinter\PrintToFaxUserSettings.xml")
$xml.usersettings.username = $username
$xml.PreserveWhiteSpace = $true
$xml.save("C:\temp\faxprinter\PrintToFaxUserSettings.xml")
Start-Sleep -s 10
$ErrorActionPreference = "SilentlyContinue"
Stop-Process -processname $FaxClientService -Force
$ErrorActionPreference = "Stop"
New-Item c:\users\$username\appdata\roaming\fax -type directory
New-Item c:\users\$username\appdata\roaming\fax\Client -type directory

$source = 'c:\temp\faxprinter\PrintToFaxUserSettings.xml'
$dest = 'c:\users\' + $username + '\appdata\roaming\fax\client\PrintToFaxUserSettings.xml'
Copy-Item -Force $source $dest
Start-Sleep -s 30
Invoke-Item $FaxClientexec
}

最佳答案

如果任务

  • 登录时触发
  • 访问用户个人资料
  • 包括一个交互式操作(启动应用程序)

  • 那么听起来确实像您希望它以 Users和“仅当用户登录时”而不是 SYSTEM一样运行。

    关于powershell - 调用项目未从计划任务执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37351601/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com