Do not use, republish, in whole or in part, without the consent of the Author. TheTAZZone policy is that Authors retain the rights to the work they submit and/or post…we do not sell, publish, transmit, or have the right to give permission for such…TheTAZZone merely retains the right to use, retain, and publish submitted work within it’s Network

Please refer to the original post as not all the script may be visible here.

This script is designed to prevent a logoff from happening if a specific program is running, otherwise, if the program isn’t found, let the logoff process continue. I don’t know everyone’s script knowledge level so just in case I need to clarify I use the words process/program/executible interchangeably throughout the following explanation:

When the script is double-clicked it searches through the process list for an executible file. In the example below the executible is called vmware-vmx.exe. If this process is running on the computer the script will display a message to the user stating “x VMs are running. Please turn them off before continuing to logoff”. If the process is not found the script will logoff the user. In order for this to work you need to put a shortcut to this script in the Start menu (and/or desktop) and edit local group policy so that the logoff button no longer appears in the Start or Ctrl+Alt+Del menu. This will force users to click on the script whenever they want to logoff. You also need to change the process/program name to whatever program you want the script to search for. Replace where it says vmware-vmx and VMware with your program’s name. You can also use this script to prevent shutdown and restart. I made a comment towards the end of the script as to how.

Code: Select all
' Created: 6/14/2007
' Updated: 7/3/2007
' A big THANK YOU to Adam, Jaker, Guy Thomas, and Lisa
' ***********************************************************

‘ Require all variables to be declared before they can be used.
‘ This helps with debugging issues
Option Explicit

‘ Define all of the variables
Dim strComputer, objWMIService, colProcesses,
Dim objProcess, strList, VMcount

‘ Establish variables
strComputer = “.” ‘setting strComputer to “.” connects to the local machine.
VMcount = 0 ‘starts the process count at 0

‘ All WMI scripts begin by connecting to the Windows Management Instruments interface
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” _
& strComputer & “\root\cimv2”)

‘ Get a collection of all running processes
Set colProcesses = objWMIService.ExecQuery(“Select * FROM Win32_Process”)

‘ Cycle through every currently running process
For Each objProcess in colProcesses
‘Check to see if the program is currently running
If objProcess.Name = “vmware-vmx.exe” Then
‘the program is running if the above statement is true.
VMcount = VMcount + 1 ‘Count the number of running processes
End If
If VMcount > 0 Then
‘Build the message box text notifying the user of any running processes
strList = strList & VMcount _
& ” VMware process(es) running.” _
& ”  Please power off before continuing to logoff.” & vbCr
‘This message box will only appear if the process was found
WSCript.Echo strList
‘Create another variable to connect to the Windows shell service.
Dim objWSHShell
‘Connect to the Windows shell service
Set objWSHShell = CreateObject(“WScript.Shell”)
‘Execute the logoff command to logoff
objWSHShell.Run “shutdown -l” ‘change to -s to shutdown or -r to restart
End if
‘Quit the script

By admin

Former Freehand Freelance Graphic Illustrator... been online since 2004 ( late starter ), blogging since 2005, presently writing a suspense-thriller e-book that began as a screenplay.

2 thoughts on “prevent a logoff from happening if a specific program is running”

Leave a Reply

Your email address will not be published. Required fields are marked *