Skip to content

Commit 8493fff

Browse files
committed
Update Collectors.cs
1 parent 6cf0f5e commit 8493fff

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

SQLCheck/SQLCheck/Collectors.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,20 @@ public static void CollectService(DataSet ds) // collects select services we ar
21902190
ManagementObjectSearcher searcher = null;
21912191

21922192
DataRow Computer = ds.Tables["Computer"].Rows[0];
2193-
DataRow Domain = ds.Tables["Domain"].Rows[0];
2193+
2194+
////////////////////// clintonw
2195+
DataRow Domain = null;
2196+
2197+
// if (Computer.GetBoolean("JoinedToDomain") == false) { } // bug : not in domain
2198+
if (ds.Tables["Domain"].Rows.Count > 0)
2199+
{
2200+
Domain = ds.Tables["Domain"].Rows[0]; // crash if not in domain
2201+
}
2202+
2203+
2204+
//////////////////// clintonw
2205+
2206+
21942207
DataRow Service = null;
21952208

21962209
//
@@ -2234,7 +2247,13 @@ public static void CollectService(DataSet ds) // collects select services we ar
22342247
// better method of converting
22352248
// Service["DomainAccount"] = Utility.TranslateServiceAccount(Service["ServiceAccount"].ToString(), Computer["NETBIOSName"].ToString());
22362249
string NTAccountName = Utility.NormalizeNTAccount(Service["ServiceAccount"].ToString(), "");
2237-
Service["DomainAccount"] = Utility.ConvertLocalAccountToDomainAccount(NTAccountName, Computer.GetString("NETBIOSName"), Domain.GetString("DomainShortName"));
2250+
2251+
// Handle computer not joined to the domain; Domain datatable will be null : bug clintonw
2252+
Service["DomainAccount"] = NTAccountName;
2253+
if (Domain != null)
2254+
{
2255+
Service["DomainAccount"] = Utility.ConvertLocalAccountToDomainAccount(NTAccountName, Computer.GetString("NETBIOSName"), Domain.GetString("DomainShortName"));
2256+
}
22382257

22392258
string startMode = mo.GetPropertyValue("StartMode").ToString();
22402259
Service["StartMode"] = startMode;
@@ -2298,7 +2317,13 @@ public static void CollectService(DataSet ds) // collects select services we ar
22982317
// better method of converting
22992318
// Service["DomainAccount"] = Utility.TranslateServiceAccount(Service["ServiceAccount"].ToString(), Computer["NETBIOSName"].ToString());
23002319
string NTAccountName = Utility.NormalizeNTAccount(Service["ServiceAccount"].ToString(), "");
2301-
Service["DomainAccount"] = Utility.ConvertLocalAccountToDomainAccount(NTAccountName, Computer.GetString("NETBIOSName"), Domain.GetString("DomainShortName"));
2320+
2321+
// Handle computer not joined to the domain; Domain datatable will be null : bug clintonw
2322+
Service["DomainAccount"] = NTAccountName;
2323+
if (Domain != null)
2324+
{
2325+
Service["DomainAccount"] = Utility.ConvertLocalAccountToDomainAccount(NTAccountName, Computer.GetString("NETBIOSName"), Domain.GetString("DomainShortName"));
2326+
}
23022327

23032328
Service["StartMode"] = "Manual";
23042329
Service["Started"] = true; // boolean

0 commit comments

Comments
 (0)