question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PWSH 7.2.1: Set-Service: Service * cannot be configured due to the following error: Access is denied.

See original GitHub issue

Prerequisites

Steps to reproduce

Open PWSH as Adminstrator via Start > PowerShell > PowerShell 7 (x64) > Run as Administrator and run the below command. In Windows PowerShell 5.1.x it works fine. Hence, seems a regression. I haven’t tried the command in any prior PWSH version. Also, SCPolicySvc is not the only service set-service fails to set with the same error message. However, it doesn’t fail to set all services, just certain ones.

Expected behavior

PS C:\WINDOWS\system32> set-service -name SCPolicySvc -startuptype disabled ; stop-service -name SCPolicySvc -force
PS C:\WINDOWS\system32>

Actual behavior

PS C:\Windows\System32> set-service -name SCPolicySvc -startuptype disabled ; stop-service -name SCPolicySvc -force
Set-Service: Service 'Smart Card Removal Policy (SCPolicySvc)' cannot be configured due to the following error: Access is denied.
PS C:\Windows\System32>

Error details

get-error

Exception             :
    Type           :
Microsoft.PowerShell.Commands.ServiceCommandException
    ServiceName    : SCPolicySvc
    Message        : Service 'Smart Card Removal Policy
(SCPolicySvc)' cannot be configured due to the following error:
Access is denied.
    InnerException :
        Type            : System.ComponentModel.Win32Exception
        NativeErrorCode : 5
        ErrorCode       : -2147467259
        Message         : Access is denied.
        HResult         : -2147467259
    HResult        : -2146233087
TargetObject          : System.ServiceProcess.ServiceController
CategoryInfo          : PermissionDenied:
(System.ServiceProcess.ServiceController:ServiceController)
[Set-Service], ServiceCommandException
FullyQualifiedErrorId : CouldNotSetService,Microsoft.PowerSh
ell.Commands.SetServiceCommand
InvocationInfo        :
    MyCommand        : Set-Service
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 359
    Line             : set-service -name SCPolicySvc
-startuptype disabled ; stop-service -name SCPolicySvc -force
    PositionMessage  : At line:1 char:1
                       + set-service -name SCPolicySvc
-startuptype disabled ; stop-service -n …
                       +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : set-service
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :




PS C:\Windows\System32>

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS C:\Windows\System32>

Visuals

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
kvprasooncommented, Dec 20, 2021

@iSazonov , on it. Thanks for the mention 😀.

2reactions
iSazonovcommented, Dec 20, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to Start or Configure Windows Security Service on ...
Set-Service : Service 'Security Center (wscsvc)' cannot be configured due to the following error: Access is denied. At line:1 char:1.
Read more >
Powershell New-Service gives permission denied
1 Answer. This is because you are running myService function in the current powershell instance and not in the new one you are...
Read more >
Set-Service for remote machine failing. Access is denied.
Set-Service : Service 'Antivirus (AntivirusSvc)' cannot be configured due to the following error: Access is denied At line:1 char:52.
Read more >
How to fix "Access is denied" error when using Windows ...
Find the Service that you want to modify · Open the Start menu and look for Command Prompt · Click Run as Administrator....
Read more >
Untitled
Lxssmanager service access denied The LxssManager server really is Windows ... New issue PWSH 7.2.1: Set-Service: Service * cannot be configured due to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found