0

I want to know how to give a warning message to user using VB Script when he tries to shutdown or sleep windows and continue if he really want to do it.

I am currently wish to use such script in Windows 7 64 bit system.

How to do this using VB Script?

GTAVLover
  • 1,407
  • 3
  • 22
  • 41

2 Answers2

1

You are talking about hooking into Operating System to trigger the script when a shutdown is initiated. This type of functionality will not work well with a scripting language like VBScript which is designed to be lightweight and has no hooks into the Windows API.

This type of task is better suited to a fully featured language like C++, C# etc. If you are familiar with VBScript, you might have some success using VB.Net due to the similarity in syntax.

Closest you will get with VBScript is having the script itself initiate the shutdown rather than hooking into the Windows API, which is discussed in the question Yes/no shut down.

Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175
0

This could work. Found this answer here and modified it to work for you.

`Set WshShell =CreateObject ("WScript.Shell")

Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process")

Function CheckForProccess()

For Each objProcess in colProcessList

If objProcess.name = "shutdown.exe" then

vFound = True

End If

Next

End Function

If vFound Then

msgbox("Warning: Your PC will shut down soon")

Else

CheckForProccess()

End If`