Scripting made easy.

Scriptius is by far the easiest way to program your own scripts with absolutely no programming experience required. All the commands are accessed through a simple pull-down menu and there is very little additional typing needed. You can easily make scripts that launch other programs, access the clipboard, copy and delete files, modify the registry and other cool stuff. I have never seen a program make script programming this easy.

A number guessing game for KiXtart.

KiXtart is yet another scripting language I’m learning. It uses a simple, BASIC-like language to allow you to make your own scripts with ease. I’ve yet to see if it’s better than AutoIt, but so far it’s been a smooth ride. Here’s a number guessing game in which the script tells you if your guess is too high or too low.

dim $guess
SRND (2007)
$num = int(RND(100))

while $num $guess

? “Your guess? “
GETS $guess

if int($guess) > $num
? “Too high.”
else
if int($guess) < $num
? “Too low.”
endif
endif

loop

? “You guessed it!”

A number guessing game.

Time to have some fun with scripting. Here’s a number guessing game that thinks of a number between 1 and 100 and has you try guessing that number, letting you know if your guesses are too high or too low.

int strGuess
intHighNumber = 100
intLowNumber = 1
Randomize
intNumber = Int((intHighNumber – intLowNumber + 1) * Rnd + intLowNumber)

Do while cint(strGuess) intNumber

strGuess = InputBox(“What is your guess?”, _
“Guess the Number”)

If cint(strGuess) > intNumber Then
Wscript.Echo “Too high.”
Elseif cint(strGuess) < intNumber Then
Wscript.Echo “Too low.”
End If

Loop

Wscript.Echo “You guessed it!”
Wscript.Quit

Clipboard paster script.

This script is similar to what I posted a few days ago, except this one copies the contents of the clipboard to a new file with the computer name as the name of the file, adding the characters “_cb” at the end of the file name. I made this one so I could easily paste error messages from the Event Log to a file for further researching.

DIM fso, MFile
Set objNetwork = CreateObject(“Wscript.Network”)
strComputer = objNetwork.ComputerName

Set objHTML = CreateObject(“htmlfile”)
ClipboardText = objHTML.ParentWindow.ClipboardData.GetData(“text”)

Set fso = CreateObject(“Scripting.FileSystemObject”)
Set MFile = fso.CreateTextFile(strComputer & “_cb.txt”, True)
MFile.WriteLine(ClipboardText)
MFile.Close

Even more scripting fun.

I came up with a VBS script that creates a text file with the computer name as the name of the file. It then writes the time and date to the file so I know when I started maintenance on that computer. As simple as this script is, it took me several days of figuring out how to go about making the script using bits and pieces of what I found online.

DIM fso, MFile
Set objNetwork = CreateObject(“Wscript.Network”)
strComputer = objNetwork.ComputerName

Set fso = CreateObject(“Scripting.FileSystemObject”)
Set MFile = fso.CreateTextFile(strComputer & “.txt”, True)
MFile.WriteLine(“Maintained on “& Date &” at “& Time)
MFile.Close

Of scripts and Firefox.

In case you haven’t been driven bonkers by my posts about scripting, here comes another one that will have you banging your head on the wall a second time. I came up with a bunch of scripts today that take scripting to new online heights.
On the server I use at work, Internet Explorer 7 is set as the default browser, which irritates me. I really get tired of those security alerts that pop up whenever a web site’s content has been blocked. I don’t want to change anything as I’m working at the very server that’s the lifeline of everyone at the office.
Fortunately, Firefox is also installed on the same server. I started looking into having Firefox launch when I type in a web address without making it the default browser. Here’s the script that does the trick.

Set objShell = CreateObject(“Wscript.Shell”)
strURL = InputBox(“Enter a web address:”, _
“Firefox Launcher”)
objShell.Run “firefox.exe ” & strURL

In that script, an input window will open to ask for the web address. Afterwards Firefox will launch and take you to that address.

Another script I made is one that does searches on Google using Firefox.

Set objShell = CreateObject(“Wscript.Shell”)
strSEARCH = InputBox(“Enter a search query:”, _
“Googler”)

strOldText = Chr(32)
strNewText = Chr(43)
strQuery = Replace(strSEARCH, strOldText, strNewText)

objShell.Run “firefox.exe ” & “http://www.google.com/search?hl=en&q=&#8221; & Chr(34) & strQuery & Chr(34) & “&btnG=Search”

This script asks for a search query, replaces any spaces between words with plus signs and then sends it to Google.

Here’s a script that utilizes Google’s “I’m Feeling Lucky” function. Here you’ll be asked for a search query and then be taken to the first site Google finds.

