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
1,984 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
  • 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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now