none
Possible to open and monitor a control panel app with WMI using it's canonical name? - VBScript RRS feed

  • Question

  • Hi All!

    I have need to open a control panel app (Win 7) via WMI and monitor it's process ID until it's closed as explained in one of your previous blog answers found here:

    http://blogs.technet.com/b/heyscriptingguy/archive/2006/12/08/how-can-i-start-a-process-and-then-wait-for-the-process-to-end-before-terminating-the-script.aspx

    I figured out how to accomplish this with Device Manager using mmc.exe and an argument like this:

    objWMIService.Create "mmc.exe devmgmt.msc", null, null, intDevMgrID

    so was hoping something like this would work:

    objWMIService.Create "c:\windows\system32\control.exe /name Microsoft.System", null, null, intSystemID

    but am having no luck. It launches the applet but doesn't run a called function after being closed as the Device Manager line does. Any thoughts?

    Thanks!
    Mike

    Monday, December 15, 2014 4:51 PM

Answers

  • Thanks for confirming that what I'm trying to do is not going to work. The workaround for me will be to use msinfo32.exe instead of the system properties.

    In all reality, it's a very simple script for a very simple process. It's all about presentation of information to a customer (layperson) about the condition of their PC. The choice to open OS windows to show this info rather than gather it and show it in a text file or dialog is purely for the benefit of the customer. Using native windows such as the ones mentioned previously makes more sense to a layperson as they may actually have seen or used some of them before and can see some familiarity in them such as their computer name or something similar. In my experience, presenting a single file with all of the same information doesn't instill the same confidence in the person that they are seeing info gathered from their actual PC.

    The reason for not wanting to show the Yes/No dialog until after the other windows are closed is because that dialog is asking if they are wanting to check their pc in to be evaluated, so opening it at the same time as the other windows can come across as a bit "presumptuous". This lead me to trying to find a way to wait until all the other windows were closed to open it.

    Again, and as always, I appreciate all your help!
    Mike

    Tuesday, December 16, 2014 4:45 PM

