Question

Return to calling VBS from HTA

Asked by: Netman66

Well....it looks like it's my turn to ask a question - WooHoo! :o)

I am developing a method for our imaging that PXE boots to WinPE, launches a VBScript to run wpeinit, map a drive and call up an HTA where you can select an image to apply to the workstation.  All this works fine, the HTA runs, my choices are captured via radio buttons and checkboxes and Ghost32 is run with the proper commandline switches.  

The issue I'm having is when the Ghost client finishes, it closes then the HTA closes - which *should* return control to the originating VBScript to execute the next line in the script.  However....the calling script throws an error:

Start.vbs (37, 1) (null): The operation was canceled by the user.

Now, I've started the HTA using several methods - objShell.Run "x:\windows\system32\mshta.exe s:\scripts\menu.hta",3,True - seems at least wait for something to happen with the HTA (either a Self.Close, Window.Close or killing the mshta process) before continuing, but the error above happens no matter what method I use to exit the HTA.

I have other things in the calling script that execute, wait and then continue after completion just fine.  It's only this return from the HTA that has greatly reduced the existence of hair on my head.

Is there any method at all I can leverage short of including the VBScript I need to launch after the HTA closes within the HTA itself?  I don't like that last idea given how I have to maintain things.

Code gurus, I'm all ears ('cause I have no more hair)!! LOL.



This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-10-16 at 09:27:29ID23821073
Tags

vbscript,hta

,

IE

Topics

VB Script

,

VB Controls

,

VB Objects

