LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Run exe and afterwards run VBScript

Solved!
Go to solution

Dear LV Champions,

I am writing a program to run an exe file of an application and afterwards press the 'ON' key through Visual Basic Script. I can successfully run the exe file and if I use following code below (Save as vbs file and run it), i can press start key of the application. But the requirement is to run it automatically. After launching application, visual basic script code should run and press the 'ON' key.

VBScript code:

set shell = createobject("wscript.shell")
wscript.sleep 200
success = shell.appactivate("SwitchBox-USB")
if success then shell.sendkeys "{tab}"
wscript.sleep 400
shell.sendkeys "{enter}"

Screenshot of application:

switchbox.JPG

 

Thanks in advance for valuable suggestions.

 

Khan.

0 Kudos
Message 1 of 11
(6,255 Views)

Hi,

 

I'm not a LabVIEW Champion, but hopefully you'll forgive me for replying anyway!

It sounds like what you want to do is call that VBScript code from within LabVIEW after running the first frame of your Flat Sequence Structure in the VI you uploaded. If that's correct, then I think this forum thread is what you need!

 

In that thread, the participants discuss calling VBScript code, and DanyAllard provides a picture showing how he has called VBScript code.

 

For your case, I think this should work, but I can't check since I don't have the executable or any knowledge of its calling requirements (like the path twice that you show here). I removed the FSS since you can use error wires to sequence instead!

runProg.png

 


GCentral
Message 2 of 11
(6,233 Views)

Dear Cbutcher,

Thanks for your quick reply. I tried to open attached VI but it is LV16 while i am using LV14. Anyhow, i implemented the same using your provided link. I got following error 'Exception occured in run-time error in Microsoft VBScript: Object Required: 'wscript' in Run Program.vi'

 

error.JPG

 

Can you kindly guide me why it's appearing.

Thank you so much.

 

khan.

0 Kudos
Message 3 of 11
(6,221 Views)

Dear zahid,

 

i encountered the same error when testing your script. Instead of using activex, i directly called the wscript.exe using the system executable and providing the path to your vbs script. I added an Echo to check wether the script will run, which it did.

 

Simply call the following line with the System Exec.vi:

wscript.exe "yourfilepath"

 

 

Fabian Wehnekamp
Senior Technical Support Engineer
National Instruments
0 Kudos
Message 4 of 11
(6,194 Views)

I couldn't find out why the VBScript didn't work properly - I also think Fabian's solution is probably the best/simplest.

Good luck! 🙂


GCentral
0 Kudos
Message 5 of 11
(6,189 Views)

Dear Fwehne,

Thanks for your reply. I have implemented what you suggested (As far as i understand). But still giving error. Attached is VI and the Code is saved as *.vbs file naming 'ON'. I run the app manually before running this VI.

Code:

set shell = createobject("wscript.shell")
wscript.sleep 200
success = shell.appactivate("SwitchBox-USB")
if success then shell.sendkeys "{tab}"
wscript.sleep 400
shell.sendkeys "{enter}"

 

Kindly guide if i am doing it wrong. Thank you so much.

 

Khan.

0 Kudos
Message 6 of 11
(6,185 Views)

Dear Cbutcher,

Thanks for your reply. I tried to put the script into a function like 'Function test.... (Script).... End Function'. When i run it, it does not give any error, but also does not perform its task. So it might be some initialization stuff need to put in which i don't know (I don't have knowledge of VB Scripting). Anyway, thanks for your valuable solution which put me close to solution.

 

Thank you so much.

Khan.

0 Kudos
Message 7 of 11
(6,183 Views)

You should only use a string input for the system executable, with the text you currently use as a path input :). The code snippet you attached should be used for calling your executable. Simply use a string constant and wire this directly into a second system exec.vi.

Fabian Wehnekamp
Senior Technical Support Engineer
National Instruments
0 Kudos
Message 8 of 11
(6,180 Views)

Dear Fwehne,

 

Thanks for your reply. Is this what you are trying to say?

 

Code.JPG

I tried this, but not working. Can you kindly elaborate your point?

 

Thanks,

 

Khan.

0 Kudos
Message 9 of 11
(6,174 Views)
Solution
Accepted by topic author zahidkjatoi

Hi Khan,

 

i have attached a short example project (saved for LV 8.6), which loads a modified version of your vbs script, with an included Echo for test purposes. The project loads the script from from a relative path, so you can execute this directly. If a popup from the Windows Script Host with the text "Like this?" shows up, the vbs script is called correctly. If your button press is not executed as you wish, you have to rework your vbs sript.

 

Cheers

Fabian Wehnekamp
Senior Technical Support Engineer
National Instruments
Message 10 of 11
(6,169 Views)