I have an error that I cannot solve, not even searching the internet.
My code:
public static void GetClasses(ref List<ListViewItem> items)
{
ManagementPath path = new ManagementPath(string.Format("\\\\{0}\\ROOT\\CIMV2", SystemInformation.ComputerName.ToUpperInvariant()));
ConnectionOptions options = new ConnectionOptions
{
EnablePrivileges = true,
Impersonation = ImpersonationLevel.Impersonate,
Authentication = AuthenticationLevel.Default,
Username = null,
SecurePassword = null
};
ManagementScope managementScope = new ManagementScope(path, options);
managementScope.Connect();
ObjectGetOptions options2 = new ObjectGetOptions();
new ManagementScope(new ManagementObject(managementScope, path, options2).Path, options);
ObjectQuery query = new ObjectQuery("SELECT * FROM meta_class WHERE __Class LIKE \"%%%\" AND NOT __Class LIKE \"[_][_]%\" AND NOT __Class LIKE \"Win32_Perf%\" AND NOT __Class LIKE \"MSFT[_]%\"");
EnumerationOptions options3 = new EnumerationOptions
{
EnumerateDeep = true,
UseAmendedQualifiers = true
};
ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(managementScope, query, options3);
new List<WMIClass>();
foreach (ManagementClass managementClass in from ManagementClass currentClass in managementObjectSearcher.Get()
orderby currentClass.ClassPath.ClassName
select currentClass)
{
bool flag = false;
// using (ManagementObjectCollection.ManagementObjectEnumerator enumerator2 = disks.GetEnumerator())
using (PropertyDataCollection.PropertyDataEnumerator enumerator2 = ManagementClass.Properties.GetEnumerator())
{
while (enumerator2.MoveNext())
{
if (enumerator2.Current.Type == CimType.String)
{
flag = true;
}
}
}
if (flag)
{
WMIClass wmiclass = new WMIClass(managementClass);
ListViewItem listViewItem = new ListViewItem
{
Name = wmiclass.DisplayName,
Text = wmiclass.DisplayName,
ToolTipText = wmiclass.Description,
Tag = wmiclass
};
listViewItem.SubItems.Add(wmiclass.Description);
items.Add(listViewItem);
}
}
}
Error line:
using (PropertyDataCollection.PropertyDataEnumerator enumerator2 = ManagementClass.Properties.GetEnumerator())
// using (ManagementObjectCollection.ManagementObjectEnumerator enumerator2 = disks.GetEnumerator())
I don't know what the mistake is. If you can help me please I don't understand the language very well.
I would greatly appreciate your help.
Try changing
using (PropertyDataCollection.PropertyDataEnumerator enumerator2 = ManagementClass.Properties.GetEnumerator())
{
while (enumerator2.MoveNext())
{
if (enumerator2.Current.Type == CimType.String)
{
flag = true;
}
}
}
to
PropertyDataCollection.PropertyDataEnumerator enumerator2 = managementClass.Properties.GetEnumerator();
while (enumerator2.MoveNext())
{
if (enumerator2.Current.Type == CimType.String)
{
flag = true;
}
}
First, "using" must be removed because GetEnumerator() does not return a disposable object and second, use "managementClass.Properties.GetEnumerator()" instead of "ManagementClass.Properties.GetEnumerator()".
I am not able to add or update milestones field for the Features in the Rally. If anyone having the code available using C# to update the same, please share with me. I am searching and doing from last one week with no luck.
When I am trying to add/Update milestones in the Features. I am getting the error as "Could not read: Could not read referenced object null". My code is as follows:-
public DynamicJsonObject UpdateFeaturesbyName(string fea, string bFun)
{
//getting list of Feature.
Request feat = new Request("PortfolioItem/Feature");
feat.Query = new Query("Name", Query.Operator.Equals, fea);
QueryResult TCSResults = restApi.Query(feat);
foreach (var res in TCSResults.Results)
{
var steps = res["Milestones"];
Request tsteps = new Request(steps);
QueryResult tstepsResults = restApi.Query(tsteps);
foreach (var item in tstepsResults.Results)
{
}
if (res.Name == fea)
{
var targetFeature = TCSResults.Results.FirstOrDefault();
DynamicJsonObject toUpdate = new DynamicJsonObject();
//toUpdate["Milestones"] = "";
// CreateResult createResult = restApi.Create(steps._ref, toUpdate);
// String contentRef = steps._ref;
//String contentRef = createResult._ref;
string[] value = null;
string AccCri = string.Empty;
if (!string.IsNullOrWhiteSpace(bFun))
{
value = bFun.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
foreach (string item in value)
{
//if (string.IsNullOrWhiteSpace(AccCri))
// AccCri = item;
//else
// AccCri = AccCri + "<br/>" + item;
if (!string.IsNullOrWhiteSpace(item))
{
//Query for Milestone.
Request ms = new Request("Milestone");
ms.Fetch = new List<string>() { "Name", "ObjectID" };
ms.Query = new Query("Name", Query.Operator.Equals, item);
QueryResult msResults = restApi.Query(ms);
var targetMLResult = msResults.Results.FirstOrDefault();
long MLOID = targetMLResult["ObjectID"];
DynamicJsonObject tarML = restApi.GetByReference("Milestone", MLOID, "Name", "_ref", "DisplayColor");
DynamicJsonObject targetML = new DynamicJsonObject();
targetML["Name"] = tarML["Name"];
//targetML["_ref"] = tarML["_ref"];
targetML["_ref"] = "/milestone/" + Convert.ToString(MLOID);
targetML["DisplayColor"] = tarML["DisplayColor"];
// Grab collection of existing Milestones.
var existingMilestones = targetFeature["Milestones"];
long targetOID = targetFeature["ObjectID"];
// Milestones collection on object is expected to be a System.Collections.ArrayList.
var targetMLArray = existingMilestones;
var tagList2 = targetMLArray["_tagsNameArray"];
tagList2.Add(targetML);//
//targetMLArray.Add(targetML);
targetMLArray["_tagsNameArray"] = tagList2;
toUpdate["Milestones"] = targetMLArray;
OperationResult updateResult = restApi.Update(res._ref, toUpdate);
bool resp = updateResult.Success;
}
}
}
//toUpdate["c_AcceptanceCriteria"] = AccCri;
//OperationResult updateResult = restApi.Update(res._ref, toUpdate);
}
}
var features = TCSResults.Results.Where(p => p.Name == fea).FirstOrDefault();
var featuresref = features._ref;
return features;
}
Now that v3.1.1 of the toolkit has been released you can use the AddToCollection method to do this.
Otherwise, you can still always just update the full collection. The value should be an arraylist of objects with _ref properties.
Check out this example (which adds tasks to defects, but should be very similar to what you're doing): https://github.com/RallyCommunity/rally-dot-net-rest-apps/blob/master/UpdateTaskCollectionOnDefect/addTaskOnDefect.cs
i have copied the code , i have a variable ("Modifiedtime_1.Modifiedtime") i want to change system time with the datetime available in (Modifiedtime_1.Modifiedtime) whenever
if (compare == 0 || compare > 0)
{
Modifiedtime_1.Modifiedtime = Max.AddMinutes(5);
Console.WriteLine("----------");
Console.WriteLine("modifiedtime");
Console.WriteLine(Modifiedtime_1.Modifiedtime);
Console.WriteLine("----------");
}
Loop is executed.
Thanks in adavnce.
using System;
using System.Management;
using System.Threading;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace datetime_1
{
public class RemoteConnect
{
public class Modifiedtime_1
{
public static DateTime? Modifiedtime = null;
}
public static void Main()
{
while (true)
{
Console.WriteLine(DateTime.Now.ToString());
Console.WriteLine("\a");
Thread.Sleep(1000);
Console.Clear();
ConnectionOptions options = new ConnectionOptions();
options.EnablePrivileges = true;
options.Impersonation = ImpersonationLevel.Impersonate;
options.Authentication = AuthenticationLevel.Packet;
options.Authority = "ntlmdomain:node1.local";
options.Username = "user1";
options.Password = "xxxxxx";
ManagementScope scope = new ManagementScope(string.Format(#"\\node1\root\cimv2"), options);
scope.Connect();
if (scope.IsConnected == true)
{
Console.WriteLine("node1 Connection Succeeded");
}
else
{
Console.WriteLine("node1 Connection Failed");
}
ConnectionOptions options1 = new ConnectionOptions();
options1.EnablePrivileges = true;
options1.Impersonation = ImpersonationLevel.Impersonate;
options1.Authentication = AuthenticationLevel.Packet;
options1.Authority = "ntlmdomain:node2.local";
options1.Username = "user2";
options1.Password = "xxxxxx";
ManagementScope scope1 = new ManagementScope(string.Format(#"\\node2\root\cimv2"), options1);
scope1.Connect();
if (scope1.IsConnected == true)
{
Console.WriteLine("node2 Connection Succeeded");
}
else
{
Console.WriteLine("node2 Connection Failed");
}
ConnectionOptions options3 = new ConnectionOptions();
options3.EnablePrivileges = true;
options3.Impersonation = ImpersonationLevel.Impersonate;
options3.Authentication = AuthenticationLevel.Packet;
options3.Authority = "ntlmdomain:WORKGROUP";
options3.Username = "user2";
options3.Password = "xxxx";
ManagementScope scope3 = new ManagementScope(string.Format(#"\\node3\root\cimv2"), options3);
scope3.Connect();
if (scope3.IsConnected == true)
{
Console.WriteLine("node3 Connection Succeeded");
}
else
{
Console.WriteLine("node3 Connection Failed");
}
ConnectionOptions options4 = new ConnectionOptions();
options4.EnablePrivileges = true;
options4.Impersonation = ImpersonationLevel.Impersonate;
options4.Authentication = AuthenticationLevel.Packet;
options4.Authority = "ntlmdomain:Workgroup";
options4.Username = "user4";
options4.Password = "xxxxxx";
ManagementScope scope4 = new ManagementScope(string.Format(#"\\node4\root\cimv2"), options4);
scope4.Connect();
if (scope4.IsConnected == true)
{
Console.WriteLine("node4 Connection Succeeded");
}
else
{
Console.WriteLine("node4 Connection Failed");
}
DateTime Localdatetime = DateTime.Now;
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_LocalTime");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("node1");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Date: {0}-{1}-{2}", queryObj["Year"], queryObj["Month"], queryObj["Day"]);
Console.WriteLine("Time: {0}:{1}:{2}", queryObj["Hour"], queryObj["Minute"], queryObj["Second"]);
String node1_Hour_TEMP = queryObj["Hour"].ToString();
String node1_Minute_TEMP = queryObj["Minute"].ToString();
String node1_SECOND_TEMP = queryObj["Second"].ToString();
String node1_Year_TEMP = queryObj["Year"].ToString();
String node1_Month_TEMP = queryObj["Month"].ToString();
String node1_Day_TEMP = queryObj["Day"].ToString();
ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(scope1, query);
foreach (ManagementObject queryObj1 in searcher1.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("node2");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Date: {0}-{1}-{2}", queryObj1["Year"], queryObj1["Month"], queryObj1["Day"]);
Console.WriteLine("Time: {0}:{1}:{2}", queryObj1["Hour"], queryObj1["Minute"], queryObj1["Second"]);
String node2_Hour_TEMP = queryObj1["Hour"].ToString();
String node2_Minute_TEMP = queryObj1["Minute"].ToString();
String node2_SECOND_TEMP = queryObj1["Second"].ToString();
String node2_Year_TEMP = queryObj1["Year"].ToString();
String node2_Month_TEMP = queryObj1["Month"].ToString();
String node2_Day_TEMP = queryObj1["Day"].ToString();
ManagementObjectSearcher searcher2 =
new ManagementObjectSearcher(scope3, query);
foreach (ManagementObject queryObj2 in searcher2.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("node3");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Date: {0}-{1}-{2}", queryObj2["Year"], queryObj2["Month"], queryObj2["Day"]);
Console.WriteLine("Time: {0}:{1}:{2}", queryObj2["Hour"], queryObj2["Minute"], queryObj2["Second"]);
String node3_Hour_TEMP = queryObj2["Hour"].ToString();
String node3_Minute_TEMP = queryObj2["Minute"].ToString();
String node3_SECOND_TEMP = queryObj2["Second"].ToString();
String node3_Year_TEMP = queryObj2["Year"].ToString();
String node3_Month_TEMP = queryObj2["Month"].ToString();
String node3_Day_TEMP = queryObj2["Day"].ToString();
ObjectQuery query4 = new ObjectQuery("SELECT * FROM Win32_LocalTime");
ManagementObjectSearcher searcher4 = new ManagementObjectSearcher(scope4, query);
foreach (ManagementObject queryObj4 in searcher4.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("node4");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Date: {0}-{1}-{2}", queryObj4["Year"], queryObj4["Month"], queryObj4["Day"]);
Console.WriteLine("Time: {0}:{1}:{2}", queryObj4["Hour"], queryObj4["Minute"], queryObj4["Second"]);
String node4_Hour_TEMP = queryObj4["Hour"].ToString();
String node4_Minute_TEMP = queryObj4["Minute"].ToString();
String node4_SECOND_TEMP = queryObj4["Second"].ToString();
String node4_Year_TEMP = queryObj4["Year"].ToString();
String node4_Month_TEMP = queryObj4["Month"].ToString();
String node4_Day_TEMP = queryObj4["Day"].ToString();
//Convert DATE Time String to INT
int node1_Hour;
int.TryParse(node1_Hour_TEMP, out node1_Hour);
int node1_Minute;
int.TryParse(node1_Minute_TEMP, out node1_Minute);
int node1_SECOND;
int.TryParse(node1_SECOND_TEMP, out node1_SECOND);
int node1_YEAR;
int.TryParse(node1_Year_TEMP, out node1_YEAR);
int node1_MONTH;
int.TryParse(node1_Month_TEMP, out node1_MONTH);
int node1_DAY;
int.TryParse(node1_Day_TEMP, out node1_DAY);
DateTime node1_DATE = new DateTime(node1_YEAR, node1_MONTH, node1_DAY, node1_Hour, node1_Minute, node1_SECOND);
//Convert DATE Time String to INT
int node2_Hour;
int.TryParse(node2_Hour_TEMP, out node2_Hour);
int node2_Minute;
int.TryParse(node2_Minute_TEMP, out node2_Minute);
int node2_SECOND;
int.TryParse(node2_SECOND_TEMP, out node2_SECOND);
int node2_YEAR;
int.TryParse(node2_Year_TEMP, out node2_YEAR);
int node2_MONTH;
int.TryParse(node2_Month_TEMP, out node2_MONTH);
int node2_DAY;
int.TryParse(node2_Day_TEMP, out node2_DAY);
DateTime node2_DATE = new DateTime(node2_YEAR, node2_MONTH, node2_DAY, node2_Hour, node2_Minute, node2_SECOND);
//Convert DATE Time String to INT
int node3_Hour;
int.TryParse(node3_Hour_TEMP, out node3_Hour);
int node3_Minute;
int.TryParse(node3_Minute_TEMP, out node3_Minute);
int node3_SECOND;
int.TryParse(node3_SECOND_TEMP, out node3_SECOND);
int node3_YEAR;
int.TryParse(node3_Year_TEMP, out node3_YEAR);
int node3_MONTH;
int.TryParse(node3_Month_TEMP, out node3_MONTH);
int node3_DAY;
int.TryParse(node3_Day_TEMP, out node3_DAY);
DateTime node3_DATE = new DateTime(node3_YEAR, node3_MONTH, node3_DAY, node3_Hour, node3_Minute, node3_SECOND);
//Convert DATE Time String to INT
int node4_Hour;
int.TryParse(node4_Hour_TEMP, out node4_Hour);
int node4_Minute;
int.TryParse(node4_Minute_TEMP, out node4_Minute);
int node4_SECOND;
int.TryParse(node4_SECOND_TEMP, out node4_SECOND);
int node4_YEAR;
int.TryParse(node4_Year_TEMP, out node4_YEAR);
int node4_MONTH;
int.TryParse(node4_Month_TEMP, out node4_MONTH);
int node4_DAY;
int.TryParse(node4_Day_TEMP, out node4_DAY);
DateTime node4_DATE = new DateTime(node4_YEAR, node4_MONTH, node4_DAY, node4_Hour, node4_Minute, node4_SECOND);
Console.WriteLine("LocalDateTime");
Console.WriteLine(Localdatetime);
Console.WriteLine("=====LINQ=====");
var Max = new[] { node1_DATE, node2_DATE, node3_DATE, node4_DATE }.Max();
Console.WriteLine(Max);
Console.WriteLine("=====LINQEND=====");
//compare datetime with local.
int compare = DateTime.Compare(Max, Localdatetime);
if (compare == 0 || compare > 0)
{
Modifiedtime_1.Modifiedtime = Max.AddMinutes(5);
Console.WriteLine("----------");
Console.WriteLine("modifiedtime");
Console.WriteLine(Modifiedtime_1.Modifiedtime);
Console.WriteLine("----------");
}
else
{
Modifiedtime_1.Modifiedtime = Localdatetime;
Console.WriteLine("----------");
Console.WriteLine("modifiedtime");
Console.WriteLine(Modifiedtime_1.Modifiedtime);
Console.WriteLine("----------");
}
}
}
}
}
}
}
}
}
Why not just do something like this
Before your infinite loop.
bool firstPass = true;
Inside your loop
... Work out what Modifiedtime_1.Modifiedtime value is.
and at the end of the loop
if ( firstPass || (..times deviated to much calculation))
{
firstPass = false;
SetLocalMachineTimeMethod(Modifiedtime_1.Modifiedtime);
}
where SetLocalMachineTimeMethod is some routine you call to set the time locally. There is also a possibility of the added refinement of checking the modified time and (local system time) to see if they have drifted apart by too much and then allow the call be be made again.
I'm trying to get bit locker recovery information for all users from active directory via below functions.
I've tried many different solution but none of them solved my problem.
I can get most of the computer properties like Operation System,Service Pack expect bit locker info.
Is there any special permission or method to search with msFVE-RecoveryInformation ?
Method 1:
DirectoryEntry child = new DirectoryEntry("LDAP://XXXXX");
DirectoryEntries enteries = child.Children;
DirectorySearcher ds = new DirectorySearcher(child);
ds.Filter = "(&(objectCategory=Computer)(cn=computerName))";
ds.SearchScope = SearchScope.Subtree;
SearchResultCollection item = ds.FindAll();
//string dn = item.GetDirectoryEntry().Properties["distinguishedname"].Value.ToString();
string temp1 = System.DirectoryServices.AccountManagement.UserPrincipal.Current.DistinguishedName;
child = new DirectoryEntry(("LDAP://" + temp1), "XXXXX", "XXXXX");
enteries = child.Children;
ds = new DirectorySearcher(child);
ds.Filter = "(objectClass=msFVE-RecoveryInformation)";
ds.SearchScope = SearchScope.Subtree;
SearchResultCollection result = ds.FindAll();
if (result.Count > 0)
{
foreach (SearchResult sr in result)
{
string recoveryKeyPackage = sr.GetDirectoryEntry().Properties["msFVE-KeyPackage"].Value.ToString();
string recoveryGUID = sr.GetDirectoryEntry().Properties["msFVE-RecoveryGuid"].Value.ToString();
string recoveryPassword = sr.GetDirectoryEntry().Properties["msFVE-RecoveryPassword"].Value.ToString();
string recoveryVolumeGUID = sr.GetDirectoryEntry().Properties["msFVE-VolumeGuid"].Value.ToString();
}
}
else
{
Console.Write ("No recovery information found!");
}
Method 2:
public Dictionary<string, string> GetBitlockerKeys(string computerName)
{
DirectoryEntry dEntry = new DirectoryEntry("LDAP://XXXX");
var keys = new Dictionary<string, string>();
using (var computerObject = dEntry)
{
var children = computerObject.Children;
var schemaFilter = children.SchemaFilter;
schemaFilter.Add("msFVE-RecoveryInformation");
foreach (DirectoryEntry child in children) using (child)
{
var recoveryGuid = new Guid((byte[])child.Properties["msFVE-RecoveryGuid"].Value).ToString();
var recoveryPassword = child.Properties["msFVE-RecoveryPassword"].Value.ToString();
if (!keys.ContainsKey(recoveryGuid))
{
keys.Add(recoveryGuid, recoveryPassword);
}
}
}
return keys;
}
I downloaded an example application for using some web services with an online system.
I am not sure if all code below is needed but it is what I got and what I am trying to do is to use the search function.
I start by calling searchCustomer with an ID I have:
partnerRef.internalId = searchCustomer(customerID);
And the code for searchCustomer:
private string searchCustomer(string CustomerID)
{
string InternalID = "";
CustomerSearch custSearch = new CustomerSearch();
CustomerSearchBasic custSearchBasic = new CustomerSearchBasic();
String nameValue = CustomerID;
SearchStringField entityId = null;
entityId = new SearchStringField();
entityId.#operator = SearchStringFieldOperator.contains;
entityId.operatorSpecified = true;
entityId.searchValue = nameValue;
custSearchBasic.entityId = entityId;
String statusKeysValue = "";
SearchMultiSelectField status = null;
if (statusKeysValue != null && !statusKeysValue.Trim().Equals(""))
{
status = new SearchMultiSelectField();
status.#operator = SearchMultiSelectFieldOperator.anyOf;
status.operatorSpecified = true;
string[] nskeys = statusKeysValue.Split(new Char[] { ',' });
RecordRef[] recordRefs = new RecordRef[statusKeysValue.Length];
for (int i = 0; i < nskeys.Length; i++)
{
RecordRef recordRef = new RecordRef();
recordRef.internalId = nskeys[i];
recordRefs[i] = recordRef;
}
status.searchValue = recordRefs;
custSearchBasic.entityStatus = status;
}
custSearch.basic = custSearchBasic;
SearchResult response = _service.search(custSearch);
if (response.status.isSuccess)
{
processCustomerSearchResponse(response);
if (seachMoreResult.status.isSuccess)
{
processCustomerSearchResponse(seachMoreResult);
return InternalID;
}
else
{
_out.error(getStatusDetails(seachMoreResult.status));
}
}
else
{
_out.error(getStatusDetails(response.status));
}
return InternalID;
}
In the code above processCustomerSearchResponse gets called
processCustomerSearchResponse(response);
The code for this function is:
public string processCustomerSearchResponse(SearchResult response)
{
string InternalID = "";
Customer customer;
customer = (Customer)records[0];
InternalID = customer.internalId;
return InternalID;
}
What the original code did was to write some output in the console but I want to return the InternalID instead. When I debug the application InternalID in processCustomerSearchResponse contains the ID I want but I don't know how to pass it to searchCustomer so that function also returns the ID. When I debug searchCustomer InternalID is always null. I am not sure on how to edit the code under response.status.isSuccess
to return the InternalID, any ideas?
Thanks in advance.
When you call processCustomerSearchResponse(response);, you need to store the return value in memory.
Try modifying your code like this:
InternalID = processCustomerSearchResponse(response);