Use the form_unload module with an application

I am not a programmer but I need to accomplish the following.

I need a VBscript to:

Start a program (ie. notepad)
detect when a user loggs off or shuts down (possibly with form_unload)
Type some charactors in notepad before it actually exits

Sample code is a must as I am terrible at coding

Thanks,

Darkstriker69
LVL 5
Darkstriker69Asked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Well....to detect logoff/shutdown you need to use some Win APIs to register yourself as interested in those messages.  Unfortunately you can't do that from within VBScript (.vbs).  You need to use a more powerful language...  =\

VB.Net 2005 Express and C# 2005 Express are both FREE from Microsoft:
http://msdn2.microsoft.com/en-us/express/default.aspx

Either language is capable of achieving what you need and we could easily provide samples for those languages.  The complexity level will go up significantly here though...

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
This will be terribly difficult (if not impossible) to accomplish in VBScript (.vbs).

What are you trying to achieve here anyways?  Why type characters into NotePad before the system logs off or shuts down?  Won't it just be lost?

Do you have any other development tools available to you?...such as VB6, VB.Net 2005 Express, C# 2005 Express, Delphi, C++, etc...
0
 
Darkstriker69Author Commented:
True, it would just be lost. I figured I could derive the actual code I need from that sample code.

I have wrote a script to type the neccissary charactors into an old DOS program called CATS that it needs to exit gracefully and not corrupt the database. The problem is that if I run it as a logoff script windows closes cats before my script actually runs.

So, I wanted to modify my script so that it can detect a logoff or shutdown event and exit the program gracefully.

I am not a programmer so I dont really have development tools
0
 
Darkstriker69Author Commented:
I guess since what I have is a VBscript, it makes more sence to go the VB.NET route.

So I guess what I need is a program that lauches my DOS program called CATS and when it detects that CATS is closing types "ESC" 5 times then types "Y" then allows it to exit.

I have upped the points for this questain as it is appearing to be more difficult then I first anticipated but I do need a solution for my teminal server to be functional.

Here is the VBscript I was attempting to use

pauseperiod = 1000 ' time in milliseconds
set objShell = CreateObject ("WScript.Shell")

WScript.Sleep pauseperiod
WScript.Sleep pauseperiod
WScript.Sleep pauseperiod
WScript.Sleep pauseperiod
WScript.Sleep pauseperiod
WScript.Sleep pauseperiod
WScript.Sleep pauseperiod

If  objShell.AppActivate("CATS") Then
    objShell.SendKeys "{ESC}"
    WScript.Sleep pauseperiod
    objShell.SendKeys "{ESC}"
    WScript.Sleep pauseperiod
    objShell.SendKeys "{ESC}"
    WScript.Sleep pauseperiod
    objShell.SendKeys "{ESC}"
    WScript.Sleep pauseperiod
    objShell.SendKeys "{ESC}"
    WScript.Sleep pauseperiod
    objShell.SendKeys "Y"
    WScript.Sleep pauseperiod
    objShell.SendKeys "{ENTER}"
    WScript.Sleep pauseperiod

End If

If objShell.AppActivate("CATS") Then
    objShell.SendKeys "{ESC}"
    WScript.Sleep pauseperiod
    objShell.SendKeys "Y"
    WScript.Sleep pauseperiod
    objShell.SendKeys "{ENTER}"
End If

0
 
Darkstriker69Author Commented:
I finally manipulated a VB program that works for what I need, thanks for the links.

Darkstriker69
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.