The VBScript Network and Systems Administrator's Cafe:

December, 2008

Dec 29 2008   3:21PM GMT

Using special characters in VBScript strings



Posted by: Jerry Lees
strings, String manipulation, string, working with variables, Special Characters, ASCII, VBScipt

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 “”

Dec 26 2008   2:42PM GMT

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



Posted by: Jerry Lees
webmaster, Web applications, migrating a web server, rebuilding a webserver, ODBC, ODBC entries, migrate ODBC entries, registry, fun with the registry

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


Dec 23 2008   3:12AM GMT

A useful site that contains a Microsoft SQL version information database



Posted by: Jerry Lees
SQL Server, Server Patching, Essential sites, web tools, Microsoft SQL Server

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!


Dec 18 2008   12:06AM GMT

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



Posted by: Jerry Lees
registry, tips and tricks, File Server, Migrating Servers, Lanmanserver, File Shares, fun with the registry

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


Dec 15 2008   5:41PM GMT

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



Posted by: Jerry Lees
essential tools, bookmark, bookmark management, tools, am-tools, web tools

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!


Dec 11 2008   2:39PM GMT

How to fix a pesky stuck pixel in a LCD monitor



Posted by: Jerry Lees
How to, repair tips, Fix an LCD Monitor, tips and tricks, Stuck Pixels, LCD Monitor Repair

Recently I got a new LCD Monitor– or at least it was new to me. And much to my dismay there were a few pixels on it that were stuck on. I was somewhat dismayed to see it, but couldn’t complain because I got a really good “3am ending auction deal on eBay”– so I started to fiddle with it and found this article that was talking about “How to Fix a Stuck Pixel on an LCD Monitor.” I’d never heard about “massaging” a stuck pixel to get it to work, but it works like a charm with the help of a java applet called JScreenFix and a couple of seconds turning the screen on and off while massaging the screen with a soft cloth.

If you’ve got stuck on pixels give it a try and report back to the rest of us on how it worked!


Dec 8 2008   10:54PM GMT

A great XMLDOM online reference for creating XSLT Translation documents



Posted by: Jerry Lees
XML, XSLT, XMLDOM, Online References

If you were interested in my previous posts relating to XML and XSL Translations. You’ll know how difficult it is sometimes to get the syntax right and know what functions are available to you when writing a XSLT document to translate a XML file into HTML.

Well, I recently found a great reference for XML’s XMLDOM interface. Check it out,


Dec 4 2008   9:22PM GMT

Using WMI’s WIN32_Process class to remotely kill a process



Posted by: Jerry Lees
VBScript, kill, win32_process, Kill processes, pkill, kill process

Recently I had a situation where I had to kill a number of processes on a number of servers in a short period of time so we could update the executable file quickly so the processes could be safely respawned. This presented a challenge because it needed to be done quickly both before users respawned the process multiple times on each server and because the number of servers involved did not lend itself to simply logging onto the server and killing the processes one server at a time.

So I pulled out the scripting hat and went to work making use of the WMI Win32_Process class to create the following function that gets passed the process name you want to kill and the remote server name where you want to kill the processes.   Worked like a champ! One hitch was that there were users still on the server, but that was solved by simply running the script multiple times while we copied the new files to the servers.

So, here is the function I spoke about… hopefully you can add it to your list of script tools in your scripting tool belt!
Function RemoteKill( StrComputer1, ProcessName)

    Dim objWMIService, colItems, objItem

    On Error Resume Next
    ‘ error control block
    Set objWMIService = GetObject(”winmgmts:{impersonationLevel=impersonate}//” &  strComputer1 & “\root\cimv2″)
    Set colItems = objWMIService.ExecQuery (”Select * from Win32_Process Where Name = ‘” & ProcessName & “‘”)
    For Each objItem in colItems
        RemoteKill = RemoteKill & VbCrLf & strComputer1 & “: “
        RemoteKill = RemoteKill & objItem.name & “(PID: ” & objItem.processid & “) Terminated.”
        ObjItem.terminate
    Next
    On Error GoTo 0
End Function


Dec 2 2008   12:55AM GMT

Very simple encryption example with VBScript



Posted by: Jerry Lees
encryption, VBScript, 3des, string, encrypt, Toolkit, String manipulation, decrytption, mid, StrReverse, Reverse Strings, decrypt, RSA

I previously mentioned a routine that I wrote to encrypt a string. Now, before the security folks look at the code… understand this:

This is intended only to obscure a string from a casual prying eye. It is NOT intended to be a replacement for true encryption like 3DES and RSA encryption. Please do NOT assume this routine is in any way secure or uncrackable. It is intended to only be an exercise in working with strings and is only as secure as the price you have paid for it. Nothing. ;-) Furthermore, it is provided as-is without warranties and by using it you agree that all risk from it’s use is transferred to you.

….Now that we’ve gotten the unpleasant legal disclaimer out of the way… Lets discuss the code!

Essentially, The code uses a variable length key to obscure the original string by iterating through the string you want obscured and adding the ASCII value of the character at each position of the original string with the ASCII value of a rotating “key character” in the key provided to generate a new ASCII value. This new ASCII value is then converted to a character and added to the newly encrypted string. The obscured string is further obscured by the fact that the original string is reversed prior to being changed. 

This key position changes after each character in the original string is obscured. The result is the key is iterated through sequentially as the original string is encrypted and when the end of the key string is encountered the iteration through the key string is started again from the beginning of the key string until the original string is completely encrypted.

This process works because the ASCII values in the typical string and the typical key string when added together do not exceed 255. (The highest possible ASCII character) Essentially, Strings and Keys with ASCII values higher than 126 should not be used or the result could be unpredictable– or worse yet, an unencryptable string.

Now that I’ve explained a bit about the premise… Lets look at the code!

Option Explicit

Dim temp, key

temp = “Now is the time for all good men To come To the aid of their fellow countrymen.”
key = “huasHIYhkasdho1″

temp = Encrypt(temp,key)
WScript.Echo temp
temp = Decrypt(temp,key)
WScript.Echo temp

Function encrypt(Str, key)
 Dim lenKey, KeyPos, LenStr, x, Newstr
 
 Newstr = “”
 lenKey = Len(key)
 KeyPos = 1
 LenStr = Len(Str)
 str = StrReverse(str)
 For x = 1 To LenStr
      Newstr = Newstr & chr(asc(Mid(str,x,1)) + Asc(Mid(key,KeyPos,1)))
      KeyPos = keypos+1
      If KeyPos > lenKey Then KeyPos = 1
 Next
 encrypt = Newstr
End Function

Function Decrypt(str,key)
 Dim lenKey, KeyPos, LenStr, x, Newstr
 
 Newstr = “”
 lenKey = Len(key)
 KeyPos = 1
 LenStr = Len(Str)
 
 str=StrReverse(str)
 For x = LenStr To 1 Step -1
      Newstr = Newstr & chr(asc(Mid(str,x,1)) - Asc(Mid(key,KeyPos,1)))
      KeyPos = KeyPos+1
      If KeyPos > lenKey Then KeyPos = 1
      Next
      Newstr=StrReverse(Newstr)
      Decrypt = Newstr
End Function