Participating Experts
1
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. vbscript drop down/hta?
    I have a vbscript that gets input and puts into a variable, I want to have one of the input boxes read a variable from a drop down list, etc. from several items then put that into a variable. Does anyone have such a script done in vbscript or would this have to be done thr...
  2. HTA\Vbscript question
    I have this code as a part of a larger script in a HTA: CreateObject("Wscript.Shell").Run("cscript notepad.exe c:\temp\temp.txt") The problem is, this works fine on the local machine. But if I launch this HTA from another remote machine (the HTA is hosted...
  3. Hta script that can run as another Hta file.
    Hi, Hta script that can run as another Hta file. I want an Hta that will ask for the Domain,User name & Password and open another Hta with that permissions. Does anyone have a script as this. REgards Sharath
  4. Convert VBscript to HTA
    I have ported a working VBscript printer listing script to try and pickup HTA...however, after making all the changes, as best I could determine, I get 2 errors... 1 on line 77, which is blank...but I believe the error is on line 78 the function line saying a syntax error ex...
  5. HTA array
    I have the below VB Script as part of a subroutine in a HTA. At the moment it populates the select box "lst_groups" with the 5 AD groups that I've defined. Instead of objOption.Text to be derived from the AD group name, I need it to be five strings of text defined ...
  6. VBS to HTA Conversion
    I want to convert the below code to HTA.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: RobSampsonPosted on 2008-10-16 at 13:36:49ID: 22735500

Hi netman,

Is this line 37?
objShell.Run "x:\windows\system32\mshta.exe s:\scripts\menu.hta",3,True

it seems a strange error to have from that line.....

You can shorten that to just
objShell.Run "mshta.exe s:\scripts\menu.hta",3,True

because mshta.exe is a system file.

Also, if your HTA path happens to have spaces, use
objShell.Run "mshta.exe ""s:\scripts\menu.hta""",3,True

Regards,

Rob.

 

by: RobSampsonPosted on 2008-10-16 at 13:51:29ID: 22735621

Or......perhaps that line 37 is in your HTA, and the HTA is trying to close while it is still executing some code?

 

by: Netman66Posted on 2008-10-16 at 15:21:02ID: 22736303

Hi Rob,  thanks for flying Netman!

Line 37 is from the calling script and is the next line after:

objShell.Run "x:\windows\system32\mshta.exe s:\scripts\menu.hta",3,True

objShell.Run "cscript.exe s:\scripts\ai-ph1.vbs",2,True  <<= this is the line it's complaining about.

I'll have to post the code tomorrow - it's at the office, but there is something in the way the HTA or mshta.exe process ends that kills the calling script (start.vbs).  When an external process is spawned from within a VBScript, does it become a child process or a process of it's own?  I'm wondering if it runs under the PID of the cscript process and when I kill mshta it kills the whole PID.  Does that make any sense?





 

by: RobSampsonPosted on 2008-10-16 at 15:39:01ID: 22736422

Hmmm, I can't see why that would fail.....

To answer your PID question.....I used Process Explorer to look at the tree when I ran the code segments below....

The first script will spawn separate processes for any external programs run, which do not seem to be dependant on the parent process running.  If I kill the highest process in the tree, the HTA stays running.

Anyway, I can run the below three code files without error....

So I'm not sure just yet why you'd have an issue......

Regards,

Rob.

' ==================================
' ==================================
'          START OF TEST1.VBS
' ==================================
If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
    strPath = Wscript.ScriptFullName
    strCommand = "%comspec% /c cscript  """ & strPath & """"
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run(strCommand), 1, True
    Wscript.Quit
End If
 
Set objShell = CreateObject("wscript.shell")
WScript.Echo "Running testhta1.hta"
objShell.Run "mshta.exe ""c:\temp\temp\test script\testhta1.hta""",3,True
WScript.Echo "Running test2.vbs"
objShell.Run "cscript.exe ""c:\temp\temp\test script\test2.vbs""",2,True
MsgBox "Finished"
' ==================================
'          END OF TEST1.VBS
' ==================================
' ==================================
 
 
 
' ==================================
' ==================================
'          START OF TESTHTA1.HTA
' ==================================
  ' Code irrelevant....any HTA with
  ' an exit button that uses Window.Close
  ' will do...
' ==================================
'          END OF TESTHTA1.HTA
' ==================================
' ==================================
 
 
 
' ==================================
' ==================================
'          START OF TEST2.VBS
' ==================================
WScript.Echo WScript.ScriptName & " is now running..."
MsgBox "Press OK to terminate this script."
' ==================================
'          END OF TEST2.VBS
' ==================================
' ==================================

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:

Select allOpen in new window

 

by: Netman66Posted on 2008-10-16 at 16:24:10ID: 22736715

Interesting....

Let me fill in a few holes in my original post - perhaps there is a difference that is relevant to you.

I startup a new workstation and hit F12 to PXE boot.
It boots up from the network into WinPE - all the modules are loaded in PE (WMI, Scripting, XML and HTA).
Startnet.cmd loads, by default, as the shell - so I'm using it.
Starnet runs one line - cscript x:\Windows\start.vbs (which is embedded into the PE wim).
Start.vbs launches WPEINIT.exe (waits), maps a network drive (waits), runs the HTA from the mapped drive (waits).
The HTA parses the mapped drive (in a certain folder) and dynamically creates buttons based on the top level folders in this location.
When a button is pressed, it parses the contents of that folder and dynamically creates radio buttons for each .gho image it finds.
When one of those radio buttons is selected a new button is created to start the imaging process using Ghost (embedded in the wim) and builds the commandline from the radio choices you make in the HTA.
Ghost launches and attaches to the Ghostcast server session name that is built above.
The image is brought down to the machine and Ghost exits.
The HTA exits.
The next line of code in the Start.vbs is supposed to execute, but the error in the original post is presented in the CMD window that was originally launched by Startnet.cmd.

So, the process is a bit weird but goes something like this:

Startnet.cmd > run Start.vbs > Run Wpeinit.exe (wait) > Map Drive > Run HTA (wait) >> HTA runs Ghost32.exe (which itself opens a CMD window to run itself - kinda different...) > Ghost32 exits > CMD window that launched Ghost exits > HTA exits > apparently the Start.vbs exits due to an error > error is presented in CMD shell started by Startnet.cmd.

I wonder if running the HTA from the network is influencing the problem?  Perhaps WinPE Scripting isn't up to the task of running it on a real OS?  Dunno....

As you can tell, I don't write Apps for a living.  I'll script for Administration, but do not normally get invloved in anything that resembles an App.  This is my first shot at creating an HTA based on one I found on the Internet and modifying it to do what I need it to.  For the most part, each component of this process works fine it's only when I attempt to run it all together sequentially that I'm running into unforseen problems.

Thanks for your time so far Rob.



 

by: Netman66Posted on 2008-10-16 at 16:27:59ID: 22736733

Sorry, type here:  Perhaps WinPE Scripting isn't up to the task of running it on a real OS?

Should have read: Perhaps WinPE Scripting isn't up to the task of running it like a real OS is?

 

by: RobSampsonPosted on 2008-10-16 at 16:43:44ID: 22736825

Hmmmm.....OK, so first off I'm wondering if CScript.exe actually executes properly in WinPE.....

Try my files out, using this as your HTA.

See if that gets to the cscript.exe OK....

If not, then you may have to use WScript.exe (or whatever happens to run a VBS by default, maybe a different implementation on WinPE).

Regards,

Rob.

<Html>
<Head>
<Title>Test HTA</Title>
 
<HTA:Application
Caption = Yes
Border = Thick
ShowInTaskBar = No
MaximizeButton = Yes
MinimizeButton = Yes>
 
<script Language = VBScript>
	Sub Exit_HTA
		Window.Close
	End Sub
</script>
<body>
	<button name="btn_exit" id="btn_exit" accessKey="x" onclick="vbs:Exit_HTA">E<u>x</u>it</button>
</body>
</head>
</html>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:

Select allOpen in new window

 

by: RobSampsonPosted on 2008-10-16 at 16:44:30ID: 22736830

In short, though, it seems like that sequence would work in theory, but let's just narrow it down a bit....

 

by: Netman66Posted on 2008-10-16 at 16:51:38ID: 22736872

OK, I'm game.  I'll test this out tomorrow when I have a PE environment to work from.

If you send me an email at my alias here at gmail then I'll send you the scripts I'm using tomorrow - I don't want some of the info in them public (and scrubbing them would defeat the purpose if you need them to work).

I'll also report back with the results of this test.

Again, thanks Rob!



 

by: RobSampsonPosted on 2008-10-16 at 17:06:18ID: 22736944

OK.  I don't have a WinPE environment that I could test in, so let's try to work without sending whole scripts....just relevant parts around problem areas are fine.

In the test code I gave above, we're pretty much emulating what you've got, just shortened it a bit, so hopefully we can get some results out of it....

Rob.

 

by: Netman66Posted on 2008-10-16 at 17:14:50ID: 22736978

It's close - the HTA calls Ghost from itself, but the principal should tell us if the HTA exit still kills the originating script.

I'll be all over this first thing in the morning.  I'm in AST so I don't know what time difference we have.

 

by: RobSampsonPosted on 2008-10-16 at 17:45:32ID: 22737084

It's currently 11:45am here....Victoria, Australia.

I may not be available tomorrow, as that will be Saturday for me.......I'll see what I can do....

 

by: Netman66Posted on 2008-10-16 at 17:50:51ID: 22737095

Ahh!  I had no idea!

I have a friend, a peer MVP in Sydney - James Kindon.

Glad to have you assisting.

We'll take it a day at a time - no worries.

 

by: Netman66Posted on 2008-10-17 at 04:54:05ID: 22739588

OMG........

You're not going to believe the ridiculously noob error I made in my script....

I tested my solution with your simple HTA - same results as I was getting previously.

Here is the line that was giving me the original error (objShell defined earlier in the script).

objShell.Run "S:\Scripts\AI-Ph1.vbs",2,True

After looking at this issue for hours, a good night sleep is all I needed to spot the problem as soon as your HTA did the same thing.

The line should have been:

objShell.Run "cscript S:\Scripts\AI-Ph1.vbs",2,True

This is a perfect example of why you should take a break after long hours of scripting.  You look at the same error over and over but it never strikes you as being incorrect.

Rob - I have to thank you for your patience and making me THINK.  I hope I can get your assistance for future problems in VBScripting.

Now to start looking at regrowing my hair!

Cheers,
NM


 

by: Netman66Posted on 2008-10-17 at 04:58:17ID: 22739607

The kicker here too is that I typed that problem line perfectly correct when I was posting it here in my first reply to you.  Unreal....

 

by: Netman66Posted on 2008-10-17 at 05:01:58ID: 31506829

Rob - without a doubt, you are a first class person.  Thanks for being professional and not making me feel as dumb as I appear to be!! LOL..

 

by: RobSampsonPosted on 2008-10-17 at 15:42:00ID: 22746038

>> The kicker here too is that I typed that problem line perfectly correct when I was posting it here in my first reply to you.  Unreal....

LOL!  Yeah, I noticed that!  Ah well, at least you've found the issue!  Well done!

Yesterday I was writing a HTA to install a program and update some shortcuts in a folder.  It was throwing an error every time I ran, even though I knew the shortcuts were there.  I had this

For Each objFile In objFSO.GetFolder(strFolder)

which threw the error, and it me ages to remember that I needed to add .Files to the end!

It's those "not quite eyntax" errors, but just omissions that make the most frustrating errors.

Anyway, sure, throw me a line if you need VBS / HTA help.....

Thanks for the grade, and the comments....

Regards,

Rob.

 

by: Netman66Posted on 2008-10-18 at 11:08:40ID: 22749142

Hi Rob,

Yeah, those "almost" correct lines that don't really throw any useful error messages take ages to figure out.

You're welcome!

Hope to do business with you again - you could teach me a thing or two!

Cheers,
Paul

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...