How I can update WMI Objects through C#.net?
-
Friday, March 02, 2012 12:37 PM
We can read WMI Object using C#. I am wondering is there a way to update the WMI Object properties with programmatically using .Net and c#? If yes, where can I find the APIs and some sample code?
My requirement is i need to schedule the SCCM advertisement for the future date and time. I assume when we schedule the SCCM advertisement it goes and updates WMI properties. I need help to update the WMI property for scheduling.
All Replies
-
Monday, March 05, 2012 1:00 PMModerator
Hi Manidon,
Welcome to the MSDN Forum.
Which WMI object properties do you want to update? Please tell us the specific object and properties since not all objects can be updated.
And here is a SCCM forum: http://social.technet.microsoft.com/Forums/en-US/category/configurationmanager
You can also try those forums.
If you agree, I will move this thread to off-topic forum, and you can start a new thread in those forum.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Wednesday, March 07, 2012 5:55 AM
Hi Mike,
Thanks for the reply.
Actually I am not that much sure that which property to update for the scheduling purpose thats why wondering some solution for this here.
Below is my issue :
I have a requirement that I need to update WMI objects if any Software going to install by SCCM in any client system as I want to schedule it for future date to install.
Steps which to do:
- Popup for S/w or application installation through SCCM to all clients
- Choice 1 – “Install now” : will start the installation on local machine
- Choice 2 - “Schedule later” : will do the scheduling for future date maximum 5 days on local machine as per user selection
- Step 3 will update the WMI objects and set installation at given date and time for that user
I am stuck in the step 3 and 4 as I don’t know how to update and Which WMI objects/property i have to update. This i am trying to do in C#.net and I think CCM_Scheduler_ScheduledMessage of WMI object need to update. Please correct me if i am wrong.
Please help me, it will be more helpful if you provide me some code snippet or any .net example.
Thanks and Regards,
Manidon
- Edited by manidon Wednesday, March 07, 2012 6:01 AM
-
Wednesday, March 07, 2012 6:25 AMModerator
Hi Manidon,
Based on your further clarification, my understanding is you are trying to use WMI to make a schedule job, so please take a look at this documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394601(v=vs.85).aspx
You can get which part you need to change from there.
And then, you can use this tool to generate your C# code: http://www.microsoft.com/download/en/details.aspx?id=8572
And here is a drill about this tool: http://blogs.technet.com/b/askperf/archive/2010/02/02/two-minute-drill-wmi-code-creator.aspx
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Friday, March 09, 2012 6:59 AM
Hi Mike,
Thanks again for the help... But let me clear you that i dont want WMI to make a schedule job. If i create a job with WMI i will not get the logs in the execmgr.log.
I want to updates the WMI object property which is handling the SCCM installations and logs. We can see the WMI logs in the "C:\WINDOWS\system32\CCM\Logs".
I have written a code below which gives the information of scheduled Message Instances in the system for a SceduledMessageID.
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\ccm\\Policy\\Machine",
"SELECT * FROM CCM_Scheduler_ScheduledMessage where ScheduledMessageID='INB2001B-INB001C0-70EEBBDE'");foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("CCM_Scheduler_ScheduledMessage instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("ActiveMessage: {0}", queryObj["ActiveMessage"]);
Console.WriteLine("ActiveTime: {0}", queryObj["ActiveTime"]);
Console.WriteLine("ActiveTimeIsGMT: {0}", queryObj["ActiveTimeIsGMT"]);
Console.WriteLine("DeliverMode: {0}", queryObj["DeliverMode"]);
Console.WriteLine("ExpireMessage: {0}", queryObj["ExpireMessage"]);
Console.WriteLine("ExpireTime: {0}", queryObj["ExpireTime"]);
Console.WriteLine("ExpireTimeIsGMT: {0}", queryObj["ExpireTimeIsGMT"]);
Console.WriteLine("MessageName: {0}", queryObj["MessageName"]);
Console.WriteLine("MessageTimeout: {0}", queryObj["MessageTimeout"]);
Console.WriteLine("ReplyToEndpoint: {0}", queryObj["ReplyToEndpoint"]);
Console.WriteLine("ScheduledMessageID: {0}", queryObj["ScheduledMessageID"]);
Console.WriteLine("TargetEndpoint: {0}", queryObj["TargetEndpoint"]);
Console.WriteLine("TriggerMessage: {0}", queryObj["TriggerMessage"]);
if(queryObj["Triggers"] == null)
Console.WriteLine("Triggers: {0}", queryObj["Triggers"]);
else
{
String[] arrTriggers = (String[])(queryObj["Triggers"]);
foreach (String arrValue in arrTriggers)
{
Console.WriteLine("Triggers: {0}", arrValue);
}
}
queryObj["ExpireMessage"] = "test";Console.WriteLine("ExpireMessage: {0}", queryObj["ExpireMessage"]);
If you see in the above code snippet i can get the values through properties but in last line i can update the property ExpireMessage = "test" during runtime. Please tell me how can i update this in the system so that i should get the different values for this ScheduledMessageId.
Hope now you get where i am stuck. It will be greate help if you can provide me its solution.
Regards,
Mani
-
Friday, March 09, 2012 9:58 PMI think you need to call Put, after making your changes.
- Proposed As Answer by Mike FengMicrosoft Contingent Staff, Moderator Sunday, March 11, 2012 5:22 AM
- Unproposed As Answer by manidon Tuesday, March 13, 2012 5:42 AM
-
Sunday, March 11, 2012 5:22 AMModerator
Hi Mani,
Thank you for your further clarification. I think I got you: Your code can update the "ExpireMessage" when your application runs, but when you exit the application, the changes didn't update to the system. Right?
How about Jared's suggestion? It looks like very helpful for this issue.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Monday, March 12, 2012 6:34 AM
Please let me know how to call put method on the above example???
Also need to know it will update the system value and i can get the logs in the exemgr log file???
Regards, ManiDon
-
Tuesday, March 13, 2012 9:22 AMModerator
Please let me know how to call put method on the above example???
Also need to know it will update the system value and i can get the logs in the exemgr log file???
Regards, ManiDon
Hi Manidon,
How about "queryObj.Put()"?
Does it work for you?
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Tuesday, March 13, 2012 9:51 AM
Hi Mike
No this is not working as this gives me "Invalid class" exception.
Regards, ManiDon
- Edited by manidon Tuesday, March 13, 2012 9:52 AM
-
Tuesday, April 23, 2013 9:23 PM
I know this a very late response, but I was just trying to solve this very same problem myself, as I was getting the same result as you (invalid class).
This solved it for me. If you add "ActualConfig" to the end of your namespace path, then you can update it with the Put() command successfully.
What you had:
ManagementObjectSearcher("root\\ccm\\Policy\\Machine","SELECT * FROM CCM_Scheduler_ScheduledMessage where ScheduledMessageID='INB2001B-INB001C0-70EEBBDE'");
Change that to:
ManagementObjectSearcher("root\\ccm\\Policy\\Machine\\ActualConfig","SELECT * FROM CCM_Scheduler_ScheduledMessage where ScheduledMessageID='INB2001B-INB001C0-70EEBBDE'");
- Marked As Answer by Mike FengMicrosoft Contingent Staff, Moderator Wednesday, May 15, 2013 12:02 PM

