rgdelank
New Member
- Joined
- Jun 17, 2023
- Messages
- 5
- Thread Author
- #1
Windows 11: I receive "access denied" by calling "Pin At Start" from the command line, no mather wich language PowerShell or VBscript.
Both are called using administrator rights.
PowerShell
==========
Error
=====
PS C:\Users\roberto> .\t.ps1
Pin-App : App(s) not found: C:\Program Files\Notepad++\notepad++.exe
In C:\Users\roberto\t.ps1:32 Zeichen:1
+ Pin-App ("C:\Program Files\Notepad++\notepad++.exe")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified:
) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Pin-App
Script
=======
function Pin-App {
param(
[parameter(mandatory=$true)][ValidateNotNullOrEmpty()][string[]]$appname,
[switch]$unpin
)
$actionstring = @{$true='Von "Start" lösen|Unpin from Start';$false='An "Start" anheften|Pin to Start'}[$unpin.IsPresent]
$action = @{$true='unpinned from';$false='pinned to'}[$unpin.IsPresent]
$apps = (New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -in $appname}
if($apps){
$notfound = compare $appname $apps.Name -PassThru
if ($notfound){write-error "These App(s) were not found: $($notfound -join ",")"}
foreach ($app in $apps){
$appaction = $app.Verbs() | ?{$_.Name.replace('&','') -match $actionstring}
if ($appaction){
$appaction | %{$_.DoIt(); return "App '$($app.Name)' $action Start"}
}else{
write-error "App '$($app.Name)' is already pinned/unpinned to/from start or action not supported."
}
}
}else{
write-error "App(s) not found: $($appname -join ",")"
}
}
Pin-App ("C:\Program Files\Notepad++\notepad++.exe")
VBSCRIPT
========
Error
=====
C:\Users\Roberto>cscript.exe t.vbs
Microsoft (R) Windows Script Host, Version 5.812
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
C:\Users\Roberto\t.vbs(37, 69) Laufzeitfehler in Microsoft VBScript: Erlaubnis verweigert.
Script
======
Option Explicit
'On Error resume next
Dim oSh, oFs, oShApp
Set oSh = CreateObject("Wscript.Shell")
Set oFs = CreateObject("Scripting.FileSystemObject")
Set oShApp = CreateObject("Shell.Application")
AmStartAnheften "C:\Program Files\Notepad++\Notepad++.exe"
Wscript.quit
Function AmStartAnheften(sProgramm)
Dim cVerbs, itemVerb, sFolder, oFolder, sFile, oFile, bAnheften
If oFs.FileExists(sProgramm) Then
'***** Do nothing, folder exists
Else
'***** Folder does not exist
bAnheften = False
WScript.Echo "File zum Anheften: " & sProgramm & " existiert nicht!!!"
WScript.Echo "Prüfen Sie die existenz der file."
Exit Function
End If
sFolder = oFs.GetParentFolderName(sProgramm)
sFile = oFs.GetFileName(sProgramm)
Err.Clear
Set oFolder = oShApp.Namespace(sFolder)
Set oFile = oFolder.ParseName(sFile)
Set cVerbs = oFile.Verbs
Err.Clear
For each itemVerb in oFile.verbs
' Verbs: PinToStartmenu, DeleteFromStartmenu, PinToTaskbar, DeleteFromTaskBar
If Replace(itemVerb.name, "&", "") = "An ""Start"" anheften" Then itemVerb.DoIt
If Err.Number <> 0 Then Wscript.Echo Err.Description & " Error."
Next
End Function
Both are called using administrator rights.
PowerShell
==========
Error
=====
PS C:\Users\roberto> .\t.ps1
Pin-App : App(s) not found: C:\Program Files\Notepad++\notepad++.exe
In C:\Users\roberto\t.ps1:32 Zeichen:1
+ Pin-App ("C:\Program Files\Notepad++\notepad++.exe")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified:

+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Pin-App
Script
=======
function Pin-App {
param(
[parameter(mandatory=$true)][ValidateNotNullOrEmpty()][string[]]$appname,
[switch]$unpin
)
$actionstring = @{$true='Von "Start" lösen|Unpin from Start';$false='An "Start" anheften|Pin to Start'}[$unpin.IsPresent]
$action = @{$true='unpinned from';$false='pinned to'}[$unpin.IsPresent]
$apps = (New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -in $appname}
if($apps){
$notfound = compare $appname $apps.Name -PassThru
if ($notfound){write-error "These App(s) were not found: $($notfound -join ",")"}
foreach ($app in $apps){
$appaction = $app.Verbs() | ?{$_.Name.replace('&','') -match $actionstring}
if ($appaction){
$appaction | %{$_.DoIt(); return "App '$($app.Name)' $action Start"}
}else{
write-error "App '$($app.Name)' is already pinned/unpinned to/from start or action not supported."
}
}
}else{
write-error "App(s) not found: $($appname -join ",")"
}
}
Pin-App ("C:\Program Files\Notepad++\notepad++.exe")
VBSCRIPT
========
Error
=====
C:\Users\Roberto>cscript.exe t.vbs
Microsoft (R) Windows Script Host, Version 5.812
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
C:\Users\Roberto\t.vbs(37, 69) Laufzeitfehler in Microsoft VBScript: Erlaubnis verweigert.
Script
======
Option Explicit
'On Error resume next
Dim oSh, oFs, oShApp
Set oSh = CreateObject("Wscript.Shell")
Set oFs = CreateObject("Scripting.FileSystemObject")
Set oShApp = CreateObject("Shell.Application")
AmStartAnheften "C:\Program Files\Notepad++\Notepad++.exe"
Wscript.quit
Function AmStartAnheften(sProgramm)
Dim cVerbs, itemVerb, sFolder, oFolder, sFile, oFile, bAnheften
If oFs.FileExists(sProgramm) Then
'***** Do nothing, folder exists
Else
'***** Folder does not exist
bAnheften = False
WScript.Echo "File zum Anheften: " & sProgramm & " existiert nicht!!!"
WScript.Echo "Prüfen Sie die existenz der file."
Exit Function
End If
sFolder = oFs.GetParentFolderName(sProgramm)
sFile = oFs.GetFileName(sProgramm)
Err.Clear
Set oFolder = oShApp.Namespace(sFolder)
Set oFile = oFolder.ParseName(sFile)
Set cVerbs = oFile.Verbs
Err.Clear
For each itemVerb in oFile.verbs
' Verbs: PinToStartmenu, DeleteFromStartmenu, PinToTaskbar, DeleteFromTaskBar
If Replace(itemVerb.name, "&", "") = "An ""Start"" anheften" Then itemVerb.DoIt
If Err.Number <> 0 Then Wscript.Echo Err.Description & " Error."
Next
End Function