mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add verbose message to Get-Service when properties cannot be returned (#27109)
This commit is contained in:
@@ -674,13 +674,30 @@ namespace Microsoft.PowerShell.Commands
|
||||
#endregion Overrides
|
||||
|
||||
#nullable enable
|
||||
|
||||
/// <summary>
|
||||
/// Writes a verbose message when a service property query fails.
|
||||
/// </summary>
|
||||
/// <param name="serviceName">Name of the service.</param>
|
||||
/// <param name="propertyName">Name of the property that failed to be queried.</param>
|
||||
private void WriteServicePropertyError(string serviceName, string propertyName)
|
||||
{
|
||||
Win32Exception e = new(Marshal.GetLastWin32Error());
|
||||
WriteVerbose(
|
||||
StringUtil.Format(
|
||||
ServiceResources.CouldNotGetServiceProperty,
|
||||
serviceName,
|
||||
propertyName,
|
||||
e.Message));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds UserName, Description, BinaryPathName, DelayedAutoStart and StartupType to a ServiceController object.
|
||||
/// </summary>
|
||||
/// <param name="scManagerHandle">Handle to the local SCManager instance.</param>
|
||||
/// <param name="service"></param>
|
||||
/// <returns>ServiceController as PSObject with UserName, Description and StartupType added.</returns>
|
||||
private static PSObject AddProperties(nint scManagerHandle, ServiceController service)
|
||||
private PSObject AddProperties(nint scManagerHandle, ServiceController service)
|
||||
{
|
||||
NakedWin32Handle hService = nint.Zero;
|
||||
|
||||
@@ -709,6 +726,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
description = descriptionInfo.lpDescription;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteServicePropertyError(service.ServiceName, nameof(NativeMethods.SERVICE_DESCRIPTIONW));
|
||||
}
|
||||
|
||||
if (NativeMethods.QueryServiceConfig2(
|
||||
hService,
|
||||
@@ -717,6 +738,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
isDelayedAutoStart = autostartInfo.fDelayedAutostart;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteServicePropertyError(service.ServiceName, nameof(NativeMethods.SERVICE_DELAYED_AUTO_START_INFO));
|
||||
}
|
||||
|
||||
if (NativeMethods.QueryServiceConfig(
|
||||
hService,
|
||||
@@ -731,6 +756,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
isDelayedAutoStart.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteServicePropertyError(service.ServiceName, nameof(NativeMethods.QUERY_SERVICE_CONFIG));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// handle when OpenServiceW itself fails:
|
||||
WriteServicePropertyError(service.ServiceName, nameof(NativeMethods.SERVICE_QUERY_CONFIG));
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
@@ -26,36 +26,36 @@
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
@@ -213,4 +213,7 @@
|
||||
<data name="UnsupportedStartupType" xml:space="preserve">
|
||||
<value>The startup type '{0}' is not supported by {1}.</value>
|
||||
</data>
|
||||
<data name="CouldNotGetServiceProperty" xml:space="preserve">
|
||||
<value>Could not retrieve property '{1}' for service '{0}': {2}</value>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
Reference in New Issue
Block a user