How do I open multiple message boxes in vbs? - vbscript

I know that if you input
Do
msgbox("This is a msg box")
loop
Then a msg box pops up that won't go away.
I want multiple message boxes that you ARE able to close.
How do I do this?

You want to look for non-modal dialogs. The msgbox that you pop-up here are modal, that's why they come one after the other (execution is suspended while the dialog is open).
You will find references for this on the web.
Func _NoHaltMsgBox($code=0, $title = "",$text = "" ,$timeout = 0)
Run (#AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(' & $code & ', '''& $title & ''', '''& $text &''',' & $timeout & ')"')
EndFunc

WARNING: You're probably going to encounter severe lag and or crashing. I am not held responsible of any damages if you choose to continue.
You can make a batch file that opens the same VBS script many times.
Make a notepad with:
msgbox("YourTextHere")
Or if you want to loop it:
do
msgbox("YourTextHere")
loop
Replace YourTextHere with whatever you want.
Then save it as .vbs
then make another notepad:
start "MessageBox" "MessageBox.vbs"
Change "MessageBox" with the name of the message box VBS you made.
Copy and paste the same script multiple times to open it more times (Do this at your own risk, you may encounter severe lag).
Then save it as .bat
Or add the batch file itself multiple times so it can create a loop of opening batch files which can open more scripts out of them. (Do this at your own risk, you may encounter severe lag).
For example:
start "BatchFile" "Batchfile.bat"
Change "BatchFile" with the name of the Batchfile you made.
Copy and paste it multiple times to open it more times again (Do this at your own risk, you may encounter severe lag).
So far, you're okay since you did not open the .bat file. IF you try testing it, It'll open multiple instances of your .bat file and the message box, then open more instances off the new instances, then more instances off the even newer instances, and repeat enough to make your PC crash or lag.

If you don't want to use a batch file, try this:
Step 1 - the error message
Let's say you wanted a=msgbox("messageboxtext"). So, in Notepad, you would write a=msgbox("messageboxtext") and save it as a .vbs file.
Step 2 - the spammer
Infinitely
In a new Notepad document, paste this:
set shell = createobject("wscript.shell")
count = "hello world"
do until count = 1
shell.run("""C:\Users\user\Documents\error.vbs""")
loop
Replace C:\Users\user\Documents\error.vbs with the location of the file. Save it as a .vbs file.
Finitely
To open a finite number of windows, use this code:
set shell = createobject("wscript.shell")
count = 0
do until count = 5
shell.run("""C:\Users\user\Documents\error.vbs""")
loop
Replace the 5 with the number of times you would like the message to spawn. Enjoy!

You need a multiple button MsgBox, set it as a value then: if CANCEL is pressed, the process will stop.
Do
spam=MsgBox("SPAM",3)
If spam = 2 Then
WScript.Quit
End If
Loop

First make an File called "anything.vbs" replace anything with anything you want.
Then Edit it and Put in the Code
msgbox("LOL")
loop"
Replace LOL with anything you Like.
Then make a .bat File.
Put in the Code
start "LOL.bat"
loop"
Now you have a Spammer. :)

Related

Alert on operation completion in windows cmd

Using windows cmd I have to put large programs on compilation which take large amount of time. Everytime to know whether operation is complete or not I have to check cmd again and again. I want to know whether there is way by which I can make changes to cmd such that it gives me a signal that operation has been completed by playing sound or by opening a dialog etc.
Please share if anyone has some idea
There can be many ways to achieve this
This is the easiest
While your code is compiling (ie compiling has just began) in the same cmd prompt
type " ctrl + G " and press enter this will go to the input stream of cmd and will wait there until it can be executed , ctrl +G is the BEL character which gives you a single beep when you execute it .
You can also enter multiple BEL characters to get multiple beeps upon completion of the task.
A harder way could be , to write a python script that executes the compilation command say "g++ my_prog.cpp" and upon completion plays a sound or give you a simple popup notification via a windows message box.
Include in yout batch file
msg console /time:3600 "The task has ended"
Send a message to the console and keep it open (if not closed by the user) 3600 seconds (if not indicated there is a 60 seconds timeout).

VBScript onTimeout then function

I have a VBScript I am working on that uses another object.
Sometimes that Object will get stuck. My VBScript code will hang on that line until it's "done". When it times out, I want to send the .Close command to the Object before the VBScript closes.
How can I tell when my VBScript times out?
I know that I can put WScript.Timeout = 60
Maybe something like..
WScript.Timeout = 5
do while true
loop
sub WScript_timeout()
msgbox("OK")
end sub
By setting the Timeout property you instruct the interpreter to automatically terminate the script when the timer expires. This is the same as running the interpreter with the option //T:xx and can't be caught/handled from within the script. What you want requires the ability to run code asynchronously, and VBScript doesn't really support that.
The real answer (to the question "How can I tell when my VBScript times out?") is that you can't. In common with almost all scripts, if VBScript stops running (because it's timed-out) the running thread ceases to run, so it can't report its status.
But there is a solution. However, it requires some cunning.
If you run a batch script instead, wherever you use that script to launch a new batch script (e.g. batch_1.bat includes this line: CALL batch_2.bat), the 2nd script will run, but the 1st script will wait.
Processing of the 1st script sits and waits (at the CALL) until script 2 stops running: at that point, control is returned to script 1, which continues with any code following the CALL, code which might be used to report the fact that script 2 has ended -
CALL batch_2.bat
ECHO The batch_2.bat script has stopped running && cmd /k
There are ways of launching batch_2.bat without causing batch_1.bat to pause until the 2nd script has finished, but they are not relevent here.
Theoretically, a batch script doesn't support parallel processing. VBScript certainly doesn't either. But the foregoing technique shows one method whereby parallel processing can be achieved, after a fashion, in a batch script -- which makes it one-up on vbScript!
.
One way to be certain that vbScript will time out, if the script hangs, so that the script must either complete successfully or fail (so you are never left with a frozen script due to it "hanging"), is to use a WScript function in your .vbs file and set the Windows Script Host settings to time out after (say) 30 seconds -
A. Open the "Windows Script Host Settings" dialog box:
Go to: Start > Run
In the "Open" box, type: WSCRIPT
Click "OK".
B. Set a timeout, to occur whenever WSH runs:
Select the option: "Stop script after specified
number of seconds".
In the "seconds" box, type the time limit to be
applied to all scripts (default is 10 seconds).
.
Here's a function to find and show what the current WSH/WScript timeout setting is (and if it shows that this setting hasn't been set yet, set it) -
WScript.Echo("WSH timeout: " + WScript.Timeout);
.
The option //T:xx can't be used, because it's a CScript function, which doesn't work in WScript, so can't be used in a .vbs vbScript file.
.

HTA - VBScript - Install program but wait for installation to complete

If you could give my a hand that would be great?
I have a HTA file nothing to fancy its to install a few programs one by one
I have been reading in a few places on how to wait for installation to complete
then install the next program but none make sense to me for what i want, also
they are saying to use wscript.sleep that would be great but it doesnt work in a HTA right ?
I have firefox, utorrent, symantec antivirus, adobe reader, office 2003 (packaged with KEY already)
and a few others.
i want to find switches to install silently but thats not important if this code someone is willing to show me works...
I hope I make sense ?
If you can help me it would be great ?
Cheers Pavle.
You might find something useful in my answer (https://stackoverflow.com/a/3742182/128427) to this question: How to get an HTA to restart itself?
It uses a VBScript helper to wait for a process to end (the HTA itself) then restarts the HTA. You could modify the vbscript instead to wait for a specific process to end (one of your installers), then return control to the HTA which starts the next installer and calls the wait script again.
I don't think an HTA can call the WScript.Sleep routine, but there are the setTimeout and setInterval methods in HTA that call a routine after X seconds, or repeatedly call a routine after every X seconds until cancelled. You can use these to check periodically if a process is still running (using WMI Win32_Process as I show in my other answer).
To process a list of items like this, instead of using a loop to go through a list and pause after each item, you have a central state-machine routine that calls itself every so often to advance the system.
'!! extremely "pseudo" pseudo-code follows
sub StartSystem()
state = "next program"
list = list of programs to install
AdvanceSystem()
end sub
sub AdvanceSystem()
if state = "next program"
if more items in list
start next installer
remove from list (or increment an index)
set state to "check program"
else
set state to "done"
if state = "check program"
use WMI to see if process is still running
if no
state = "next program"
if state <> "done"
setInterval(AdvanceSystem, 5000) ' call again in 5 seconds
end sub
' then somewhere in your HTA interface have a button to start things off
buttonClick = StartSystem()
Using an arrangement like this you may not even need to run a separate VBScript to check the process and sleep. Also, with this kind of incremental process, you can send output to a DIV somewhere so the user can see progress, whereas when processing things in a loop, output doesn't show up until the whole process has finished. After each pass through AdvanceSystem, the control returns to the HTA level and the system can update itself.
Let me know if you need a more specific example, I'll try to write something up.

getting a batch file to open the next file before the last one is closed

I've never had this happen before and I've used dozens of batch files before so I'm stumped. I'm executing the batch on windows 7.
My batch file reads exactly as follows:
"C:\Users\MYOB\Desktop\ISSP Project\Learning Objectives.docx"
"c:\users\MYOB\desktop\comp\unit2.pdf"
"C:\Users\MYOB\Desktop\course.bat"
What I would like is for all three files to open up. The behaviour I get is that the first file will open, the command prompt window will remain open with the text showing the execution line visible, and until I close the file that was just opened the next one will not open.
This behaviour seems to specifically relate to PDF files, I can open a hundred at a time of any other filetype, but for a pdf it waits for me to close the first file.
How can I work around this?
You can use start like this
start "" "C:\Users\MYOB\Desktop\ISSP Project\Learning Objectives.docx"
start "" "c:\users\MYOB\desktop\comp\unit2.pdf"
start "" "C:\Users\MYOB\Desktop\course.bat"
Although the blank quotes aren't strictly necessary for the last 2, it will save you getting caught out if you add more that have spaces in the path.

TextStream.AtEndOfStream sometimes is never true

I have a vb script that processes text files on a server, however, very occasionally without any apparent reason, the script gets stuck in a loop.
Files are uploaded by clients via ftp (smallish about 2 - 10 kb), a .Net service that is watching the ftp folder kicks off an executable (written in VB6), the executable moves the file from the ftp folder to a folder where it is processed. At this point the exe kicks off the vb script. 98% of the time the script runs without issue.
When the infinite loop occurs I kill the exe process. The odd thing is that when I re-kick off the process manually (by copying it back to the the folder that's being watched) the exact same file it goes through without issue.
In short the script opens the file into a text stream then it loops through the TextStream object until its AtEndOfStream property is true. Within the loop it creates a new file with some additional information added, now whenever the infinate loop situation occurs the temp file doesnt contain any of the sourcefile data, just the extra data added by the script, for example, the following code works 98% of the time:
Do While ts.AtEndOfStream <> True
sOriginalRow = ts.ReadLine
sUpdatedRow = sOriginalRow & ",Extra_Data"
NewFile.WriteLine sUpdatedRow
Loop
So if the source file contains:
LineALineBLineC
The new file is created conbtaining:
LineA,Extra_DataLineB,Extra_DataLineC,Extra_Data
but when the problem occurs and the new file is instantly populated with thousands of rows of
,Extra_Data,Extra_Data,Extra_Data,Extra_Data,Extra_Data...
its as though the AtEndOfStream property never becomes true.
My initial thought is that the source file is getting corrupted somehow but when these source files are reprocessed they are fine. Another thought is that the textstream object is getting incorrectly created, and not picking up the new line character, maybe because the file is locked by another process or something.
The only way I have found to replicate the behaviour is to comment out the ReadLine part of the code, which in effect prevents the current line number from incrementing. e.g.
sOriginalRow = "" 'ts.ReadLine
Can anyone offer any suggestions?
Well, as you say, the only thing I can offer are suggestions, not real answers:
Maybe your stream bumps against an ObjectDisposedException (not catchable in VBScript), so the EndOfStream condition gets <> True but not False.
For the sake of the experiment, you could try to change Do While ts.AtEndOfStream <> True to Do While Not ts.AtEndOfStream or Do Until ts.AtEndOfStream but my bio-logical circuits tell me that is probably not going to work.
There is another problem described where the stdIn and stdErr are conflicting with each other causing a hang in particular situations.
Could you also please answer the comment of Tmdean. On Error Resume Next could create a real mess: If ts.AtEndOfStream returns Null or garbage (because ts was destroyed for example) it will not become True and will cause a loop in Foreverland.

Resources