The VBScript Network and Systems Administrator's Cafe


September 4, 2008  4:01 PM

Pinging a remote computer from another remote computer using the WMI Win32_PingStatus class in VBScript

Jerry Lees Jerry Lees Profile: Jerry Lees

I recently began working on trying to figure out ways to troubleshoot real problems with a VBScript and give me some diagnostic information about the current state of the environment. As I build this script I plan on sharing pieces of it bit by bit with you, my readers. I also wanted to get back to writing some WMI scripts that will help you all do your jobs more efficiently. Lastly, I wanted to begin building a “toolbox” script that you could use to write your own scripts. These are the goals I’m tracking toward in my next series of posts that contain VBScript code. Now onto this script…

The first piece of troubleshooting a problem, in my opinion, is ensuring that a communication path exists between two systems. Duh! However, simply pinging the systems individually from your desktop isn’t a good test… it only tests the your computer can communicate with the two systems, not that they can communicate with each other!

This script simply uses our friend WMI to make a call a remote computer requesting that computer ping another computer. Simple enough, but invaluable because how many times have you had to login to a remote computer to check if it can connect to a system? Now you don’t have to… you can do it from a script!

The script uses the Win32_PingStatus class in WMI. Essentially, it will only work on Windows XP and newer (Sorry, Windows 2000 and older doesn’t support the WMI class we need.) and the user executing the script will likely need to be an administrator on the system that is being called (but not necessarily being pinged). For further information on this class you can reference the Win32_PingStatus documentation.

Now lets get to the script!

 ‘Use a remote computer to ping another remote computer
Option Explicit
 
‘Change the SourceServer and RemoteServer Strings below to servernames or IP addresses for you.
wscript.Echo RemotePing(“SourceServer”, “RemoteServer”)
wscript.Echo “Done!”

Function RemotePing( SourceComputer, DestinationComputer)

 Dim strComputer1, strComputer2
 Dim objWMIService, colItems, objItem

 strComputer1 = SourceComputer
 strComputer2 = DestinationComputer

 On Error Resume Next
  ‘ error control block
  Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}//” & strComputer1 & “\root\cimv2″)
  Set colItems = objWMIService.ExecQuery (“Select * from Win32_PingStatus ” & “Where Address = ‘” & strComputer2 & “‘”)
  For Each objItem in colItems
      If objItem.StatusCode = 0 Then
          RemotePing = strComputer1& “: Reply received from ” & strComputer2 & ” in ” & objItem.ResponseTime & ” ms.”         
      Else
       RemotePing = “Error pinging ” & strComputer2 & ” from ” & strComputer1 & “. The status code returned was :” & objItem.StatusCode
      End If
  Next
 On Error GoTo 0
End function

As always, this code works perfectly. However, sometimes the formatting of the blog breaks the code if you copy and paste it into your editor. So, if you’d like to not type or troubleshoot any syntax errors due to the copy and paste problems– I’ve provided the code for download, plus example output files  from my final tests for you. You’ll find the code and other files available for download from my website’s (www.websystemsadministration.com) File Depot under the ITKE Blog Scripts category. Enjoy and happy scripting!

September 2, 2008  3:44 PM

Google’s new browser, Chrome scheduled for release today

Jerry Lees Jerry Lees Profile: Jerry Lees

Well, the blogosphere is currently in a frenzied state about the new Google Chrome browser– and there still isn’t a download page for it. It’s gotten to such a point that even searching Google won’t bring up a link for the browser from google itself– which is actually kind of funny if you think about it.

I’ll be posting information to this article as it becomes available throughout the day, so check back often or bookmark the page to get the latest information on thenew Google Chrome Browser.

 It appears that for a time there was a download page, tons of sites link to it but the page simply redirects you to the google home page at this time. I’ve seen some speculation that the response was overwhelming Google’s servers… I doubt that seriously. I’m betting it is simply sheer marketing, generate a frenzy and release it later. The official google blog has a posting yesterday claiming the release to the public was an accident… oops.

 At any rate, while the browser isn’t available to download yet, I did manage to find some Chrome screenshots that were not hosted on google’s site– and are still available to view over at pcworld.

