Link to home
Start Free TrialLog in
Avatar of WeTi
WeTi

asked on

Powershell accessing to the desktop

Dear expert

Powershell: $env: USERPROFILE\desktop\folder\
now when I run it, it tells me a error that permission denied... ok weird... I don't use right to access my desktop? Now when I try and full path, it works well...

What is the problem?
Regards
WeTi
Avatar of oBdA
oBdA

When you run what exactly?
You need to be more specific about what it is you're trying to do and the exact error message you're getting.
Avatar of WeTi

ASKER

Hi oBdA

Its a decryption script by calling openssl. the error I get is:

openssl.exe : Can't open C:\Users\weti\desktop\secret for reading, Permission denied

Function Decry {
$Input = "$env:USERPROFILE\desktop\secret"
$Output = "$env:USERPROFILE\desktop\secret"
$UniqueKey = '(stdin)= aef44983e90b10***4af1742a15***8942'
$KeyFile = "$env:USERPROFILE\desktop\secret"
$RandomkeyFileName = Get-Random
$KeyFileExtractPath = "$Env:APPDATA\Microsoft"
openssl.exe enc -aes-256-cbc -salt -d -in $KeyFile -out $KeyFileExtractPath\"$RandomkeyFileName.key" -k $UniqueKey
$ReadKey = Get-Content -Path $KeyFileExtractPath\"$RandomkeyFileName.key"
$AllFiles = Get-ChildItem -Path $Input | ?{$_.Extension -eq $null -or $_.Extension -eq ""}
ForEach ($EachFile in $AllFiles){
$fullPath = $EachFile.FullName
$FileName = $EachFile.Name
    ForEach ($FileNameS in $ReadKey){
        $FileH,$FileN = $FileNameS.split(",",2)
       Write-Host "$FileH" -ForegroundColor Yellow
       Write-Host "$FileName" -ForegroundColor Green
            if($FileH -eq $FileName){
                Write-Host "Decrypted File : $FileN" -ForegroundColor Black -BackgroundColor White
                openssl.exe enc -aes-256-cbc -salt -d -in $fullPath -out $Output\$FileN -k $UniqueKey
            }
    }
}
Remove-Item $KeyFileExtractPath\"$RandomkeyFileName.key" -Force
}
Decry

Open in new window

Avatar of WeTi

ASKER

Thing is if I directly type:

$Input = 'C:\Users\weti\desktop\secret' This works... now because it will be a network shared script so env: must work tho...
Avatar of WeTi

ASKER

now I lied... direct input didn't work as well, same problem
Replace $Input with $SourceFolder or whatever. $Input is a default variable.

$input gotchas
https://dmitrysotnikov.wordpress.com/2008/11/26/input-gotchas/
Avatar of WeTi

ASKER

Did, didn't help, same problem. Now I really dont know what the hell is going on... It worked before with direct path...
Use
"$($env:USERPROFILE)\desktop\folder\"

Open in new window


NVM
now I lied... direct input didn't work as well, same problem
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WeTi

ASKER

After a restart, things started working well again. With my old option: $env:USERPROFILE