TheTAZZone - Internet Chaos

prevent a logoff from happening if a specific program is running

ORIGINALLY POSTED BY KBERN3 FOR THETAZZONE/TAZFORUM HERE

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
'************************************************************
' PREVENT LOGOFF SCRIPT
' 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
Next
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
Else
‘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
WScript.Quit

2 Responses to prevent a logoff from happening if a specific program is running

  1. admin August 15, 2009 at 11:07 pm

    Best thing to do is to join our forum and ask the experts there. 😀

  2. Charles Mander August 12, 2009 at 8:10 am

    when I turn computer off it says a program is still running. How do I find out what program this is?

Leave a Reply

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

Advertise

If you'd like to advertise on The Mutt ( aka TheTAZZone.com ) feel free to contact us at: administration[at]thetazzone.com

TheTAZZone is a non-commercial entity. We do not sell any products or services ourselves. Our revenue comes from advertising and donations only.

We appreciate your support! Your advertising revenue ( or donations ) helps us to continue to upgrade, improve, and offset the costs of maintaining this site.

Donations can be made through the page ' Donate '.