All replies

  • Why do you need to do it?

    -- Bill Stewart [Bill_Stewart]

    Monday, December 15, 2014 4:56 PM
    Moderator
  • Thanks for the reply, Bill.

    I'm writing a script that opens a number of different windows at one time such as Task Manager, MSConfig, Device Mgr, System Properties, Action Center, etc.  I've already been using some code that launches all the windows with no problem using the .run method.

    Currently, I have need to run a function that pops a "Yes/No" dialog box as well, but the catch is that it needs to run that function after all of the other windows have been closed. So far I've figured out how to monitor all of the windows except for the one specified previously.

    Monday, December 15, 2014 5:10 PM
  • That doesn't answer the underlying question.

    Why are you opening a number of different windows at one time? What is the requirement that this solves?


    -- Bill Stewart [Bill_Stewart]

    Monday, December 15, 2014 5:30 PM
    Moderator
  • Another way to ask this question: What is the goal/purpose of the script?

    -- Bill Stewart [Bill_Stewart]

    Monday, December 15, 2014 5:49 PM
    Moderator
  • It's part of a script that is used to gather information on the status of a PC in an IT environment. The user needs to assess things such as the status of and how many items in startup, how many running processes, memory usage, disabled or items with errors in Device manager, amount of RAM and processor type, AV installed and enabled, etc.

    These windows present all of the needed information. Once the windows are closed the user is presented a Yes/No dialog box asking if the system is meeting all requirements. The Yes or No value is then sent to a web server and entered into a db.

    My requirement, I suppose, is that I need to present this Yes/No dialog only after these other windows have been closed. WMI is the only way I've found to do this and WMI doesn't appear to monitor control panel applets opened as arguments from control.exe as far as my testing has shown.

    Monday, December 15, 2014 5:50 PM
  • Why not just get those items directly in the script and write them to a file? In this way you don't need to pop up any windows or ask the users any questions.

    -- Bill Stewart [Bill_Stewart]

    Monday, December 15, 2014 5:57 PM
    Moderator
  • Because the users are presenting this information in front of a customer and it needs to be shown in a way that the customer can relate to (the Windows OS).

    The script has been in use for a few months now and has been working great but now that there is a requirement of the dialog it changes how I need to manage the windows.

    I DO appreciate you considering whether or not there is a better way to accomplish what I'm needing to do though. :)

    Monday, December 15, 2014 6:09 PM
  • You could gather the information and display it in a popup box, if you insist on user interaction. I don't really see the value in doing what you're doing. Control panel applets launch asynchronously, as you noticed, and aren't really designed to be run from a script in the way you're trying to do it.

    -- Bill Stewart [Bill_Stewart]


    Monday, December 15, 2014 6:18 PM
    Moderator
  • There are tools that do this such as the software formally known as "QTP".

    If this is an important application then I recommend using professional tools.

    http://www8.hp.com/us/en/software-solutions/unified-functional-testing-automation/

    This can do everything you need and is configured an created by recording a sequence.  You can then edit the text file and do things like specify that a dialog should be shown after all windows are closed.What you are trying to do by brute force with script will never be easy or reliable.


    ¯\_(ツ)_/¯

    Monday, December 15, 2014 8:00 PM
  • Thanks for the replies Bill and jrv.

    This app is definitely not on a level at which I'd need to use something like UTF.

    Here's my 0.02 if I might and please know this is communicated with no animosity.

    I appreciate that you both understand that I may not be approaching the design of this piece of code in the "proper" or "best practices" way. This being considered, I feel a bit more like I'm being reprimanded for such behavior.  If you're going to give me the bitter pill (explaining that I'm not doing this properly) then at least give me the spoonful of sugar (if you MUST do it that way, here's a way to achieve it. Or no, it's not technically possible for WMI to monitor a window launched via control.exe).

    Maybe at some point in time I'll be able to revisit the design of this app but it's not an option right now. I just need to find a solution that falls within my requirements, if one even exists!

    Thanks for your time today!

    Monday, December 15, 2014 9:45 PM
  • There is no way to automate control panel items as you ask.  You can start them and stop them.  They have no automation interface.

    The kind of control you ask for can only beobtained via the low level debug API. That is wht QTP uses. THat is why we need an application like QTP when we do testing. If it could easily be done by scrpt then you would see it used extensivily.

    No one is chatizing you. We are only trying to undrstnad why you think this is necessary. Perhaps if you could make that clear we could show you a way to obtain the result you seek.


    ¯\_(ツ)_/¯

    Monday, December 15, 2014 10:03 PM
  • Thanks for confirming that what I'm trying to do is not going to work. The workaround for me will be to use msinfo32.exe instead of the system properties.

    In all reality, it's a very simple script for a very simple process. It's all about presentation of information to a customer (layperson) about the condition of their PC. The choice to open OS windows to show this info rather than gather it and show it in a text file or dialog is purely for the benefit of the customer. Using native windows such as the ones mentioned previously makes more sense to a layperson as they may actually have seen or used some of them before and can see some familiarity in them such as their computer name or something similar. In my experience, presenting a single file with all of the same information doesn't instill the same confidence in the person that they are seeing info gathered from their actual PC.

    The reason for not wanting to show the Yes/No dialog until after the other windows are closed is because that dialog is asking if they are wanting to check their pc in to be evaluated, so opening it at the same time as the other windows can come across as a bit "presumptuous". This lead me to trying to find a way to wait until all the other windows were closed to open it.

    Again, and as always, I appreciate all your help!
    Mike

    Tuesday, December 16, 2014 4:45 PM
  • All of that is in MSINFO.  You can also dump MSINFO into an XML file and reformat it however you like using XSL.  Microsoft also distributes a super diagnostic which scavenges as deep into the system as is possible.  It is called "DebugDiag". http://www.microsoft.com/en-us/download/details.aspx?id=40336

    There are numerous other tools as well as dozens of scripts in the repository.  This is how we normally do what you are trying to do.


    ¯\_(ツ)_/¯

    Tuesday, December 16, 2014 5:26 PM