2017-02-10 7 views
4

PSスクリプトを使って膨大な数のCrystal Reports(Windows 7)の.xml表現を生成しています。このスクリプトでは、解析する必要があるすべてのファイルを表すオブジェクトを作成し、それらのファイルをループして1つずつ.exeを呼び出します。場合によっては、この.exeがクラッシュすることがあります。これは非常にまれで、処理できないレポートは手動でフラグを立てて見直すことができるため、問題ありません。問題は、処理する.rptファイルが何千もあり、.exeがクラッシュすると、Windowsはデバッグまたは続行を求めるダイアログを表示します。Powershellから.exeを呼び出すときに「プログラムが動作しなくなりました」というダイアログを表示させないようにする

enter image description here

物事私はこの問題を解決するために試してみました:

    \ DebugApplicationsを報告
  • ます。HKEY_CURRENT_USER \ Software \ Microsoft \ Windowsの\ Windowsエラー:私はここに私のexeファイル名を入れて、設定0に値(ではない、デバッグを行う)

  • HKEY_LOCAL_MACHINE \ SOFTWARE \マイクロソフト\ Windowsの\ Windowsエラー報告\ DebugApplications:

  • 上記と同じ
  • はSilentlyContinueというのexeファイルを呼び出すループを設定し

  • 次のようにエラー報告をオフにします。コントロールパネル]> [アクションセンター>変更アクションセンターの設定]> [問題の報告[設定]> [すべてのユーザーの変更レポート設定>「をチェックすることはありません[OK]> [OK]をクリックします(これにより、[Windowsはオンラインでチェックできません]ダイアログボックスが表示されます)。

まだポップアップが表示されています。 「プログラムは動作を停止しました」UIを完全に無効にする別のregキーがありますが、他のアプリケーションの開発者として、いつクラッシュするのかを知る必要があるため、これをやりたくありません。私は、このスクリプトまたはそれを呼び出すexeをUIの表示から除外したいだけです。

これを行うことができれば、スクリプトは無人で実行できます。

misbehavesは、ここから最新のバイナリリリース:https://github.com/ajryan/RptToXmlであり、レポートファイルにヌルバイトが発生すると失敗するようです。

は、ここに私のコードです:

[xml]$MainConfigFile = Get-Content "settings.config.xml" 
[xml]$SSRSConfigFile = Get-Content "ssrs.config.xml" 
[xml]$CrystalConfigFile = Get-Content "crystal.config.xml" 

# create settings objects from xml objects 
$MainSettings = @{ 
    OutputPath = $MainConfigFile.Settings.OutputPath 
    SearchString = $MainConfigFile.Settings.SearchString 
    ParseCrystal = $MainConfigFile.Settings.ParseCrystal 
    ParseSSRS = $MainConfigFile.Settings.ParseSSRS 
} 

$CrystalSettings = @{ 
    InputFolderPath = $CrystalConfigFile.CrystalSettings.InputFolderPath 
    ContinueOnError = $CrystalConfigFile.CrystalSettings.ContinueOnError 
} 

$RsSettings = @{ 
    ReportServerUri = $SSRSConfigFile.RsSettings.ReportServerUri 
    RsVersion = $SSRSConfigFile.RsSettings.RsVersion 
} 

Clear 

Write-Host "Ensure these settings are correct before you proceed:" -ForegroundColor Yellow 
Write-Host "" 

Write-Host "Main Settings" -ForegroundColor Green 
$MainSettings 
Write-Host "" 

Write-Host "Crystal Settings" -ForegroundColor Green 
$CrystalSettings 
Write-Host "" 

Write-Host "SSRS Settings" -ForegroundColor Green 
$RsSettings 
Write-Host "" 

# user must confirm 
[string]$SettingsOK=(Read-Host "[Y] to proceed, [N] to quit:") 
if ($SettingsOK -ne "Y") {exit} 

Write-Host "" 
Write-Host "______________________________________" 
Clear 

# is the output path syntax valid? 
if (!(Test-Path -Path $MainSettings.OutputPath -IsValid)) { 
    Write-Host -ForegroundColor Green "Output path syntax is invalid:" $MainSettings.OutputPath 
    exit 
    } else { 
    Write-Host -ForegroundColor Green "Output path syntax is correct:" $MainSettings.OutputPath 
    } 

# does the output path exist? 
if (!(Test-Path -Path $MainSettings.OutputPath)) { 
    Write-Host -ForegroundColor Yellow "Output path does not exist:" $MainSettings.OutputPath 
    [string]$CreateOutputPathOK=(Read-Host "[Y] to create the directory, [N] to quit.") 
     if ($CreateOutputPathOK -ne "Y") {exit} else {New-Item -Path $MainSettings.OutputPath -ItemType Directory} 
    } else { 
    Write-Host -ForegroundColor Green "Output path already exists:" $MainSettings.OutputPath 
} 

Write-Host "" 
Write-Host "______________________________________" 
Clear 

# get all .rpt files in the input folder, recursively 
$CrystalFiles=Get-ChildItem -Path $CrystalSettings.InputFolderPath -Include "*.rpt" -Recurse 

Write-Host "" 
# count files first and ask the user if they want to see the output, otherwise proceed 
Write-Host -ForegroundColor Yellow $CrystalFiles.Count ".rpt files were found in" $CrystalSettings.InputFolderPath 
[string]$ShowFilesOK=(Read-Host "[Enter] to proceed, [Y] to view the list of files in the directory, [N] to quit.") 
if ($ShowFilesOK -eq "Y") { 
    Clear 
    # loop through the collection of files and display the file path of each one 
    $CrystalFiles | ForEach-Object -Process {$_.FullName.TrimStart($CrystalSettings.InputFolderPath)} 
    Write-Host "______________________________________" 
    # user must confirm 
    Write-Host "" 
    Write-Host -ForegroundColor Yellow "The above .rpt files were found in" $CrystalSettings.InputFolderPath 
} elseif ($ShowFilesOK -eq "N") {exit} 

Write-Host "" 
[string]$ProcessingOK=(Read-Host "[Y] to proceed with .rpt file processing, [N] to quit:") 
if ($ProcessingOK -ne "Y") {exit} 

Write-Host "" 
Write-Host "______________________________________" 
Clear 

# create a dir inside the output path to hold this run's output 
Write-Host -ForegroundColor Green "Creating folder to hold this run's output..." 
$RunDir = (New-Item -Path $MainSettings.OutputPath -Name "$(Get-Date -f yyyy-mm-dd__hh_mm_ss)" -ItemType Directory) 
$RunDir.FullName 

# use .NET ArrayList because immutable PS arrays are very slow 
$Success = New-Object System.Collections.ArrayList 
$Failure = New-Object System.Collections.ArrayList 

#loop through the collection again, this time processing each file and dumping the output to the output dir 
$CrystalFiles | ForEach-Object -ErrorAction SilentlyContinue -Process { 
    $RelativePathName = $_.FullName.TrimStart($CrystalSettings.InputFolderPath) 
    $XmlFileName = "$RunDir\$RelativePathName.xml" 

    # force-create the file to ensure the parent folder exists, otherwise RptToXML will crash trying to write the file 
    New-Item -Path $XmlFileName -Force 
    # then simply delete the empty file 
    Remove-Item -Path $XmlFileName 

    Write-Host -ForegroundColor Green "Processing file" $RelativePathName 
    CMD /c .\RptToXML\RptToXml.exe $_.FullName $RunDir\$($_.FullName.TrimStart($CrystalSettings.InputFolderPath)).xml 
    if ($LASTEXITCODE -eq 0) { 
     Write-Host "Success" $Success.Add($RelativePathName)} else {Write-Host "Failure" $Failure.Add($RelativePathName)} 
    } 

$Success | Export-CSV "$RunDir\CrystalSuccess.txt" 
$Failure | Export-CSV "$RunDir\CrystalFailure.txt" 
+0

それは

  • をクラッシュした場合でも戻り、呼び出し元に制御を返すスクリプトを呼び出します'に' -Timeout'パラメータを指定して、ジョブが妥当な時間内に完了しない場合、ジョブを強制終了します。これにより、応答しないアプリケーションとそのポップアップが停止するはずです。 – TheMadTechnician

  • 答えて

    2

    私は自分の質問に答える、これを行うことを憎むが、私は今のところ回避策を見つけました。

    # Disable WER temporarily 
    Set-ItemProperty "HKCU:\Software\Microsoft\Windows\Windows Error Reporting" -Name DontShowUI -Value 1 
    

    ループ後::これは別のスクリプトからこのスクリプトを呼び出すことによって改善される

    # Reset the WER UI reg key 
    Set-ItemProperty "HKCU:\Software\Microsoft\Windows\Windows Error Reporting" -Name DontShowUI -Value 0 
    

    :ループの前に

    • は、現在の値を取得します。変更するキー
    • 変更する
    • あなたは常にバックグラウンドジョブとして実行可能ファイルを実行し、 `待って、ジョブを使用することができ、元の値にREGキー
    関連する問題