The VBScript Network and Systems Administrator's Cafe


January 16, 2009  1:56 AM

Word Tip: Quick and easy tables in Microsoft Word

Jerry Lees Jerry Lees Profile: Jerry Lees

This isn’t a VBScript tip— or even a systems administrator tip. However, it is a valuable tip on a quick easy way to create tables in word that are EXACTLY the size you need without knowing ahead of time and doing a lot of clicking in the menus… and if your like me with the number of tables you have to create for documentation this tip is a life saver!

Essentially, You Type the rows like you would a normal sentence except between where you want the columns you place a tab. When the row is completed, instead of pressing ENTER to start a new row… press SHIFT ENTER to start a new row. Then, end the table by simply pressing ENTER.

Finally, highlight the text you wanted to make into a table and select “Make Table” or “Insert Table” from the menu in Microsoft Word, depending on your version. TAHDAH!!!

Here is an example:

This is a cell “Tab” in a row “Tab” that is the first row “Shift Enter”
This is another cell “Tab” in another row “Tab” that is the second row “Shift Enter”
This is a cell “Tab” in the last row “Tab” that is the end of the table “Enter”

It should look like this after you select to Insert the table:

This is a cell in a row that is the first row
This is another cell in another row that is the second row
This is a cell in the last row that is the end of the table

January 12, 2009  1:46 AM

Windows Tip: Moving a window from off screen back into view

Jerry Lees Jerry Lees Profile: Jerry Lees

If you’ve ever hooked up your laptop to a secondary monitor and then disconnected without remembering to move the windows back to the primary desktop, you’ve probably encounted this problem: 

The application is running. You can see it in the taskbar, but you can’t see it on the screen, because it still thinks it’s running on the secondary monitor. You try and use right-click, Move, but that doesn’t do anything, and the window doesn’t move anywhere. Maybe you try doing a minimize and then a restore… but still the window doesn’t come into a area of the screen you can actually use. Likely, you simply end up rebooting.

There’s a simple trick to get around this. First make sure you’ve clicked on the windows to bring it into focus. Then right-click on the taskbar and choose Move, then hit any one of the arrow keys and simply move your mouse.

TAAADAHHH!!! Enjoy!


January 8, 2009  2:18 AM

Essential tools: Fiddler Web Debugger, Display HTTP packets LIVE without a packet sniffer

Jerry Lees Jerry Lees Profile: Jerry Lees

You may have been thinking I had forgotten about this series of articles since I haven’t posted to it in a while. Nope! Just haven’t run across anything that was truely aazing enough to be an “Essential Tool”. Well, I recently found just that web I had to troubleshoot a application that was making calls to a web service.

The tool i was lead to is Fiddler, the Web Debugger!!! If you’re like me and you have to trouble shoot web applications that make web service calls– you’re going to LOVE fiddler. No more digging through logs to determine problems real time, especially since IIS caches the log data and writes it in chunks.

Fiddler displays the HTTP (and HTTPS) traffic originated from a machine it is ran on and then shows the cooresponding response from the server you connected with in the request. It’s a real life saver, especially if your not certain the packet is well formed for a SOAP web service on the other end. As an added bonus, Fiddler also allows you to see the raw HTTP (or HTTPS) headers and response headers.

Best of all it’s FREE!!! (We’ll it cost me a $250 call to Microsoft to find out about it… but the application is free and for you the information is free!) Try it out— TODAY!


January 5, 2009  2:03 AM

Retrieve environment variable values from a remote system with WMI

Jerry Lees Jerry Lees Profile: Jerry Lees

Back in October I shared with you a way to retrieve environment variables with a script titled Using Environment variables inside a VBScript script. The script worked like a champ and got me through several tight binds in gathering information, hopefully it has for you as well. However, it has one flaw… it doesn’t work on a remote system! In fact, it only works on the system that the script is running on.

So, I had to recently go back to the drawing board and create a script and series of functions that would work remotely so that I could wrap it in a function to gather information from a bunch of servers. I also Learned a thing or two in the process!

First, The script uses the Win32_environment classes in WMI and this class returns ALL envirnment variables for ALL users. That threw me for a loop when I saw multiple PATH environment variables– some that were different. Second, The search is case sensitive without using the SQL % wildcards (I didn’t need them, so implementing that is left up to you the reader.)

I have the three functions I wrote, that are really variations of one another below. Just add them to your script and call them with the appropriate values and you should be in business!

Function RemoteAllEnvironmentVariables(ServerName)
     ‘Lists all environment variables on the remote system
    
