@@ -36,96 +36,108 @@ public override bool CanRunOnPlatform()
3636 /// </summary>
3737 public void ExecuteWindows ( )
3838 {
39- var fsc = new FileSystemCollector ( new CollectCommandOptions ( ) { SingleThread = opts . SingleThread } ) ;
40- System . Management . SelectQuery sQuery = new System . Management . SelectQuery ( "select * from Win32_Service" ) ; // where name = '{0}'", "MCShield.exe"));
41- using System . Management . ManagementObjectSearcher mgmtSearcher = new System . Management . ManagementObjectSearcher ( sQuery ) ;
42- foreach ( System . Management . ManagementObject service in mgmtSearcher . Get ( ) )
39+ try
4340 {
44- try
41+ System . Management . SelectQuery sQuery = new System . Management . SelectQuery ( "select * from Win32_Service" ) ; // where name = '{0}'", "MCShield.exe"));
42+ using System . Management . ManagementObjectSearcher mgmtSearcher = new System . Management . ManagementObjectSearcher ( sQuery ) ;
43+ foreach ( System . Management . ManagementObject service in mgmtSearcher . Get ( ) )
4544 {
46- var val = service . GetPropertyValue ( "Name" ) . ToString ( ) ;
47- if ( val != null )
45+ try
4846 {
49- var obj = new ServiceObject ( val ) ;
47+ var val = service . GetPropertyValue ( "Name" ) . ToString ( ) ;
48+ if ( val != null )
49+ {
50+ var obj = new ServiceObject ( val ) ;
5051
51- val = service . GetPropertyValue ( "AcceptPause" ) ? . ToString ( ) ;
52- if ( ! string . IsNullOrEmpty ( val ) )
53- obj . AcceptPause = bool . Parse ( val ) ;
52+ val = service . GetPropertyValue ( "AcceptPause" ) ? . ToString ( ) ;
53+ if ( ! string . IsNullOrEmpty ( val ) )
54+ obj . AcceptPause = bool . Parse ( val ) ;
5455
55- val = service . GetPropertyValue ( "AcceptStop" ) ? . ToString ( ) ;
56- if ( ! string . IsNullOrEmpty ( val ) )
57- obj . AcceptStop = bool . Parse ( val ) ;
56+ val = service . GetPropertyValue ( "AcceptStop" ) ? . ToString ( ) ;
57+ if ( ! string . IsNullOrEmpty ( val ) )
58+ obj . AcceptStop = bool . Parse ( val ) ;
5859
59- obj . Caption = service . GetPropertyValue ( "Caption" ) ? . ToString ( ) ;
60+ obj . Caption = service . GetPropertyValue ( "Caption" ) ? . ToString ( ) ;
6061
61- val = service . GetPropertyValue ( "CheckPoint" ) ? . ToString ( ) ;
62- if ( ! string . IsNullOrEmpty ( val ) )
63- obj . CheckPoint = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
62+ val = service . GetPropertyValue ( "CheckPoint" ) ? . ToString ( ) ;
63+ if ( ! string . IsNullOrEmpty ( val ) )
64+ obj . CheckPoint = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
6465
65- obj . CreationClassName = service . GetPropertyValue ( "CreationClassName" ) ? . ToString ( ) ;
66+ obj . CreationClassName = service . GetPropertyValue ( "CreationClassName" ) ? . ToString ( ) ;
6667
67- val = service . GetPropertyValue ( "DelayedAutoStart" ) ? . ToString ( ) ;
68- if ( ! string . IsNullOrEmpty ( val ) )
69- obj . DelayedAutoStart = bool . Parse ( val ) ;
68+ val = service . GetPropertyValue ( "DelayedAutoStart" ) ? . ToString ( ) ;
69+ if ( ! string . IsNullOrEmpty ( val ) )
70+ obj . DelayedAutoStart = bool . Parse ( val ) ;
7071
71- obj . Description = service . GetPropertyValue ( "Description" ) ? . ToString ( ) ;
72+ obj . Description = service . GetPropertyValue ( "Description" ) ? . ToString ( ) ;
7273
73- val = service . GetPropertyValue ( "DesktopInteract" ) ? . ToString ( ) ;
74- if ( ! string . IsNullOrEmpty ( val ) )
75- obj . DesktopInteract = bool . Parse ( val ) ;
74+ val = service . GetPropertyValue ( "DesktopInteract" ) ? . ToString ( ) ;
75+ if ( ! string . IsNullOrEmpty ( val ) )
76+ obj . DesktopInteract = bool . Parse ( val ) ;
7677
77- obj . DisplayName = service . GetPropertyValue ( "DisplayName" ) ? . ToString ( ) ;
78- obj . ErrorControl = service . GetPropertyValue ( "ErrorControl" ) ? . ToString ( ) ;
78+ obj . DisplayName = service . GetPropertyValue ( "DisplayName" ) ? . ToString ( ) ;
79+ obj . ErrorControl = service . GetPropertyValue ( "ErrorControl" ) ? . ToString ( ) ;
7980
80- val = service . GetPropertyValue ( "ExitCode" ) ? . ToString ( ) ;
81- if ( ! string . IsNullOrEmpty ( val ) )
82- obj . ExitCode = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
81+ val = service . GetPropertyValue ( "ExitCode" ) ? . ToString ( ) ;
82+ if ( ! string . IsNullOrEmpty ( val ) )
83+ obj . ExitCode = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
8384
84- if ( DateTime . TryParse ( service . GetPropertyValue ( "InstallDate" ) ? . ToString ( ) , out DateTime dateTime ) )
85- {
86- obj . InstallDate = dateTime ;
87- }
88- obj . PathName = service . GetPropertyValue ( "PathName" ) ? . ToString ( ) ;
85+ if ( DateTime . TryParse ( service . GetPropertyValue ( "InstallDate" ) ? . ToString ( ) , out DateTime dateTime ) )
86+ {
87+ obj . InstallDate = dateTime ;
88+ }
89+ obj . PathName = service . GetPropertyValue ( "PathName" ) ? . ToString ( ) ;
8990
90- val = service . GetPropertyValue ( "ProcessId" ) ? . ToString ( ) ;
91- if ( ! string . IsNullOrEmpty ( val ) )
92- obj . ProcessId = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
91+ val = service . GetPropertyValue ( "ProcessId" ) ? . ToString ( ) ;
92+ if ( ! string . IsNullOrEmpty ( val ) )
93+ obj . ProcessId = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
9394
94- val = service . GetPropertyValue ( "ServiceSpecificExitCode" ) ? . ToString ( ) ;
95- if ( ! string . IsNullOrEmpty ( val ) )
96- obj . ServiceSpecificExitCode = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
95+ val = service . GetPropertyValue ( "ServiceSpecificExitCode" ) ? . ToString ( ) ;
96+ if ( ! string . IsNullOrEmpty ( val ) )
97+ obj . ServiceSpecificExitCode = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
9798
98- obj . ServiceType = service . GetPropertyValue ( "ServiceType" ) ? . ToString ( ) ;
99+ obj . ServiceType = service . GetPropertyValue ( "ServiceType" ) ? . ToString ( ) ;
99100
100- val = service . GetPropertyValue ( "Started" ) . ToString ( ) ;
101- if ( ! string . IsNullOrEmpty ( val ) )
102- obj . Started = bool . Parse ( val ) ;
101+ val = service . GetPropertyValue ( "Started" ) . ToString ( ) ;
102+ if ( ! string . IsNullOrEmpty ( val ) )
103+ obj . Started = bool . Parse ( val ) ;
103104
104- obj . StartMode = service . GetPropertyValue ( "StartMode" ) ? . ToString ( ) ;
105- obj . StartName = service . GetPropertyValue ( "StartName" ) ? . ToString ( ) ;
106- obj . State = service . GetPropertyValue ( "State" ) ? . ToString ( ) ;
107- obj . Status = service . GetPropertyValue ( "Status" ) ? . ToString ( ) ;
108- obj . SystemCreationClassName = service . GetPropertyValue ( "SystemCreationClassName" ) ? . ToString ( ) ;
109- obj . SystemName = service . GetPropertyValue ( "SystemName" ) ? . ToString ( ) ;
105+ obj . StartMode = service . GetPropertyValue ( "StartMode" ) ? . ToString ( ) ;
106+ obj . StartName = service . GetPropertyValue ( "StartName" ) ? . ToString ( ) ;
107+ obj . State = service . GetPropertyValue ( "State" ) ? . ToString ( ) ;
108+ obj . Status = service . GetPropertyValue ( "Status" ) ? . ToString ( ) ;
109+ obj . SystemCreationClassName = service . GetPropertyValue ( "SystemCreationClassName" ) ? . ToString ( ) ;
110+ obj . SystemName = service . GetPropertyValue ( "SystemName" ) ? . ToString ( ) ;
110111
111- val = service . GetPropertyValue ( "TagId" ) ? . ToString ( ) ;
112- if ( ! string . IsNullOrEmpty ( val ) )
113- obj . TagId = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
112+ val = service . GetPropertyValue ( "TagId" ) ? . ToString ( ) ;
113+ if ( ! string . IsNullOrEmpty ( val ) )
114+ obj . TagId = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
114115
115- val = service . GetPropertyValue ( "WaitHint" ) ? . ToString ( ) ;
116- if ( ! string . IsNullOrEmpty ( val ) )
117- obj . WaitHint = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
116+ val = service . GetPropertyValue ( "WaitHint" ) ? . ToString ( ) ;
117+ if ( ! string . IsNullOrEmpty ( val ) )
118+ obj . WaitHint = uint . Parse ( val , CultureInfo . InvariantCulture ) ;
118119
119- Results . Push ( obj ) ;
120+ Results . Push ( obj ) ;
121+ }
122+ }
123+ catch ( Exception e ) when (
124+ e is TypeInitializationException ||
125+ e is PlatformNotSupportedException )
126+ {
127+ Log . Warning ( Strings . Get ( "CollectorNotSupportedOnPlatform" ) , GetType ( ) . ToString ( ) ) ;
128+ }
129+ catch ( Exception e )
130+ {
131+ Log . Warning ( e , "Failed to grok Service Collector object at {0}." , service . Path ) ;
120132 }
121- }
122- catch ( Exception e ) when (
123- e is TypeInitializationException ||
124- e is PlatformNotSupportedException )
125- {
126- Log . Warning ( Strings . Get ( "CollectorNotSupportedOnPlatform" ) , GetType ( ) . ToString ( ) ) ;
127133 }
128134 }
135+ catch ( Exception e )
136+ {
137+ Log . Warning ( e , "Failed to run Service Collector." ) ;
138+ }
139+
140+ var fsc = new FileSystemCollector ( new CollectCommandOptions ( ) { SingleThread = opts . SingleThread } ) ;
129141
130142 foreach ( var file in Directory . EnumerateFiles ( "C:\\ ProgramData\\ Microsoft\\ Windows\\ Start Menu\\ Programs\\ Startup" ) )
131143 {
0 commit comments