There’s more to come as information becomes available. For now, the best information I’ve seen is that the download is supposed to be available at 2pm EST and will be available at the  Google Chrome Page. but while you wait, you can read the comic they put out that supposedly explains how it works.


August 29, 2008  2:04 PM

VBScript Statements: Explanation of the Randomize Statement

Jerry Lees Jerry Lees Profile: Jerry Lees

The Randomize statement seeds the VBScript random number generation engine with a new seed. A seed is a user defined value that helps create a random number.

There are no options for the Randomize statement, it’s use is simply:

Randomize


August 27, 2008  6:12 PM

Essential Tools: A free undelete utility that actually recovers files effectively

Jerry Lees Jerry Lees Profile: Jerry Lees

Please note: This is a re-posting of a previously deleted post, details to come. 

The next tool I’d like to share with you in my Essential Tools series is another useful tool from a company called Piriform, who created a free drive defragmenter tool in the series, Defraggler.

This tool, Recuva, is an excellent file recovery tool— hence the name Recuva, which is pronounced like recover. Recuva is easy to use and quite impressive in it’s ability to recover files.

It first presents you with a wizard that, if you chose to use it, will guide you through the selection, scanning, and recovery process. Once it has scanned your drive it presents you with a list of files that were deleted– along with their recover ability in plain English! Simply select the files you need to recover and then choose to recover them and your on your way to getting back to that game of Halo with your co workers!

So why not take a second an run over and download the application and give it a shot– It’s FREE!!!

Know of a tool that you think is essential? Post a comment here and if I don’t already have it in my tool belt, I’ll add it and give it a shot. If it makes the grade– I’ll add it to the list of tools to review. The only criteria are:

  1. The tool must be free, or inexpensive with a “Per User” type license. (No pay per installation licenses, please)
  2. The tool (or it’s installation file) must be small enough to fit on a 256Mb flash drive for portability.
  3. Command line run time options are beneficial, but not required.
  4. If it has ads… it needs be truly INVALUABLE.
  5. It should make the user’s job easier by gathering information or preforming a task that a typical Network or Systems Administrator would preform.

Enjoy!


August 22, 2008  2:23 PM

Essential Tools: A FREE File Level Drive Defragmenter

Jerry Lees Jerry Lees Profile: Jerry Lees

Please note: This is a re-posting of a previous post that was deleted, further details to come.

The first tool I want to call out in my Essential Tools series, and the inspiration for the series, is one from a company called Piriform the tool is one that I’ve been looking a long time for… a real drive defragmenter.

As a systems administrator, I’m sure you know defragmentation can kill the performance of a system and that it doesn’t take long before a drive is defragmented! Plus, you probably know the frustration of spending hours defragging a drive to only find out that after defragging one, maybe two or three, times that there is still a file with hundreds of fragments!

I absolutely hate that! Three hours out of my life and the best you can do is leave a file with 878 fragments?!? I’m from back “in the day”, when DOS 6.22’s defrag utility actually defragged the hard drive and also did a file level defrag.

Sure there are some apps that do that, but they charge out the nose for the software and, lets face it, not everyone works at a fortune 500 company with a million dollar software budget to spend on disk defragmentation software.

There is a tool that does this, does it quite well, and better yet is FREE! This tool is called Defraggler.

It will defrag your drive, like most other defrag software applications, but it goes one step further… It will allow you to choose an individual file to defragment!

Plus, for those of you that are batch scripters or command line people (nothing wrong with that), there’s a command line tool installed that they don’t mention, df.exe, in addition to the standard Windows version!

Straight from the command line help we see how powerful this can be if you have a file or folder that has heavy disk activity:

df C:
Defrag drive C:

df “C:\Program Files”
Defrag “C:\Program Files” folder.

df “C:\Program Files” /S
Defrag “C:\Program Files” folder and recurses into sub folders.

df “C:\Windows\*.exe”
Defrag all executables inside “C:\Windows” folder.

So check it out, I’m sure you’ll find it to be one of those tools that you simply add to your tool belt or boot disk.

Until next time….


August 21, 2008  2:25 PM

Essential Tools: A free tool to mount an ISO cdrom or DVD image as a Virtual CDROM drive

Jerry Lees Jerry Lees Profile: Jerry Lees

We’ve all had times when we needed a file from an installation CD or DVD, but only had an ISO image available on the network. So, we have to copy the image to our machine then burn the image to media– just to get the file.

There are utilities out there that do this, like Alcohol 120%, but none seem to be free and free from ads or “Value add toolbars”. (Alcoholsoft makes Alcohol 52%, but it has toolbars). I’ve recently found a free utility that does fit the bill for my free essential tools series!

The tool is Virtual CloneDrive from Slysoft. Virtual CloneDrive delivers all the functionality you need to mount an ISO as a virtual CD/DVD Drive in a small (1.86Mb for a full install) FREE package! (As a added benefit, it appears to have multi-language support as well)

Once installed it adds a Virtual CDROM drive to your system that has a menu context “Virtual CloneDrive” that gives you the Mount and unmount options, just like Alcohol 120% does. And it keeps track of your recent ISO’s like Alcohol 120% as well.

It also registers .ISO files with itself and simply double clicking on the file automatically mounts the image in your virtual drive, a nice touch.

All in all, the performance is good and the integration with windows is top notch. Give it a shot, I’m sure you’ll find it to be one of your essential tools.

Know of a tool that you think is essential? Post a comment here and if I don’t already have it in my tool belt, I’ll add it and give it a shot. If it makes the grade– I’ll add it to the list of tools to review. The only criteria are:

  1. The tool must be free, or inexpensive with a “Per User” or “site” type license. (No pay per installation licenses, please)
  2. The tool (or it’s installation file) must be small enough to fit on a 256Mb flash drive for portability.
  3. Command line run time options are beneficial, but not required.
  4. If it has ads… it needs be truly INVALUABLE.
  5. It should make the user’s job easier by gathering information or preforming a task that a typical Network or Systems Administrator would preform.

Enjoy!


August 18, 2008  5:48 PM

Essential Tools: Determining disk usage graphically with free tools

Jerry Lees Jerry Lees Profile: Jerry Lees

The next essential tool is one that I have used for quite some time now, and one I searched to find for some time. As a systems administrator, its an ever ending battle for you to keep space clear on the servers. It’s a battle that puts you smack in the middle of the users who are using all the space and the management who refuses to buy more space. Additionally, management all to often refuses to place a mandate on how old data is before it is free to delete.

 This tool won’t help you delete files, but it will tell you really quickly where exactly the space is being used for any particular volume… even if it is a UNC path on your network mapped to a network drive!

This tool, spacemonger, is a tool that will show you this in a visual representation by size where space is being used. It allows you to drill down into directories to see more detail and gives you shortcuts via a context menu to common tasks you would preform on a directory.

SpaceMonger truly is an essential tool. The 1.x version I’ve linked to is older, but free and it gets the job done. Additionally, a newer version is available that has more features and is relatively cheap. Go ahead, check it out… I’m sure you’ll add it to your essential tools!

Know of a tool that you think is essential? Post a comment here and if I don’t already have it in my tool belt, I’ll add it and give it a shot. If it makes the grade– I’ll add it to the list of tools to review. The only criteria are:

  1. The tool must be free, or inexpensive with a “Per User” or “site” type license. (No pay per installation licenses, please)
  2. The tool (or it’s installation file) must be small enough to fit on a 256Mb flash drive for portability.
  3. Command line run time options are beneficial, but not required.
  4. If it has ads… it needs be truly INVALUABLE.
  5. It should make the user’s job easier by gathering information or preforming a task that a typical Network or Systems Administrator would preform.

