2016-07-03 26 views
0

我想使用Powershell在註銷期間自動運行ccleaner,我將添加爲註銷腳本。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} 
+0

看來你忘了,包括在你的問題的問題。 – Biffen

+0

普遍的共識是不要使用CCleaner。不相關,不是一個答案,但不值得風險。 https://superuser.com/questions/199151/should-i-use-registry-cleaners –

回答

-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

你可以這樣做:

$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 
} 
+0

找不到接受參數「真」的位置參數。 在線:3 char:13 + if(Test-Path <<<< = True){0}類別信息:InvalidArgument:(:) [Test-Path],ParameterBindingException + FullyQualifiedErrorId:PositionalParameterNotFound,Microsoft.PowerShell.Commands .TestPathCommand – DisplayName

+0

我的代碼正在工作(至少在我的系統上)並且不包含單詞「True」。請嘗試在沒有事先修改的情況下運行它;-)。 – sodawillow

+0

我很高興你們幫助我保持清理我將添加爲註銷腳本的服務器 – DisplayName