Solved

How to use Visual Studio to debug a VBS script ( error: Unable to attach to the crashing process.  The process has been terminated.)

Posted on 2008-10-03
9
2,065 Views
Last Modified: 2012-06-21
I'm trying to debug a VBS in Visual Studio 2005 and I've done this before.  For some reason my current attempts keep failing and I don't get it.

Ideally I will debug this script locally as I launch it from a remote machine for which I have access.  Example:

cscript \\ServerXyz\Projectn\MyVbsScript.vbs //x

This script has no parameters and it doesn't matter whether I run it locally or not - I get the same thing.  Also, I know there is nothing wrong with the script because it runs every day on various machines to do the job it does.  I want to debug it to understand what it does.

Please advise as to how I can debug this script.  I'm thinking I should be able to browse to the script, attach it and debug it!!

Thanks!
0
Comment
Question by:John500
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 9

Accepted Solution

by:
gregcmcse earned 500 total points
ID: 22637275
I actually have never tried to use Visual Studio to debug VBScript, but here is an article that seems to detail the process:
http://krestenm.blogspot.com/2007/12/vbscript-projects-in-visual-studio2.html

I've typically found that if I remove or remark out all "on error resume next" commands that I find the problem pretty rapidly.  If you must have that to get around a particular quirk of code, then put an "on error goto 0" right after you check for the error so that your code will throw the error it should to tell you where things are going awry.
0
 

Author Comment

by:John500
ID: 22637629
Appreciate the input.  Can you test on your own machine any simple script using VS 2005?

The thing that is bugging me is that I've done this before just about three months ago.  It's not the script that's causing the problem, I'm sure it's the way I'm calling the script from the command prompt:

cscript \\ServerXyz\Projectn\MyVbsScript.vbs //x

What's the difference between wscript and cscript?  Maybe that's the way I was doing it ......
0
 

Author Comment

by:John500
ID: 22637755
What's happening is the script runs regardless and does the job it is supposed to do.  The problem is that although the cscript .... //x qualifier/syntax does launch the debugger dialoge, the debugger doesn't 'attach' .... but the script really never crashes.  See the screen shot below:
cscript-error.JPG
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:John500
ID: 22637948
I see the fundamental problem as being there is no existing 'project' for the debugger to work with.  Given this constraint the ' cscript ... //x ' syntax attempts to attach the process (vbs script) to the debugger as if it had an existing project.  This is what is failing.

Thus, I attempted to work around this problem by creating a VB Console project and I changed the extension of the module from VB to VBS.  After I did this I pasted all the code I'm trying to debug into the module.vbs file.

I then tried to build the project but I received the error message below.  Since I'm new to vbs I'm not sure exactly how I should modify the code to accomodate this error.  Is this a simple modification?

Thanks
vbs-project.JPG
0
 
LVL 9

Expert Comment

by:gregcmcse
ID: 22638011
I don't think that's going to fix the problem, but you can try it.

In your VBScript, after you declare any global variables, add a line that says "call Main" ("call" isn't necessary, but is good form).  Then surround the rest of the loose code in your script with:

Sub Main()

    ' all loose code here

End Sub ' Main

0
 

Author Comment

by:John500
ID: 22638261
When I try to build I get:

Error:  Sub Main was not found

The code looks like this:

Globals here .....

Call Main()

Sub Main()

          loose code here

End Sub 'Main

Any ideas why it wouldn't like this?

Thanks
0
 

Author Closing Comment

by:John500
ID: 31502884
This was the ticket thanks!  From work the pictures wouldn't display for the procedure given in the blog.  Thus, I didn't even give it a try.  However from home I was able to see the pictures and was able to create the VBS project.

Thanks again!
0
 
LVL 1

Expert Comment

by:advapp
ID: 35039209
Just in case someone else comes along and finds this question, there is another instance where this message occurs.  I have been debugging WSF/JS/VBS code for years without needing to create a project.  However, when I went to Windows 7 x64, I encountered this same error message when I tried to debug a script with the //X //D at the command line.

The problem is that VS2005 is still a 32-bit application and, by default, a command window in an x64 edition of Windows is the 64-bit version (C:\Windows\System32\cmd.exe).  To debug, you need to use the 32-bit version of the command-line (C:\Windows\SysWOW64\cmd.exe).  This works fine and I just created a short-cut in my programs to point to either of the two flavors of cmd.exe.
0
 

Author Comment

by:John500
ID: 35044872
Appreciate the heads-up !
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

724 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