工作powershell脚本不会按计划任务运行(Windows IOT - RPI 3)

时间:2016-05-30 14:35:20

标签: powershell raspberry-pi3 windowsiot

我们希望让我们的应用自动升级。由于Windows IOT没有Windows应用商店,我们必须手动完成。

这是我们的解决方案。如果我们的网络服务器上有新版本,我们的应用每7天检查一次。如果是,app将其下载到文件夹\ LocalState \ Install。

下一部分是powershell脚本,每小时检查该文件夹中是否有文件。如果是她安装它。

问题是我们无法按计划任务启动脚本,也无法使用powershell -File运行它(我们尝试了UnRestricted,Bypass和RemoteSigned的所有选项,我们也签了它)。

脚本是可以的,当我们从命令行启动它时它会工作。

有什么解决方案吗?请帮助:)

    $items = Get-ChildItem -Path "c:\Data\Users\DefaultAccount\AppData\Local\Packages\"

foreach ($item in $items)
{
      # if the item is a directory, then process it.
      if ($item.Attributes -eq "Directory")
      {
            if ($item.name -Match "<app name>") {           
                "Backuping ini files..."
                $AppPath = "c:\Data\Users\DefaultAccount\AppData\Local\Packages\" + $item + "\LocalState"
                $AppName = $item
                cp "$AppPath\*.ini" "C:\Data\Users\Administrator\Temp"

                $path1 = "c:\Data\Users\DefaultAccount\AppData\Local\Packages\" + $item.name + "\LocalState\Install\"
                $path = Get-ChildItem -Path $path1          
                $dependencies1 = $path1 + "Dependencies\ARM\"
                $dependencies = Get-ChildItem -Path $dependencies1              
                "Dependencies..."
                foreach ($dependency in $dependencies)
                {
                      if ($dependency.Attributes -ne "Directory")
                      {
                            "***** Installing: " + $dependency
                            Add-AppxPackage -ForceApplicationShutdown $dependencies1$dependency                   }
                }

                "APP update..."
                foreach ($p in $path)
                {
                      # if the item is NOT a directory, then process it.
                      if ($p.Attributes -ne "Directory")
                      {
                        if ($p.name -Match "appxbundle") {
                            "***** Installing: " + $p
                            Add-AppxPackage -ForceApplicationShutdown $path1$p                  
                        }   
                      }
                }       

                "Removing install files..."
                rm $path1\* -Recurse

                "Restoring ini files..."
                cp "C:\Data\Users\Administrator\Temp\*.ini" "$AppPath\"

                "Setting APP as default app"
                IotStartup add headed $AppName
                "Done"
            }
      }
}

0 个答案:

没有答案