Contents for Guy’s Scripting Ezine 33 – Troubleshooting
- This Week’s Secret
- Troubleshooting Strategy
- Syntax Errors
- Logical Errors
- 4 VBScript Troubleshooting Methods
I am on the horns of a dilemma. If I tell you that I have encountered 18 different syntax errors in my scripts, then you will think that I am accident prone. However, if I tell you there are 53 different syntax errors with VBScript and I have only seen 18 of them, then you may think that I do not know much!
In fact, I have created a whole section of my website dedicated to WSH Error Codes WSH 0800 error codes .
It’s no secret that problem solving skill comes with experience. If you have seen the error code before, then it becomes easier to understand the cause of the current problem. What I seek to do in this issue is to bottle that know-how and give you some short cuts to troubleshooting.
Guy Recommends: The Free IP Address Tracker (IPAT)
Calculating IP Address ranges is a black art, which many network managers solve by creating custom Excel spreadsheets. IPAT cracks this problem of allocating IP addresses in networks in two ways:
For Mr Organized there is a nifty subnet calculator, you enter the network address and the subnet mask, then IPAT works out the usable addresses and their ranges.
For Mr Lazy IPAT discovers and then displays the IP addresses of existing computers. Download the Free IP Address Tracker
When I am asked to troubleshoot scripts, my first piece of advice is break down the script into manageable chunks. When we are hunting down the problem, let us make sure that at least we are looking in the right field. My strategy is to get each section working, then to reassemble the parts into the original big long script.
Finding and interpreting clues is ultimately what solves the problem. The main source of information comes in the form of a WSH Error Message box. What cuts down the search area is to deduce what is causing the error. The first fork in the decision path is to decide if we are looking for a syntax error or a logical error.
When you are dealing with a syntax error, check to see if there is a spelling misnake in a method? Alternatively, is there a missing or inappropriate, !punctuation mark?
Confirmation of a syntax error comes from two sources in the error message. Firstly, the WSH error message will show a runtime error the last line of the WSH message box. Secondly, while there are 53 possible syntax errors, they all begin with Code: 0800Axxxx, so you should be able to separate them from logical errors which usually begin with 08007xxxx..
This category covers all manner of sins. Firstly, it could be that the drive letter is already in use? Secondly, perhaps the server is down or the name that you typed does not exist?
Where you suspect a logical error the question to ask is: ‘Could there be a fault in the network, or is it a pure scripting oversight?’ For example, does server \\ alana exist? How many arguments does MapNetworkDrive require? Probing, by asking ‘what happening here’, will develop the classic troubleshooting technique of framing a question that only has two possible answers.
Perhaps the most disconcerting problem is when the script does not work, but there is no error message. If you are assigning your script through group policy, then what has happened is this, the user or computer is not in the OU where you have assigned the policy. If you know that the user is in correct OU, then refresh with gpupdate on XP, secedit on Windows 2000 pro.
- Option Explicit
- On error resume next
- Wscript.echo “The script completed “
- A good script editor e.g VBsEdit
1. Option Explicit
Good scripting technique will reduce errors. Prevention is better than cure, so start with Option Explicit. What this statement does is to force you to declare variables, for example Dim objNetwork. If you later try and use obbbjNetwork, Option Explicit will throw up an error 800A01F4, ‘Variable is undefined’ and so stop you committing a logical error.
2. On error resume next
This is not the cure all that it may seem. The best use of ‘On error resume next’ is where a server is unavailable and you wish the other parts of the script to complete.
Top script writers add error controlling sub-routines, for example, the ‘ON error’ command. What I find is that for relatively simple logon script we (I) do not have the time for proper error handling routines. (Perhaps I should get into better habits.)
3. Wscript.echo “The script completed “
I have to say that one of the defects of VBScript is that it does not have a good debugger. However judicious Wscript.echo statements can help to reveal what is happening. As you may know, I love to add variables to my scripts. For example Wscript.echo “This drive was mapped ” & Driveletter. Where Driveletter is my variable corresponding to say, K:.
4. A good script editor e.g OnScript
What a good script editor will do is firstly tell you the line number and character, so you do not have to waste time counting down 73 lines, (including blanks), to find the error message. Script editors also color code methods, Set commands and more, this helps by giving you visual clues when something is wrong, or when you have corrected the error.
Troubleshooting in general, and correcting VBScript 0800 errors in particular improves with experience. However, by methodically applying problem solving tactics you can increase the chances of your scripts doing what you planned.