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

Posted on 2006-03-23
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
    LVL 23

    Expert Comment

    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


    Author Comment

    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

    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 20

    Assisted Solution

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    proper way to parse text with delphi 7 76
    mirrorEnds challenge 6 66
    notReplace  challenge 53 93
    seriesUp challenge 7 81
    Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now