0

I have a VB6 application that should be able to check if the same (or a certain other) application is running on other pc's in the network. The goal of this is being sure the application is not running on any pc in the network in order to do a database compress. If the application is detected somewhere in the network, can i stop it with my vb6 app. ?

Any idea how to achieve this with vb6 ?

Thanks in advance, Dirk

  • 2
    So the two instances will detect and try to kill each other? – GSerg Feb 11 '16 at 10:52
  • 1
    What's the database type? Security issues makes this a really complex solution. You might want to see if you can bring your database in a `Single Connection` state. – Stefan Feb 11 '16 at 10:53
  • Possible duplicate of [How to find all instances of a running program on all hosts on a LAN?](http://stackoverflow.com/questions/3190056/how-to-find-all-instances-of-a-running-program-on-all-hosts-on-a-lan) – GSerg Feb 11 '16 at 10:55
  • Possible duplicate of [How to check if there are other application instances running](http://stackoverflow.com/q/16199858/11683) – GSerg Feb 11 '16 at 10:55
  • the database is Ms Access. The check should be done if a user is stopping his VB6 application. If it's run somewhere else on the network the database compress will not be executed, else it will execute. – user3240726 Feb 11 '16 at 11:08
  • 2
    Suppose you check that no other apps are running and decide to compress the database. The millisecond after you've checked but before you started the compression, another app is launched. What is going to happen? – GSerg Feb 11 '16 at 11:14
  • The user stops his app if he is leaving the office, so the compress will start if the last users closes his VB app. – user3240726 Feb 11 '16 at 13:29
  • 2
    What I'm trying to say is that the common solution to all these race condition-prone checks is to "just do it" and handle/ignore the error. You cannot compress a database that is opened by other users. So just try, and if you succeed you were the last one. – GSerg Feb 11 '16 at 16:12

1 Answers1

0
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")

For Each objItem in colItems
    msgbox objItem.ProcessID & " " & objItem.CommandLine
    If objItem.name = "Calculator.exe" then objItem.terminate
Next

The dot in \\.\ above is the computer name. . means local computer but you can put another computer's name in there instead. To see what properties/methods are available type in a command prompt

wmic process get /?

and

 wmic process call /?