Archive for the ‘Uncategorized’ Category
Read this and thought it was incredibly insightful-
Exemplify Excellence : Its almost ironic how effective we can be in the last minutes of accomplishing something. The thing is, it was not the external world that brought out our efficacy, it was our perception of what needed to be done.
Quoted From: http://highestfaculties.wordpress.com/2009/04/26/defeating-student-syndrome-for-productivity/
Displaying Windows Task Scheduler Tasks with PHP
Excellent writeup of a PHP app that interfaces with the Windows Task Scheduler. I’m going to have to double check on his use of the Task Service object. I thought it was only COM accessible in Task Scheduler 2.0 (the new version, that comes with Vista or Windows 7, or Server 2008). I thought in XP (which included the Task Scheduler 1.0 – the schtasks.exe or the good old Scheduled Task’s folder) that either the Task Service COM interface had to be accessed with a lower level language, or possibly the Scheduled Task’s accessible via WMI (but not through the schtask folder interface). Its possible thats the task scheduler this code uses for access. If thats the reality, then you may not see all the tasks you may have entered using the GUI interface, using this tool. More on that later.
http://codesnob.wordpress.com/2009/05/18/displaying-windows-task-scheduler-tasks-with-php/
Google Analytics Api with VBScript
I know its ugly, but it does the job. Whats that you say? Youd like to programmatically pull your list of Profile Numbers? Stay tuned and we’ll get er done. What this script does, is it pulls down yesterdays number of visitors for whatever site you entire the “profilenum” of for that variable. Dont forget to put your email and password in there too. I know there are some scandanavian or Dutch variables in there. I borrowed a decent chunk of this code (and changed a whole lot) from Mikael Thunberg’s VBA flavoring found at: http://mikaelspage.blogspot.com/2009/08/excel-functions-for-fetching-data.html
There may be objects that sit unused or variables too. I had to de-workify the code and was in a hurry. Also, the previous version spit back all visits because it pulled all your profile numbers. Because that remains fairly static, I pulled that function out of the code. I may have left some remnants of it in there, though.
‘*******************************************************************************
‘*
‘* Good Script to pull one time-frames worth of visits from google analytics
‘* for a website with a known profilenum
‘*
‘*
‘*******************************************************************************
Set DataList = CreateObject(“System.Collections.ArrayList”)
Call main()
Sub main()
email = “emailaddress@gmail.com”
password = “password”
profilenum = “191919191″
token = getGAauthenticationToken(email, password)
‘arr = getGAdata(token, profilenum, ”visits”, Date - 7, Date - 1) ’visits for last week
arr = getGAdata(token, profilenum, “visits”, (Date – 1), (Date – 1), “”, “”, “”, “”, “”) ‘visits for previous day
WScript.Echo arr(1,1)
For Each strItem in DataList
Wscript.Echo strItem
Next
If Err.Number <> 0 Then WScript.Echo “ERROR - Main(): ” & Err.Description
End Sub
Function getGAauthenticationToken(email, password)
If email = “” Or password = “” Then
getGAauthenticationToken = “”
Exit Function
End If
CurChr = 1
Set objhttp = CreateObject(“MSXML2.ServerXMLHTTP”)
URL = “https://www.google.com/accounts/ClientLogin”
objhttp.Open “POST”, URL, False
objhttp.setRequestHeader “Content-type”, “application/x-www-form-urlencoded”
objhttp.send (“accountType=GOOGLE&Email=” & email & “&Passwd=” & password & “&service=analytics&Source=CrribsDotCom”)
authResponse = objhttp.responseText
If InStr(1, authResponse, “BadAuthentication”) = 0 Then
authTokenStart = InStr(1, authResponse, “Auth=”) + 4
authToken = Right(authResponse, Len(authResponse) - authTokenStart)
getGAauthenticationToken = authToken
Else
WScript.Echo “ERROR - getGAauthenticationToken()1: ” & Err.Description
End If
If Err.Number <> 0 Then
WScript.Echo “ERROR - getGAauthenticationToken()2: ” & Err.Description
End If
End Function
Function getGAdata(authToken, profileNumber, metrics, startDate, endDate, filters, dimensions, sort, includeHeaders, showArraySize)
If authToken = “Authentication failed” Then
ReDim TempArray(1 ,1)
TempArray(1, 1) = “Authentication failed”
getGAdata = TempArray
Exit Function
End If
If authToken = “” Then
ReDim TempArray(1, 1)
TempArray(1, 1) = “Authentication token missing”
getGAdata = TempArray
Exit Function
End If
If startDate > endDate Then
ReDim TempArray(1, 1)
TempArray(1, 1) = “Start date should be before end date”
getGAdata = TempArray
Exit Function
End If
startDateString = Year(startDate) & “-” & Right(“0″ & Month(startDate), 2) & “-” & Right(“0″ & Day(startDate), 2)
endDateString = Year(endDate) & “-” & Right(“0″ & Month(endDate), 2) & “-” & Right(“0″ & Day(endDate), 2)
URL = “https://www.google.com/analytics/feeds/data?ids=ga:” & profileNumber & “&start-date=” & startDateString & “&end-date=” & endDateString & “&max-results=10000″
If metrics <> “” Then
If Left(metrics, 3) <> “ga:” Then metrics = “ga:” & metrics
metrics = Replace(metrics, “&”, “&ga:”)
metrics = Replace(metrics, “&ga:ga:”, “&ga:”)
tempAns = “”
CurChr = 1
metrics = Replace(metrics, “ga%00″, “ga:”)
metrics = Replace(metrics, “%26″, “%2C”)
URL = URL & “&metrics=” & metrics
End If
If filters <> “” Then
If Left(filters, 3) <> “ga:” Then filters = “ga:” & filters
filters = Replace(filters, “;”, “;ga:”)
filters = Replace(filters, “;ga:ga:”, “;ga:”)
filters = Replace(filters, “,”, “,ga:”)
filters = Replace(filters, “,ga:ga:”, “,ga:”)
tempAns = “”
CurChr = 1
Do Until CurChr – 1 = Len(filters)
Select Case Asc(Mid(filters, CurChr, 1))
Case 37, 42, 44, 46, 48 > 57, 59, 65 > 90, 97 > 122, 126
tempAns = tempAns & Mid(filters, CurChr, 1)
Case 32
tempAns = tempAns & “%” & Hex(32)
Case Else
tempAns = tempAns & “%” & _
Format(Hex(Asc(Mid(filters, _
CurChr, 1))), “00″)
End Select
CurChr = CurChr + 1
Loop
filters = tempAns
filters = Replace(filters, “ga%00″, “ga:”)
filters = Replace(filters, “%26″, “%2C”)
URL = URL & “&filters=” & filters
End If
If dimensions <> “” Then
If Left(dimensions, 3) <> “ga:” Then dimensions = “ga:” & dimensions
dimensions = Replace(dimensions, “&”, “&ga:”)
dimensions = Replace(dimensions, “&ga:ga:”, “&ga:”)
tempAns = “”
CurChr = 1
Do Until CurChr – 1 = Len(dimensions)
Select Case Asc(Mid(dimensions, CurChr, 1))
Case 37, 48 > 57, 65 > 90, 97 > 122
tempAns = tempAns & Mid(dimensions, CurChr, 1)
Case 32
tempAns = tempAns & “%” & Hex(32)
Case Else
tempAns = tempAns & “%” & _
Format(Hex(Asc(Mid(dimensions, _
CurChr, 1))), “00″)
End Select
CurChr = CurChr + 1
Loop
dimensions = tempAns
dimensions = Replace(dimensions, “ga%00″, “ga:”)
dimensions = Replace(dimensions, “%26″, “%2C”)
URL = URL & “&dimensions=” & dimensions
End If
If sort = True Then URL = URL & “&sort=-” & metrics
Set objhttp = CreateObject(“MSXML2.ServerXMLHTTP”)
objhttp.Open “GET”, URL, False
objhttp.setRequestHeader “Content-type”, “application/x-www-form-urlencoded”
objhttp.setRequestHeader “Authorization”, “GoogleLogin Auth=” & authToken
objhttp.send (“”)
gaResponse = objhttp.responseText
If InStr(1, gaResponse, “Token invalid”) > 0 Or InStr(1, gaResponse, “Authorization required”) > 0 Then
ReDim TempArray(1, 1)
TempArray(1, 1) = “Authentication failed”
getGAdata = TempArray
Exit Function
End If
Set XMLdoc = CreateObject(“MSXML2.DOMDocument”)
XMLdoc.LoadXML (objhttp.responseText)
Set juuri = XMLdoc.DocumentElement
Set lapset = juuri.ChildNodes
For Each lapsi In lapset
If lapsi.nodeName = “openSearch:totalResults” Then
varRows = CDbl(lapsi.Text)
End If
If lapsi.nodeName = “entry” Then
Set lapset2 = lapsi.ChildNodes
For Each lapsi2 In lapset2
If lapsi2.nodeName = “dxp:dimension” Or lapsi2.nodeName = “dxp:metric” Then
varColumns = varColumns + 1
End If
Next
End If
Next
If varRows > 10000 Then varRows = 10000
If varRows = 0 And varColumns = 0 Then
ReDim TempArray(1, 1)
TempArray(1, 1) = “No data found”
getGAdata = TempArray
Exit Function
End If
ReDim TempArray(varRows, varColumns)
If includeHeaders = True Then ReDim TempArray(varRows, varColumns)
If showArraySize = True Then
ReDim TempArray(1, 1)
TempArray(1, 1) = varColumns & “ columns * ” & varRows & “ rows”
If includeHeaders = True Then TempArray(1, 1) = TempArray(1, 1) & “ + header row”
getGAdata = TempArray
Exit Function
End If
varrow = 1
For Each lapsi In lapset
If lapsi.nodeName = “entry” Then
varcol = 1
Set lapset2 = lapsi.ChildNodes
For Each lapsi2 In lapset2
If lapsi2.nodeName = “dxp:dimension” Then
Set attribuutit = lapsi2.Attributes
TempArray(varrow, varcol) = Left(attribuutit.getNamedItem(“value”).Text, 255)
If varrow = 1 And includeHeaders = True Then TempArray(0, varcol) = attribuutit.getNamedItem(“name”).Text
varcol = varcol + 1
End If
If lapsi2.nodeName = “dxp:metric” Then
Set attribuutit = lapsi2.Attributes
If Not IsNumeric(attribuutit.getNamedItem(“value”).Text) Then
TempArray(varrow, varcol) = CDbl(Replace(attribuutit.getNamedItem(“value”).Text, “.”, “,”))
Else
TempArray(varrow, varcol) = CDbl(attribuutit.getNamedItem(“value”).Text)
End If
If varrow = 1 And includeHeaders = True Then TempArray(0, varcol) = attribuutit.getNamedItem(“name”).Text
varcol = varcol + 1
End If
Next
varrow = varrow + 1
End If
Next
getGAdata = TempArray
If Err.Number <> 0 Then
WScript.Echo “ERROR - getGAdata(): ” & Err.Description
End If
End Function
Send Twitter Update with VBScript
I was thinking of using Twitter as a kind of ‘syslog’ for all of the scripts we have running (via the task scheduler) all over the enterprise. There is no centralized logging implemented. Ive made some attempts via text files, sql server, the event log, etc., but nothing has taken hold as – easy to implement, universal, and straightforward. This is the visual basic script I came up with to upload the messages.
'**************************************************************************
'* Scriptname: PostToTwitterSimple.vbs
'* TWITTER STATUS UPDATE
'* Brad Shultz - crribs.com
'**************************************************************************
strUsername = "username" 'Username
strPassword = "password" 'Password
strMessage = "This is a test twitter update from a vbscript." 'Message for twitter
strTwitterXMLResponse = SendToTwitter(strMessage, strUsername, strPassword)
'postback what you sent to twitter
MsgBox strTwitterXMLResponse, VbOkOnly, "TWITTER STATUS UPDATE"
Function SendToTwitter(strMessage, strUsername, strPassword)
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.open "POST", "http://twitter.com/statuses/update.xml", false, strUsername, strPassword
objHTTP.send "status=" & strMessage
SendToTwitter = objHTTP.responseText
Set objHTTP = nothing
End Function
Cool Asp Help Desk (Freeware)
http://www.liberum.org/content/features.aspx
Is a neat free .asp help-desk solution. It could be customized pretty easily to an organization’s specific needs. I’ve found that help-desk software can be expensive and over-complicated for our sometimes very basic needs.
Scheduled Task Report
Get a comma seperated, consolidated file with all of the configured scheduled tasks within your domain. Will also work in a workgroup, you just need to be sure that you have configured a network username and password and can authenticate successfully as an admin on that machine. Save the following as a '.bat' file, in its own folder, along with a file named 'servers.ini'. In th servers.ini file, simply list the machine names for those machines you want the schtask report from. Run it, and you should get a text file that could be parsed through and imported into a database, or just useful for auditing purposes.ECHO %DATE% %TIME% > SchTaskReport.txt FOR /F “tokens=1″ %%i in (servers.ini) DO schtasks /query /s %%i /v /fo csv >> SchTaskReport.txt
Add VBScript to Scheduled Tasks – from Context Menu
This has been something that’s bothered me for awhile- especially at work, with all the tasks I schedule daily. It bothered me that I always had to look up the system account username and password that’d been designated as our ‘Task Scheduler Account’. The password is a tough one (and rightly so- its a domain admin account). It also bothered me that in order to schedule a task, I had to go to the GUI applet interface (Control Panel) or the command prompt, then add the task- even though I’d just written the script and was staring at it in the directory I wanted it to run from. Thus was born the (fairly ugly, but useful) – ScheduleAsTask context menu item.
There is a limitation on the name of the vbs file- it cannot have spaces in it. This is because we are using the filename as an argument – so if there is a space in the name, the Windows Scripting Host thinks there are multiple arguments. This limitation could be overcome by getting the number of arguments found at runtime, and concatenating them fairly easily.
The default name is your script’s name, minus the extension. If there is already a task scheduled with the same name, the script will throw an error. You can change the task name to whatever you like in step 2.
And step 3 is just configuring the details for the task.
———————————————————————————
1. Save the following code to a directory as “schtaskContextMenu.vbs” (the name doesnt matter as long as the extension is .vbs).
2. Go to http://www.mvps.org/emorcillo/en/code/vb6/index.shtml and scroll down until you see “Using the Task Scheduler”. Click the link underneath it and save the .dll in the same directory as the script.
3. Run the script. You may have to give it permission to run. Tested on XP Pro sp2. Might work on Vista, not sure. Vista uses the TaskScheduler 2.0 interface, which has some backwards support. Try it.
Here is the script zipped up for you. Once you have the .dll from the above link in the same folder as the script, simply double click on the script. It will ask you if you are installing or updating. Click yes to install the whole shebang, no to just update the script (in case you make any changes), or cancel to, well, cancel the script.
Oh, and be sure to enter the account information in the .vbs so it will work on your machine (yep, its a security risk- anyone could open the script’s source and read the account info- maybe make a special non-admin account for scheduled tasks? As far as I am concerned – in the environments I work in- the account info is available to any legit user. If we have a rogue hacker looking through our scripts, plaintext passwords are the least of our concerns.) Context Menu Task Scheduler Script for Vbscripts
