我想在桌面上执行"google chrome"的目标路径



我想执行"google chrome"在我的桌面上。但这行不通。请问你有解决办法吗?下面是我的代码:

function targetshortcut {
$path="C:UsersPublicDesktop"
$a=get-childitem $path | Where-Object {$_.BaseName -like "Google Chrome"}
$a.FullName
$b=$a.FullName
$sh = New-Object -COM WScript.Shell
$targetPath1 =  $sh.CreateShortcut($b).TargetPath 
return $targetPath1
}
$targetshortcut1=targetshortcut 
$targetshortcut1

function executeasadmninsage {
param (
$pathco
)
Start-Process -FilePath  $pathco -Verb RunAs -PassThru
}

$executeasadmninsage1=executeasadmninsage  [string]$targetshortcut1
$executeasadmninsage1

我有这样的输出:

PS D:powershell1> d:powershell1rund.ps1
C:UsersPublicDesktopGoogle Chrome.lnk
C:Program Files (x86)GoogleChromeApplicationchrome.exe
Start-Process: D:powershell1rund.ps1:33:9
Line |
33 |          Start-Process -FilePath  $pathco -Verb RunAs -PassThru
|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| This command cannot be run due to the error: Le fichier spécifié est introuvable.

解决方案如下:

function targetshortcut {
$path="C:UsersPublicDesktop"

$a=get-childitem $path | Where-Object {$_.BaseName -like "Google Chrome"}
$b=$a.FullName

$sh = New-Object -COM WScript.Shell


$targetPath1 =  $sh.CreateShortcut($b)
return $targetPath1.TargetPath



}
$targetshortcut1=targetshortcut 
$targetshortcut1

function executeasadmninsage {
param (
$pathcoalaclient
)
Start-Process -FilePath  $pathcoalaclient -Verb RunAs -PassThru


}

$executeasadmninsage1=executeasadmninsage  $targetshortcut1
$executeasadmninsage1

最新更新