[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
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
Medium Priority
?
2,133 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

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!

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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