VBScript? to display message on all computers in domain that are running a specific exe

Posted on 2006-03-23
Medium Priority
Last Modified: 2008-02-01
We have some software that runs on our network with only 25 user licenses. When all are in use the next person who tries to use it cannot log in to it.

That work fine until we have people who leave a session open on their system and forget about it.

I want to be able to display a message to all users on our local domain, who currently have that program running, and ask them to log out if they have finished using it.

Any thoughts on how I might tackle this would be welcome. ( I was thinking a vbscript that I could run from my machine, but I am open to suggestions)


Question by:duanelitchfield
  • 3
LVL 23

Expert Comment

ID: 16268951
Look here :


Which has the following script :

strComputer = "FullComputerName"       '<-- You can use an InputBox here instead so it prompts you
strDomain = "DOMAIN"              '<-- Put your FQDN in here
strUser = InputBox("Enter user name")    '<-- You could hard code this in
strPassword = InputBox("Enter password")    '<-- you could hard code this in
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer(strComputer, _
    "root\CIMV2", _
    strUser, _
    strPassword, _
    "MS_409", _
    "ntlmdomain:" + strDomain)
Set colProcessList = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Process WHERE Name = 'notepad.exe'")   '<-- Change the name of the process name
For Each objProcess in colProcessList

If you need any more help please post back.
LVL 23

Expert Comment

ID: 16268959

Author Comment

ID: 16269699
Whoa - I need to clarify a bit here I think.

The script you posted wil terminate the target process on the machine it is found on.

I just want to put up a message on THAT computer asking them to close the target app if they are not currently using it.

If I replace the line

objProcess.Terminate() with

msgbox("Please close notepad.exe if you are not using it")

I get a message box on the machine I ran the script on not the one that notepad.exe was found on.

Hope that makes more sense.

Thanks & regards,

LVL 23

Accepted Solution

gecko_au2003 earned 500 total points
ID: 16272972
If I am right, I think you have to have the messenger service enabled and use net send

to get that to work you would need something like so

Set objShell = CreateObject("Wscript.Shell")

objShell.Run "cmd.exe"
wscript.sleep 250
wscript.sendkeys "Net Send " & strComputer & " " & strDomain

or something to that extent , take a look here :

NET SEND {name | * | /DOMAIN[:name] | /USERS} message
Sends messages to other users, computers, or messaging names on the network. The Messenger service must be running to receive messages.

You can send a message only to an name that is active on the network. If the message is sent to a username, that user must be logged on and running the Messenger service to receive the message.

name       Is the username, computername, or messaging name to send the message to. If the name is a computername that contains blank characters, enclose the alias in quotation marks (" ").
*       Sends the message to all the names in your group.
/DOMAIN[:name]        Sends the message to all the names in the workstation domain. If name is specified, the message is sent to all the names in the specified domain or workgroup.
/USERS       Sends the message to all users connected to the server.
message       Is text to be sent as a message.

which I got from here :


and also the code project example ( which has source code )

LVL 22

Assisted Solution

JesterToo earned 500 total points
ID: 16413588
Hi Duane,

I think Shane (gecko) just forgot to substitute the "net send" for the "terminate" code in the example script.  His idea should work, but you will need to wrap some more code around it.  Specifically, you need to iterate through a list of computer names and run the code against each one of them to see if that machine is currently running the executable in question.  That can be accomplished by enumerating all the computers in Active Directory... but, if you have very many machines it could take a considerable amount of time to query them all.  This will be especially true if some of those computers might be powered off at the time you run this script but that can be partially compensated for by pinging each machine prior to attempting the WMI query.  

Another approach might be possible... if the launch-process for this licensed app can be modified (such as placing it in a batch file and pointing desktop icons to the batch file) to create/write a filename consisting of just the computername to a common shared directory each time a user launches the app then this script can locate all those files with the current date and use that list to send the message to.  This could significantly reduce the amount of time the script has to spend querying the remote machines.

Let us know if you think that might work and also if you need any assistance with the script itself.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question