Set objShell = CreateObject(“Wscript.Shell”)
strSEARCH = InputBox(“Careful, you are feeling lucky. Enter a search query:”, _
“I’m Feeling Lucky”)

strOldText = Chr(32)
strNewText = Chr(43)
strQuery = Replace(strSEARCH, strOldText, strNewText)

objShell.Run “firefox.exe ” & “http://www.google.com/search?hl=en&q=&#8221; & Chr(34) & strQuery & Chr(34) & “&btnI=I’m+Feeling+Lucky”

Here’s a script that does a Google search on Experts Exchange’s web site.

Set objShell = CreateObject(“Wscript.Shell”)
strSEARCH = InputBox(“Enter a search query:”, _
“Experts Exchange Search”)

strOldText = Chr(32)
strNewText = Chr(43)
strQuery = Replace(strSearch, strOldText, strNewText)

objShell.Run “firefox.exe ” & “http://www.google.com/search?q=site%3Awww.experts-exchange.com+&#8221; & Chr(34) & strQuery & Chr(34)

I had originally saved this script as expertsexchange.vbs, but the title really looked strange. No script will ever do an expert sex change, so I ended up renaming it to experts-exchange.vbs.

All the above scripts will work with Internet Explorer as well. Just replace “firefox.exe” with “iexplore.exe”.

I close with a cool script that launches a multi-tabbed instance of Firefox.

Set objShell = CreateObject(“Wscript.Shell”)
objShell.Run “firefox.exe google technet kbalertz experts-exchange”

This particular script launches Firefox with tabs for Google, Microsoft Technet, kbAlertz and Experts Exchange. I ran this by Internet Explorer but it got confused and took me to its search page.
That’s enough scripting for today. Who knows what scripts I’m going to come up with tomorrow.

Copying the computer name to the clipboard.

This is a script that copies the computer name to the clipboard. For the longest time I’d been looking for a program that does this and it’s too bad that I no longer work at the office where I needed this script the most. Oh well. Who knows when this is going to come in handy again.

Set objNetwork = CreateObject(“Wscript.Network”)
strComputer = objNetwork.ComputerName
Set objIE = CreateObject(“InternetExplorer.Application”)
objIE.Navigate(“about:blank”)
objIE.document.parentwindow.clipboardData.SetData “text”, strComputer
objIE.Quit
Wscript.Echo “Computer name copied to clipboard.”

More scripting fun.

I had some more fun with scripts today. I went back to Microsoft’s Scripting Center and continued snipping lines of code from the sample scripts and making my own scripts in the process. In some cases I made the scripts run even better.
For example, there’s the column in which someone wanted to know how to tell if the server’s been rebooted. Their script gave the answer by telling how long the server’s been running. I fixed the script so the output is a bit more meaningful by reporting how many days the server’s been running. Then it converts the days into hours and the hours into minutes. I also worked in VBNewLine to implement line breaks in the script.

strComputer = “.”
Set objWMIService = GetObject _
(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colOperatingSystems = objWMIService.ExecQuery _
(“Select * from Win32_OperatingSystem”)
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
dtmSystemUptime = DateDiff(“h”, dtmLastBootUpTime, Now)
dtmSystemUptimeMin = DateDiff(“n”, dtmLastBootUpTime, Now)
dtmSystemUptimeDay = DateDiff(“d”, dtmLastBootUpTime, Now)
Wscript.Echo “This computer has been up for:” & VBNewLine & dtmSystemUptimeDay & ” days” & VBNewLine & dtmSystemUptime & ” hours” & VBNewLine & dtmSystemUptimeMin & ” minutes”
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
Next
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & “/” & _
Mid(dtmBootup, 7, 2) & “/” & Left(dtmBootup, 4) _
& ” ” & Mid (dtmBootup, 9, 2) & “:” & _
Mid(dtmBootup, 11, 2) & “:” & Mid(dtmBootup, _
13, 2))
End Function

Just scripting around.

It was another slow day at the office today so I passed the time studying scripting at Microsoft’s Script Center web site. I read the Hey, Scripting Guy! column and gathered snippets of code to start making my own scripts. It’s really cool.
Here’s a script I made that displays your computer name.

Set objNetwork = CreateObject(“Wscript.Network”)
strComputer = objNetwork.ComputerName
Wscript.echo “Computer name: ” & StrComputer

Just paste the above three lines into Notepad and save the file using the VBS extension, as in “Computername.vbs”. Just double-click on the script and viola, up pops your computer name. I should’ve discovered scripting years ago. The computer name script would’ve come in so handy.