Update your Twitter status with VbScript

Tutorial and downloads about using VbScript to Tweet directly from your desktop or server, programmatically, within your programm or webapplication, or fired off from a trigger or schedule... or whatever.. be creative..!

The basic script

Below is the script. Open notepad and copy 'n paste the code below. Then save it as "PostToTwitterSimple.vbs" (or whatever filename you want). Change the 3 values, somewhere around lines 24 to 26, into your own values. So it logs in to your Twitter account. Save it, and close it. Double click the script file and you will see the messagebox appearing. And you will see the text appearing on Twitter.

'==============================================================
'
' Scriptname: PostToTwitterSimple.vbs
'
' SITEJUNCTION
' TWITTER STATUS UPDATE
'
' With this script you can update your Twitter status
'
' July 2009 - Erick Hiemstra
'
' more info:
' http://sitejunction.awardspace.com/vbscript_tweets/basic_script/
'
'==============================================================

OPTION EXPLICIT 'Be sure you have declared all your variables.

' --------------------------
' SOME VARIABLES
' In this script the response is hardcoded directly into a variable
' to keep the script readable, but could of
' course come from whatever source.
' --------------------------

Dim strUsername, strPassword, strMessage
strUsername = "your Twitter username here" ' Your Twitter username
strPassword = "your Twitter password goes here" ' Your Twitter password
strMessage = "Testing Twitter script found on http://sitejunction.awardspace.com/vbscript_tweets/" ' Write the message you would like to seen on your Twitter here.


' Calling the function and store the result in a variable.
Dim strTwitterXMLResponse
strTwitterXMLResponse = SendToTwitter(strMessage, strUsername, strPassword)

' Post back the result with a messagebox so you know something happend
MsgBox strTwitterXMLResponse, VbOkOnly, "TWITTER STATUS UPDATE"

' --------------------------
' FUNCTIONS
' This is where the actual work is done
' --------------------------

Function SendToTwitter(strMessage, strUsername, strPassword)

     ' This is the function wicht does all the work.
     ' It uses XMLHTTP to post your message to Twitter..
     Dim objHTTP
     Set objHTTP = CreateObject("Microsoft.XMLHTTP")
     
          objHTTP.open "POST", "http://twitter.com/statuses/update.xml", false, strUsername, strPassword
          objHTTP.send "status=" & strMessage
          
          ' The function stores the Twitter response to the result of the function so you can use this later
          SendToTwitter = objHTTP.responseText
     
     Set objHTTP = nothing 'Release the object
     
End Function

You can also download the script as a text file here. Right click with you mouse on the download link, choose "save as" and change the *.txt extension into the extension *.vbs. Later on you can always use notepad to open the file again to change variables.

Frequently Asked Questions, Feedback and Questions
I keep up with questions about this script sent to me by visitors on the Frequently Asked Questions page for this script. Got issues implementing this script, take a look at the FAQ page or feel free to send me an e-mail, so I can change the text on this page so everybody will understand it and can enjoy the power and advantages of scripting.

In the next chapter I tweak this script so you can use it directly from your desktop...