Enjoy!


August 17, 2008  2:02 AM

VBScript Statements: Explanation of the ReDim Statement

Jerry Lees Jerry Lees Profile: Jerry Lees

The ReDim statement in VBScript allows you to declare a array, or a multi-dimensional array, in your code. Also, this statement allows you to re-declare the number of elements in the array at a later time in the code.

This is important because it also allows you to release memory or allocate more memory for use in your script.

As you use this statement, be sure to use the Preserve keyword if you wish to preserve the existing data in the array.

Below are examples:

Dim x(10)
ReDim x(15)


August 13, 2008  2:29 PM

Essential tools: Wget, a command line tool to retrieve web pages

Jerry Lees Jerry Lees Profile: Jerry Lees

There is nothing more annoying than having a web server or site down and IE (or FireFox, for that matter) become dog slow or simply getting in the way of trouble shooting the page. Additionally, sometimes these browsers actually get in the way of troubleshooting the problem by masking the error page the server sends back– IE’s “friendly” HTTP errors messages, for example. When it comes right down to fixing the problem, sometimes you need to retrieve just the HTML code a particular web page sends simply for inspection or analysis. That is where our next essential tool comes in!

Wget is a small (~325K) command line utility that allows you to download a HTTP, HTTPS, or FTP file quickly from the command line and save it locally so you can open it with a text editor, simply have it in an alternate location, or use in a comparison to what a specific browser renders after download. Wget for windows can be downloaded here. It’s a powerful tool, and covering all the options in one posting isn’t possible, so let’s start off with a little syntax to get you rolling:

In its  simplest form you can download a specific page, including a full URL, as shown below:

wget http://www.gamersigs.net

Alternatively, you can download a site and all its linked items recursively to a specific number of levels. This is useful to archive a site or  to simply grab pages that the HTML uses, but doesn’t link to directly– Cascading Style Sheets (css) for example. The syntax below will recursively get 2 levels of www.msn.com and automatically create a directory called www.msn.com in the current directory.

wget -r –level=2 http://www.msn.com

If the page links to a HTTPS page, wget will automatically try to negotiate a SSL connection. You can optionally specify the SSL protocol to use by adding –secure-protocol=PR, where PR is either auto, SSLv2, SSLv3, or TLSv1. This is especially helpful in testing and ensuring your servers do not respond to the weaker SSLv2 SSL protocol.

If you deal with websites as a part of your Systems Administration duties– or if you’re just interested in it as a side project at the office, I’m sure you’ll add this tool to your essential tools.

Know of a tool that you think is essential? Post a comment here and if I don’t already have it in my tool belt, I’ll add it and give it a shot. If it makes the grade– I’ll add it to the list of tools to review. The only criteria are:

  1. The tool must be free, or inexpensive with a “Per User” or “site” type license. (No pay per installation licenses, please)
  2. The tool (or it’s installation file) must be small enough to fit on a 256Mb flash drive for portability.
  3. Command line run time options are beneficial, but not required.
  4. If it has ads… it needs be truly INVALUABLE.
  5. It should make the user’s job easier by gathering information or preforming a task that a typical Network or Systems Administrator would preform.

Enjoy!


August 9, 2008  1:57 AM

VBScript Statements: Explanation of the While … Wend Statement

Jerry Lees Jerry Lees Profile: Jerry Lees

The While conditional statement is useful because it allows you to repeat a block of code as long as a conditional test is True, rather than just a simple number of times. It is useful in situations where you need to loop through code, but do not know how many times yo need to run the portion of code.
 
Keep in mind that you must end While statements with a Wend statement.

Here is an example:

test =0
While test<100
     test = test +1
     Wscript.echo test
Wend


 


Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: