The VBScript Network and Systems Administrator's Cafe:

November, 2008

Nov 28 2008   5:07PM GMT

Reversing a String with VBScript… the easy way!



Posted by: Jerry Lees
VBScript, String manipulation, StrReverse, Reverse Strings

In a previous post, entitled Reversing a string with VBScript using the mid function, I shared a piece of code with you that reversed a string. It was simple and effective… but it’s not the piece of code I ended up using in my encryption code.

I found a much easier function built right into VBScript! The StrReverse function! It’s quite simple to use… pass it a string and it returns back to you a reversed version of that string. Here is the code I posted earlier– only using the StrReverse function:

Option Explicit

Dim MyStr, char, NewStr, x, y

MyStr = “Reverse Me!”

NewStr = StrReverse(MyStr)

WScript.Echo NewStr

Nov 26 2008   2:43PM GMT

Reversing a string with VBScript using the mid function



Posted by: Jerry Lees
VBScript, String manipulation, mid

As a part of the VBScript encryption I mentioned working on I needed to find a way to reverse a string. Doing this yielded many possibilities, but this piece of code seemed to work the best (and was the simplest) out of all the pieces of code I came up with to reverse a string.

It’s simple, but effective and you could easily wrap a function statement around it to create your own function to reverse a string. Here is the code:

Option Explicit

Dim MyStr, char, NewStr, x, y

MyStr = “Reverse Me!”

y = Len(MyStr)
For x = y To 1 Step -1
     char = Mid(MyStr,x,1)
     NewStr = NewStr & char
Next

WScript.Echo NewStr


Nov 21 2008   7:50PM GMT

Encryption and Decryption with VBScript



Posted by: Jerry Lees
encryption, VBScript, decrytption

I’ve always been somewhat interested in encryption, but never been terribly good at understanding the math behind it and couldn’t find any example code for doing encryption and decryption with VBScript… so I thought I’d write something that would atleast shield characters in a document from a prying eye. It’s not your true encryption like RSA or 3DES, but I think it would thwart a typical prying eye.

 I’ll place the code itself in a post later this week, but wanted to give everyone a chance at cracking it. So here it is… my “ecrypted” sentance:

-aÆàA»IÖàDÖ,ß_?OUÇ”º²_Dß?UO^OsÉÆU¼iE¼<ÆàOE? ¼IOµi½xUE”DODQUäÇ”-¶AÜ<ÆUO^âs^ìDA

Did you crack it? Let me know by posting a comment with the sentance in it. If you’d like post your comment along with your suggestions for improving it, if you’d like.


Nov 20 2008   11:34PM GMT

$10 off black friday purchases at Thenerds.net



Posted by: Jerry Lees
coupons, special offers

I don’t pass these along often, but this offer actually isn’t bad… so here it is!

For those of you who have not shopped at thenerds.net before– they have some pretty cool geek toys there. I recently saw a Black Friday ad from thenerds.net that was offering $10 Off Any Order for Black Friday - Cyber Monday at TheNerds.net!. Plus, they are offereing free shipping this weekend… so why not buy yourself something nice for christmas! ;-)

Forthose of you who aren’t aware, Cyber-Monday is the Monday after Thanksgiving and is when most e-retailers see a rise in shopping activity on their websites. Happy Thanksgiving to everyone!


Nov 13 2008   2:36PM GMT

Lighter Side: Irish girl wants to blow up her school



Posted by: Jerry Lees
Jokes, Prank calls

This isn’t really (OK, not at all…) VBScript related, but I recently recieved a e-mail with a link to this cute little Irish girl that was making prank calls to a demolition company about wanting to blow up her school. Well it turns out she does this for a radio program in Dublin and has several calls out there on the internet.

So I thought there was no better post for a Monday morning to get your week off on the right foot than a good laugh. I’m sure if you haven’t heard it, and even if you have, you’ll enjoy the other calls as well. Go ahead and check out the list of prank calls she’s made, check out the list of prank calls she’s made.


Nov 10 2008   4:01AM GMT

Getting the date and time from a remote system via WMI and the WIN32_LocalTime class



Posted by: Jerry Lees
VBScript, date, systems management, win32_localtime

Recently, after the time change I had to log into around 30 to 40 servers to check that the date was correct. This was a real pain, since it required me to actually log onto the server via terminal services and run a command prompt to issue a date command.

Unfortunately, I didn’t have a script written to do this remotely with WMI and I needed to get it done very quickly… so I had to do it the long, old fashioned, and unlazy way. Shortly after this I wrote the following function to check the date on a remote server using the WMI Win32_LocalTime class! Notice the class name is “Local Time”, and that’s just what it is… the local time of the system. However, if you run it on a remote system it returns the local time of the remote system!

Here is the function I wrote:

WScript.Echo GetDate(”.”)

Function GetDate(strcomputer)
on Error resume next
Set objWMIService = GetObject(”winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2″)

Set ColDate = objWMIService.ExecQuery(”Select * from Win32_LocalTime”)

for each objDate in ColDate
GetDate = ObjDate.Month & “/” & ObjDate.Day & “/” & ObjDate.Year
Next

‘cleanup memory
objWMIService = Nothing
End Function


Nov 5 2008   4:10PM GMT

Clean up your toys when your done: Fighting memory leaks in your scripts



Posted by: Jerry Lees
tips and tricks, VBScript, working with objects, memory leaks

One on the things you always want to do when you create objects in your scripts, especially objects from third party companies is, is to always remember to destroy the objects when you are done with them. At the very least, before you exit the script.

Object creation and not destroy the objects can be one source of memory leaks. In order to destroy an object should use the object’s .dispose method. If it does not have a dispose method, you set simply it to a special value of nothing. This will destroy the object and free up it’s memory. An example of using nothing is shown below:

Dim ObjTest
Set ObjTest = GetObject(”winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2″)
ObjTest = nothing


Nov 3 2008   4:18PM GMT

HTTP Status Codes explained for web servers



Posted by: Jerry Lees
HTTP, web tools, web sites, Web applications, webmaster, http tools, Web Pages, HTTP Status Codes

As a web administrator I encounter quite a few instances where a weird HTTP status is returned to a browser.Even using them often it’s hard to remember the codes 100% and what they all mean. Sure, a 404 means the file doesn’t exist and a 200 is a good response… but what about the harder more obscure ones? Generally the toughest to resolve revolve around permissions and the HTTP 401.x status, here is a good article explaining the HTTP 401 sub status codes for IIS (The general idea will flow over to other web servers like apache as well).

As a  added bonus here is a great article that explains a vast variety of other HTTP Status codes.