Skip to content

New-Service Should Throw on System StartupType #4803

@markekraus

Description

@markekraus

Note: The test case @{name = 'badstarttype'; parameter = "StartupType"; value = "System"} from test\powershell\Modules\Microsoft.PowerShell.Management\Set-Service.Tests.ps1 failed in daily test run due to this issue, so it's disabled for now. Please re-enable the test when fixing this issue.

Steps to reproduce

New-Service -StartupType System -Name badstarttype -BinaryPathName "$PSHOME\powershell.exe" -ErrorAction Stop

Expected behavior

Should throw

CouldNotNewService,Microsoft.PowerShell.Commands.NewServiceCommand

Actual behavior

Creates Service when run on release build

Name                : badstarttype
RequiredServices    :
CanPauseAndContinue : False
CanShutdown         : False
CanStop             : False
DisplayName         : badstarttype
DependentServices   : {}
MachineName         : .
ServiceName         : badstarttype
ServicesDependedOn  :
StartType           :
ServiceHandle       : Microsoft.Win32.SafeHandles.SafeServiceHandle
Status              : Stopped
ServiceType         : Win32OwnProcess

Fails Fast on debug build:

FailFast: bad StartupType

   at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
   at System.Management.Automation.Diagnostics.Assert(Boolean condition, String whyThisShouldNeverHappen, String detailMessage) in C:\github\PowerShell\src\System.Management.Automation\utils\assert.cs:line 196
   at System.Management.Automation.Diagnostics.Assert(Boolean condition, String whyThisShouldNeverHappen) in C:\github\PowerShell\src\System.Management.Automation\utils\assert.cs:line 131
   at Microsoft.PowerShell.Commands.NewServiceCommand.BeginProcessing() in C:\github\PowerShell\src\Microsoft.PowerShell.Commands.Management\commands\management\Service.cs:line 2018
   at System.Management.Automation.Cmdlet.DoBeginProcessing() in C:\github\PowerShell\src\System.Management.Automation\engine\cmdlet.cs:line 164
   at System.Management.Automation.CommandProcessorBase.DoBegin() in C:\github\PowerShell\src\System.Management.Automation\engine\CommandProcessorBase.cs:line 500
   at System.Management.Automation.CommandProcessor.DoBegin() in C:\github\PowerShell\src\System.Management.Automation\engine\CommandProcessor.cs:line 272
   at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream) in C:\github\PowerShell\src\System.Management.Automation\engine\pipeline.cs:line 1050
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input) in C:\github\PowerShell\src\System.Management.Automation\engine\pipeline.cs:line 489
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext) in C:\github\PowerShell\src\System.Management.Automation\engine\runtime\Operations\MiscOps.cs:line 455
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame) in C:\github\PowerShell\src\System.Management.Automation\engine\interpreter\CallInstruction.Generated.cs:line 569
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in C:\github\PowerShell\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 356
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in C:\github\PowerShell\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 356
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) in C:\github\PowerShell\src\System.Management.Automation\engine\interpreter\Interpreter.cs:line 111
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) in C:\github\PowerShell\src\System.Management.Automation\engine\interpreter\LightLambda.Generated.cs:line 78
   at System.Management.Automation.DlrScriptCommandProcessor.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess) in C:\github\PowerShell\src\System.Management.Automation\engine\ScriptCommandProcessor.cs:line 516
   at System.Management.Automation.DlrScriptCommandProcessor.Complete() in C:\github\PowerShell\src\System.Management.Automation\engine\ScriptCommandProcessor.cs:line 417
   at System.Management.Automation.CommandProcessorBase.DoComplete() in C:\github\PowerShell\src\System.Management.Automation\engine\CommandProcessorBase.cs:line 614
   at System.Management.Automation.Internal.PipelineProcessor.DoCompleteCore(CommandProcessorBase commandRequestingUpstreamCommandsToStop) in C:\github\PowerShell\src\System.Management.Automation\engine\pipeline.cs:line 607
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input) in C:\github\PowerShell\src\System.Management.Automation\engine\pipeline.cs:line 519
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper() in C:\github\PowerShell\src\System.Management.Automation\engine\hostifaces\LocalPipeline.cs:line 426
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc() in C:\github\PowerShell\src\System.Management.Automation\engine\hostifaces\LocalPipeline.cs:line 622
   at System.Threading.Thread.ThreadMain_ThreadStart()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Environment.FailFast(System.String, System.Exception)
   at System.Management.Automation.Diagnostics.Assert(Boolean, System.String, System.String)
   at System.Management.Automation.Diagnostics.Assert(Boolean, System.String)
   at Microsoft.PowerShell.Commands.NewServiceCommand.BeginProcessing()
   at System.Management.Automation.Cmdlet.DoBeginProcessing()
   at System.Management.Automation.CommandProcessorBase.DoBegin()
   at System.Management.Automation.CommandProcessor.DoBegin()
   at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(System.Object)
   at System.Management.Automation.PipelineOps.InvokePipeline(System.Object, Boolean, System.Management.Automation.CommandParameterInternal[][], System.Management.Automation.Language.CommandBaseAst[], System.Management.Automation.CommandRedirection[][], System.Management.Automation.Language.FunctionContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.Interpreter.Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon)
   at System.Management.Automation.DlrScriptCommandProcessor.RunClause(System.Action`1<System.Management.Automation.Language.FunctionContext>, System.Object, System.Object)
   at System.Management.Automation.DlrScriptCommandProcessor.Complete()
   at System.Management.Automation.CommandProcessorBase.DoComplete()
   at System.Management.Automation.Internal.PipelineProcessor.DoCompleteCore(System.Management.Automation.CommandProcessorBase)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(System.Object)
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
   at System.Threading.Thread.ThreadMain_ThreadStart()
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)

Environment data

Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
GitCommitId                    v6.0.0-beta.6-43-g2761c3ff210caf7a9c18968c03c18c6921046251
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Ref #4785 (comment)

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions