Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.basic.visual.misc > #913
| From | "MikeD" <nobody@nowhere.edu> |
|---|---|
| Newsgroups | comp.lang.basic.visual.misc, microsoft.public.vb.general.discussion |
| Subject | Re: How do I start/stop a system service |
| Date | 2012-03-10 17:57 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <jjgm94$4vl$1@dont-email.me> (permalink) |
| References | <jjdm45$kv9$1@dont-email.me> <jjdq5u$fb3$1@dont-email.me> <jje0pr$n5o$1@dont-email.me> <jjfhbb$gho$1@dont-email.me> <jjg5q6$7a6$1@dont-email.me> |
Cross-posted to 2 groups.
"GS" <gs@somewhere.net> wrote in message news:jjg5q6$7a6$1@dont-email.me... > MikeD expressed precisely : >> >> "GS" <gs@somewhere.net> wrote in message >> news:jje0pr$n5o$1@dont-email.me... >>> MikeD wrote on 3/9/2012 : >>>> >>>> "GS" <gs@somewhere.net> wrote in message >>>> news:jjdm45$kv9$1@dont-email.me... >>>>> My apps rely on WMI for gathering hardware info. How would I start WMI >>>>> if not running, then stop it when I'm done using it? >>>>> >>>> >>>> >>>> The simplest way I can think of would be to use "net start" from the >>>> command line. You can run cmd.exe with the /c parameter followed by >>>> the net start command. For example (syntax may not be exactly right): >>>> >>>> cmd.exe /c net start "Windows Management Instrumentation" >>>> >>>> Similarly, to stop the service, use "net stop". >>>> >>>> Mike >>> >>> Thanks, Mike. I assume you mean to do this via Shell or ShellExecute? I >>> was thinking there'd be API[s] involved but if it's that simple... >>> >>> -- >> >> Yes. Use Shell. >> >> There are API calls you can make (as per Jeff's reply), but I think this >> is simpler. The only caveat, if you want to even call it that, is that a >> command prompt window will open and close, but you could hide that. > > I assume I can do this via cmd line switches? I have no idea how but I'd > be happy to research any ref docs you can point me to. Of course, a code > example is always an appreciated alternative. If you simply use VB's Shell function, you should be able to specify the vbHide parameter. Yeah, these work: Shell "cmd.exe /c net start ""Windows Management Instrumentation""", vbHide Shell "cmd.exe /c net stop ""Windows Management Instrumentation""", vbHide Make SURE you specify the /c parameter. It's important. If you're not familiar with cmd.exe parameters, type "cmd /?" from a command prompt window. I need to qualify "works". Apparently at least on Windows 7, there could be services running that are dependent on WMI. So, if you try to stop WMI and any of these dependent services are running, you're informed of these other services and prompted to continue (need to type Y or N). If the window is hidden, there's no way to respond to this prompt. That shouldn't have any affect on what you're doing because you'll only be stopping WMI if you had to start it, so those dependent services shouldn't be running. But I just wanted to mention this. On ANY version of Windows, either MS or 3rd party services could be installed that are dependent on WMI, and you'd run into the same problem. > >> And Farnsworth made the excellent point that I neglected to, which is >> that the user must have permissions to start and stop services. > > Yeah, that's a good point. I agree with Mayayana that it will only be > stopped if corporate Group Policy or Active Directory has disabled it. I > make it perfectly clear (up front) that it must be fully functional for my > app to work properly, and so I don't anticipate ever needing to start it > anyway. That doesn't exclude, however, personal machines where it has > inadvertently been stopped/paused by some process. It's this scenario that > I want to be able to mitigate... Here's my opinion on the whole thing though. I don't really agree with what you're doing. I don't think any program has any business starting/stopping services or doing certain other things behind the scenes (i.e. without the user's knowledge or consent). OK. You say you make it perfectly clear that WMI has to be running. That's making a couple of assumptions. First is that the user actually READ that. Now I don't know where you have it documented, but users are notorious for not fully reading documentation. And even if they did read it at one time, they could forget. Second assumption is that WMI is not disabled for whatever reason (which you mentioned). It boils down to this: don't make your program dependent on things that you can't necessarily control. Now I don't know what hardware information you're trying to get, but I'd bet there's other ways besides using WMI to get it. Maybe there are API functions or perhaps you can even just get it from the Registry. I just think what you're doing is not really "clean" and could be considered a little bit devious. I'm not saying there are bad or ill intentions behind what you're doing. If *I* were evaluating your program, I might very well choose not to use it. Mike
Back to comp.lang.basic.visual.misc | Previous | Next — Previous in thread | Next in thread | Find similar
How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-09 14:36 -0500
Re: How do I start/stop a system service "MikeD" <nobody@nowhere.edu> - 2012-03-09 15:45 -0500
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-09 17:38 -0500
Re: How do I start/stop a system service "MikeD" <nobody@nowhere.edu> - 2012-03-10 07:27 -0500
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-10 13:16 -0500
Re: How do I start/stop a system service "MikeD" <nobody@nowhere.edu> - 2012-03-10 17:57 -0500
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-10 21:08 -0500
Re: How do I start/stop a system service "MikeD" <nobody@nowhere.edu> - 2012-03-10 22:57 -0500
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-10 23:58 -0500
Re: How do I start/stop a system service Jason Keats <jkeats@melbpcDeleteThis.org.au> - 2012-03-11 20:22 +1100
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-11 15:54 -0400
Re: How do I start/stop a system service Jason Keats <jkeats@melbpcDeleteThis.org.au> - 2012-03-12 15:19 +1100
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-12 01:14 -0400
Re: How do I start/stop a system service "Mike Williams" <Mike@WhiskyAndCoke.com> - 2012-03-11 09:20 +0000
Re: How do I start/stop a system service "MikeD" <nobody@nowhere.edu> - 2012-03-11 19:11 -0400
Re: How do I start/stop a system service "Mike Williams" <Mike@WhiskyAndCoke.com> - 2012-03-11 09:13 +0000
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-11 16:19 -0400
Re: How do I start/stop a system service "MikeD" <nobody@nowhere.edu> - 2012-03-11 19:23 -0400
Re: How do I start/stop a system service "Mayayana" <mayayana@invalid.nospam> - 2012-03-11 20:54 -0500
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-11 22:12 -0400
Re: How do I start/stop a system service "Mayayana" <mayayana@invalid.nospam> - 2012-03-12 09:57 -0500
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-12 13:24 -0400
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-12 13:59 -0400
Re: How do I start/stop a system service "Henning" <computer_hero@coldmail.com> - 2012-03-12 22:46 +0100
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-12 18:59 -0400
Re: How do I start/stop a system service "Farnsworth" <nospam@nospam.com> - 2012-03-09 16:01 -0500
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-09 17:36 -0500
Re: How do I start/stop a system service "Farnsworth" <nospam@nospam.com> - 2012-03-09 18:55 -0500
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-09 21:30 -0500
Re: How do I start/stop a system service "Farnsworth" <nospam@nospam.com> - 2012-03-11 11:14 -0500
Re: How do I start/stop a system service "Jeff Johnson" <I.get@enough.spam> - 2012-03-09 17:41 -0500
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-09 18:23 -0500
Re: How do I start/stop a system service "Mayayana" <mayayana@invalid.nospam> - 2012-03-10 09:24 -0500
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-10 13:06 -0500
Re: How do I start/stop a system service "Mayayana" <mayayana@invalid.nospam> - 2012-03-10 14:11 -0500
Re: How do I start/stop a system service GS <gs@somewhere.net> - 2012-03-10 15:25 -0500
csiph-web