CCleaner作为清理工具

时间:2016-07-03 07:51:03

标签: powershell

我想在注销期间使用Powershell自动运行ccleaner,我将添加为注销脚本。

我希望ccleaner能够运行,无论它是哪个文件夹。

如果不是ProgramFiles(x86)那么ProgramFiles。

$I="$env:ProgramFiles(x86)\CCleaner\CCleaner.exe"
$y="$env:ProgramFiles\CCleaner\CCleaner.exe"
if ((test-path $I) -or (test-path $y))
**{& $y '/AUTO' -or $I '/AUTO'}**
else
{ will add temp cleaning script here} 

2 个答案:

答案 0 :(得分:1)

你可以这样做:

$path32 = Join-Path ${env:ProgramFiles(x86)} "Ccleaner"
$path64 = Join-Path $env:ProgramFiles "Ccleaner"

if(Test-Path $path32) {
    $exePath = Join-Path $path32 "Ccleaner.exe"
    & $exePath "/auto"
} elseif (Test-Path $path64) {
    $exePath = Join-Path $path64 "Ccleaner.exe"
    & $exePath "/auto"
} else {
    #manual temp cleaning
}

答案 1 :(得分:-1)

运行此

$path32 = Join-Path "$env:ProgramFiles(x86)" "Ccleaner"
$path64 = Join-Path $env:ProgramFiles "Ccleaner"

if(Test-Path $path32) {
    $exePath = Join-Path $path32 "Ccleaner.exe"
    & $exePath "/auto"
} elseif (Test-Path $path64) {
    $exePath = Join-Path $path64 "Ccleaner.exe"
    & $exePath "/auto"
} else {
    #manual temp cleaning
}