[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Use the form_unload  module with an application

Posted on 2007-10-20
5
Medium Priority
?
524 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:Darkstriker69
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 20116697
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
 
LVL 5

Author Comment

by:Darkstriker69
ID: 20116736
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 20116761
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
 
LVL 5

Author Comment

by:Darkstriker69
ID: 20118030
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
 
LVL 5

Author Comment

by:Darkstriker69
ID: 20161924
I finally manipulated a VB program that works for what I need, thanks for the links.

Darkstriker69
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

872 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