2016-08-24 10 views
0

私は、ファイル共有上の.exeのバージョンをチェックし、それをユーザーのデスクトップ上の.exeと比較するはずのスクリプトの先頭にバージョンチェック機能を持っています。バージョンが異なる場合は、現在のデスクトップ.exeが削除され、ファイル共有上のものと置き換えられます。ただし、.exeから実行した場合は置き換えられませんが、PowerShell StudioまたはISEから実行すると機能します。私はPowerShell Studioを.exeにコンパイルしています。ここに私のコードです:PowerShell - アイテムを削除してアイテムをコピー

function global:VersionCheck 
{ 
    # Get filepath of updated program 
    $updatedprogram = (Get-Item \\fileshare\example\DeviceHealth\DeviceHealthV2.exe).VersionInfo | select -ExpandProperty FileVersion 
    # Get version of current script on device 
    $outdateprogram = (Get-Item c:\Users\$env:USERNAME\desktop\DeviceHealthV2.exe).VersionInfo | select -ExpandProperty FileVersion 

    if ($updatedprogram -ne $outdateprogram) 
    { 
     [System.Windows.Forms.MessageBox]::Show("Program will be updated", "Out of Date") 
     Start-Sleep -Seconds 2 
     Remove-Item -Path "c:\Users\$env:USERNAME\desktop\DeviceHealthV2.exe" -Force 
     Start-Sleep -Seconds 2 
     Copy-Item -Path "\\fileshare\example\DeviceHealth\DeviceHealthV2.exe" -Destination "c:\Users\$env:USERNAME\desktop" -Force 
    } 
    else { } 
} 

VersionCheck 

私はそれが.exeとしてそれを実行するときに動作しない理由を誰かが私を助けることができますか?ありがとう。

+0

実行ファイルはどのように実行されていますか?ユーザーまたはサービスによって?実行しているすべてのものが共有にアクセスできますか? – Matt

+0

ユーザーによってデスクトップから管理者として実行されています。そこにある他のものにアクセスするので、共有にアクセスできます。 –

+0

実行中の同じ実行可能ファイルを置換するアイテムはありますか?ユーザーがDeviceHealthV2.exeを起動していて、それを削除/置き換えしようとしていますか? – TheMadTechnician

答えて

0

私の明らかな解決策が見つかりました。私は、アップデータのための別のスクリプトを作成したとする私のスクリプトを変更:

function global:VersionCheck 
{ 
    # Get filepath of updated program 
    $updatedprogram = (Get-Item \\fileshare\test\DeviceHealth\DeviceHealthV2.exe).VersionInfo | select -ExpandProperty FileVersion 
    # Get version of current script on device 
    $outdateprogram = (Get-Item c:\Users\$env:USERNAME\desktop\DeviceHealthV2.exe).VersionInfo | select -ExpandProperty FileVersion 

    if ($updatedprogram -ne $outdateprogram) 
    { 
     [System.Windows.Forms.MessageBox]::Show("Program will be updated", "Out of Date") 
     Start-Process "\\fileshare\test\scripts\Martin\PMCS\DeviceHealthUpdate.exe" -WindowStyle Hidden 
    } 
    else { } 
} 

VersionCheck 

と私は入れて更新スクリプトで:

Get-Process DeviceHealthV2 | Foreach-Object { $_.CloseMainWindow() | Out-Null } | stop-process –force 
Remove-Item -Path "c:\Users\$env:USERNAME\desktop\DeviceHealthV2.exe" -Force 
Start-Sleep -Seconds 1 
Copy-Item -Path "\\fileshare\ask\DeviceHealth\DeviceHealthV2.exe" -Destination "c:\Users\$env:USERNAME\desktop" -Force 
Start-Sleep -Seconds 1 
Start-Process "\\fileshare\ask\DeviceHealth\DeviceHealthV2.exe" 
Start-Sleep -Seconds 1 
[System.Windows.Forms.MessageBox]::Show("Update Successful", "Complete") 

私はそれをテストし、それは素晴らしい作品。みなさんのおかげでありがとう!

関連する問題