Dim objWMIService, colItems, objItem
 
     RemoteAllEnvironmentVariables = “”
     Set objWMIService = GetObject(“winmgmts:\\” & ServerName & “\root\cimv2″)
     Set colItems = objWMIService.ExecQuery(“Select * from Win32_Environment”)
     For Each objItem in colItems
         RemoteAllEnvironmentVariables = RemoteAllEnvironmentVariables & objitem.name & “: ” & objItem.VariableValue & VbCrLf
     Next
End Function

Function RemoteAllEnvironmentVariablesVariations(ServerName, VariableName)
     ‘Lists all environment variables on the remote system, along with every case variation
     Dim objWMIService, colItems, objItem
 
     RemoteAllEnvironmentVariablesVariations = “”
     Set objWMIService = GetObject(“winmgmts:\\” & ServerName & “\root\cimv2″)
     Set colItems = objWMIService.ExecQuery(“Select * from Win32_Environment”)
     For Each objItem in colItems
         If UCase(objItem.name) = UCase(VariableName) Then
         RemoteAllEnvironmentVariablesVariations = RemoteAllEnvironmentVariablesVariations & objitem.name & “: ” & objItem.VariableValue & VbCrLf
         End If
     Next
End Function

 
Function RemoteEnvironmentVariable(ServerName, VariableName)
     ‘Lists all environment variables on the remote system, exactly as you typed it in the function call.
     Dim objWMIService, colItems, objItem
 
     RemoteEnvironmentVariable = “”
     Set objWMIService = GetObject(“winmgmts:\\” & ServerName & “\root\cimv2″)
     Set colItems = objWMIService.ExecQuery(“Select * from Win32_Environment Where Name = ‘” & VariableName & “‘”)
     For Each objItem in colItems
         RemoteEnvironmentVariable = objItem.VariableValue
     Next
End Function


January 2, 2009  3:01 AM

Searching the Windows Eventlog for specific events with WMI

Jerry Lees Jerry Lees Profile: Jerry Lees

On occasion as a systems administrator you have to find the proverbial needle in the haystack with respect to the events in the event logs. You know what I mean, the one event you care about and need to know when it occured as part of your troubleshooting… then throw in that you need to do it in many servers. That’s a mess!

Sure, you can use event viewer and pull out some superadmin skills to filter the events to only see the ones you want– but your still only looking at one server at a time! Yes, you could export the events from multiple servers to a CSV file and then compile them into one excel spreadsheet– but that would take hours to do.

What if I told you there was a way to do it with VBScript? How much would you expect to pay? Three easy payments of 19.99?? … WAIT, don’t answer because it’s FREE!

The script below calls a function it defines called GetLogInfo to gather the requested event information to standard the standard output (the console). The function uses the Win32_NTLogEvent class from— you guessed it, our life long friend WMI! It accepts four inputs, in order; a string that is the name of the server, the Event ID that you are looking for, the specific application log you want to search, and the date in YYYYMMDD format. (Hint: if you have custom event logs on your server, or it is a DNS server or a Domain Controller, you can specify the name of the log instead of Application, System, or Security to get at the log information.)

Here is the script I wrote:

GetLogInfo “ServerName”,”1309″, “application”, “20081218″

Function GetLogInfo( StrComputer1, EventID, EventLogType, YYYYMMDD)

    Dim objWMIService, colItems, objItem
    Dim TempStr

    On Error Resume Next
    ‘ error control block
    Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}//”_
    & strComputer1 & “\root\cimv2″)
    Set colItems = objWMIService.ExecQuery (“Select * from Win32_NTLogEvent Where EventCode=” &_
    EventID & ” and logfile=’” & EventlogType & “‘”)
    For Each objItem in colItems
        TempStr = “”
        If mid(objItem.timegenerated,1,8) = YYYYMMDD Then
            TempStr = objItem.message
        End if
    Next
    On Error GoTo 0
End Function


December 29, 2008  3:21 PM

Using special characters in VBScript strings

Jerry Lees Jerry Lees Profile: Jerry Lees

I just realized I’ve been using Visual Basic String constants in my scripts with little to no explanation. We’ll rectify that situation right now! ;-)

When dealing with strings in VBScript, you occasionally need to add formatting characters to a string, so that when it is displayed on the screen or in a file it looks correct. If you know your ASCII chart you can certainly preform this with a “& chr(X) &”.However, if you don’t know what ASCII value a tab is (it’s 9) then you can simply use Visual Basic’s string constants in your scripts and have the added benefit if making it easier to read!

The constants and their meanings are listed below:

VBTab A Tab character [Chr(9)]
VBCr A carriage return [Chr(13)]
VBCrLf A carriage return and line feed [Chr(13) + Chr(10)]
vbBack A backspace character [Chr(8)]
vbLf A linefeed [Chr(10)]
vbNewLine A platform-specific new line character, either [Chr(13) + Chr(10)] or [Chr(13)]
vbNullChar A null character of value 0 [Chr(0)]
vbNullString A string of value 0 [no Chr code]; note that this is not the same as “”


December 26, 2008  2:42 PM

Fun with the Registry: Saving ODBC Entries from a server (and moving them to a new server)

Jerry Lees Jerry Lees Profile: Jerry Lees

On occasion you have to rebuild servers, some are worse than others to rebuild. Much like my previous post on moving file and print shares, Web Servers are not that difficult to rebuild, but one of the tedious tasks in moving a web server is setting up all the ODBC entries that have been added over time all at once. you know the drill:

Point. Click. Click. Click. Add. Double check settings. Click OK.  Pray it’s right.

Well, all the ODBC enties on a system are actually in the registry! You can save a TON of time– and be lazy! — by simply exporting the proper key in the registry and importing it to the new server! (Note: This just moves the OBDC entries… you’ll want to be extra careful that all the ODBC Drivers imported are actually installed on the server and probably are the same versions)  The registry key is:

HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI

Keep in mind… your editing the registry on your fresh new server… so I’ll once again blatantly copy Microsoft’s stereotypical disclaimer:  ;-)

Caution, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow the steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:

322756  (http://support.microsoft.com/kb/322756/ ) How to back up and restore the registry in Windows


December 23, 2008  3:12 AM

A useful site that contains a Microsoft SQL version information database

Jerry Lees Jerry Lees Profile: Jerry Lees

I don’t get the occasion to manage SQL servers in a DBA role any longer, like MrDenny in his blog, nor have I been a true assigned DBA– I’ve only worked at places where the database servers were treated like any other server. Basically, mine to manage. Those of you in small to medium enterprises know what I’m talking about… If it plugs into the network it’s a Network/Server admin’s responsibility.

Now my role is more along the lines of Supporting the web applications that use the services that the database servers provide. Leaving the DBA role up to the folks assigned the title of DBA. Oh, how I used to think that would be so much easier! But that was when I imagined a team of folks who thought and worked like I did… Instead on occasion you get the folks on the other team who don’t believe a problem exists.

Well, I’ve recently found a site that really comes in handy in determining if SQL patches have been applied or if they may be relevant to an article you are reading that looks promising over at SQLSecurity.com that  is a database of SQL Server patches that helps you determine if a patch is relevant to your installation or not.

Hopefully, this will help you out in your challenges!


December 18, 2008  12:06 AM

Fun with the registry: Saving shares and share permissions from a server (and moving them to a new server)

Jerry Lees Jerry Lees Profile: Jerry Lees

On occasion you have to rebuild servers, some are worse than others to rebuild. File Servers are not that difficult to rebuild, but one of the tedious tasks in moving a file server is setting up all the shares that have been added over time all at once. you know the drill:

Point. Click. Click. Click. Add. Double check settings. Click OK.  Pray it’s right.

Well, all the shares and the share permissions that are associated with each share are actually saved in the registry! You can save a TON of time and look like a super hero IT professional– and be lazy! By simply exporting the proper key in the registry and importing it to the new server! (Note: If your drive letters change you will need to update the paths in the registry to get them to work.)  The registry key is:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares

Keep in mind… your editing the registry on your fresh new server… so I’ll blatantly copy Microsoft’s stereotypical disclaimer:  ;-)

Caution, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow the steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:

322756  (http://support.microsoft.com/kb/322756/ ) How to back up and restore the registry in Windows


December 15, 2008  5:41 PM

Essential tools: A useful tool to remove dead favorites links from your bookmarks

Jerry Lees Jerry Lees Profile: Jerry Lees

As a quick addition to my additional tools series I wanted to share with you a great utility I found in the past few weeks that helps to manage old bookmarks.

If you’re like me, you have tons of bookmarks in your book marks and it’s There’s nothing worse than trying to weed through them to find that the item you have bookmarked is no longer there where you bookmarked it! I found a great tool called AM-Deadlink that is freeware!!! (Yes, it fits into the requirement I have for an essential tool that the tool be either cheap or free!) Seems like a handy tool to me, since I just spent hours going through bookmarks to delete old, no longer available bookmarks, in all my book marks!

Directly from the website it says “AM-DeadLink detects dead links and duplicates in browser bookmarks and text files. If a bookmark has become unavailable you can verify and delete it permanently.”

Check it out here!


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: