VBScript question

I’m writing a VBScript that is going to execute a program, allow the users to run the program, then query them for whether to logout or shut down the machine when they are done.

I have the script pretty much written at this point but the problem is that I can’t get the script to pause when it executes the program before it pops up the message box to query the user. The thing is all running together so that the program pops up the authentication box for the .rdt session and also pops up the message box asking them if they want to reboot or logout at the same time.

What I need is some way for the program to run the .rdt session and then to pop up the query message box when the user exits the program. I’m no VBScript guru by any means but I’m pretty sure there is a way to do this. Any help would be much appreciated.

-XT

I’m no VBS guru either & it’s been a long time since I used it, but I think you need to find a RunShell function.

VBS kicks off your program and is done with that step as far as the script is concerned, so it goes to the next script step.

You have to have a function to poll the process until it’s finished if you want the script to wait till the program is finished before doing the next step.

I’d send you a copy of the one I use, but it’s VBA not VBS.
ETA: Or maybe it’s called ShellWait or something like that. I’d have to go find a copy to say for sure. Anyway, you want the VBS version of the same thing.

WScript.Sleep? That’s what I’m using atm (to basically tell the program to wait for a time before executing the message box in the background). It works…you don’t see the message box until you exit the terminal services session. It’s just kind of…cheesy I guess. I was hoping for something a bit cleaner.

Freaking RDP is driving me nuts! Can’t save user name and password without a registry change, times out without any seeming way to change the time out parameters…sheesh, you’d think it was a Microsoft product…

Oh, wait…it IS a Microsoft product. No wonder…

:wink:

BTW, appreciate the response. If you have a code snippet I can look at I would appreciate it. Just cut and paste it in the thread if you like.

-XT

I only do VB and not VBScript so some of this might not apply, but if your launched application has a reliable window caption, you could wrap a sleep 1000 and a doevents in a loop, using the FindWindow function from win32 API to watch for when the application windows is terminated, then move forward to your popup.

Public Declare Function FindWindow Lib “user32” Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

I think the one I’ve got actually gets a process handle and checks to see when it finishes, but it’s been a long time since I looked at it.

I’ll try to remember to paste it in tomorrow morning when I’m back at work.

.RDT file? Do you mean .RDP file? If so, and you are just “running” the .RDP file directly, the shell is probably finding the program to open the RDP file with (mstsc.exe), starting it up, and returning to you immediately. What may help is to actually give the entire command line as “mstsc yourfile.rdp”, so that you’re actually specifying a program to run instead of just a file to open.

Even if you do that, there is likely more than one API for execing a program. I’m not too familiar with VB, but I’ve done some WSH, and in that environment, there are two similar shell functions: exec, which always returns immediately and returns an object that lets you query the subprocess, and run, which can optionally return immediately or wait for the subprocess to exit. You could use the WSH object (it’s called WshShell) or look into whatever equivalents are built into VB.

Google

Here’s a bunch of ready-made VBS to do what you’re wanting. Some of them use the WSH that ntucker mentioned. I think these will help more than the VBA code I’ve got; looks like they do the same thing.

Hope that helps!