Friday, March 30, 2012

AutoIT RSS Feeder

After my last post on how to get the Windows 7 RSS Feeder gadget to start on logon, I started to write my own RSS feed in Autoit. Im sorry to say that it was slightly more than I could do on my own so I had a bit of a Google on it. There were several good examples available and I found one that showed you the basic ways to do it using the XMLDomWapper.au3 file and the appbarhelper.au3 files.

Here's the code.

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <inet.au3>
#include <array.au3>
#include <_XMLDomWrapper.au3>
#include <appbarHelper.au3>

Local $update_freq = 18000
Local $rss_source = "http://RESTOFTHEURLTOTHEXMLFILE"
Global $rss_gui = _AppbarNew("RSS FEED", "NEWS")

GUISetBkColor(0xFFFFFF)
Local $rss_text = _GetFeedData($rss_source)
Global $rss_label = GUICtrlCreateLabel($rss_text, -1, -1, @DesktopWidth, 40)
GUICtrlSetFont(-1, 14, 400, 2, "Verdana")
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKSIZE)
GUISwitch($rss_gui)
_AppbarSetDockingEdges(False, False, True, True)
_AppbarDock($rss_gui, $ABE_TOP, 40, 10)
GUISetState(@SW_SHOW, $rss_gui)
While 1
 Sleep(200)
 If Not isMouseOverRSS() Then
  Local $TempText = GUICtrlRead($rss_label)
  GUICtrlSetData($rss_label, StringTrimLeft($TempText, 1) & StringLeft($TempText, 1))
 EndIf
WEnd
Func _GetFeedData($rss_source)
 Local $strXML = _INetGetSource($rss_source)
 _XMLLoadXML($strXML, "")

 Local $title_node = "//rss/channel/item/title";
 Local $title_array = _XMLGetValue($title_node)
 Local $descr_node = "//rss/channel/item/description";
 Local $descr_array = _XMLGetValue($descr_node)
 Local $link_node = "//rss/channel/item/link";
 Local $link_array = _XMLGetValue($link_node)
 Local $feed_data = ""
 For $i = 1 To $title_array[0]
  $feed_data = $feed_data & $title_array[$i] & ": " & $descr_array[$i] & " - "
  If $i = $title_array[0] Then $feed_data = $feed_data & " --END-- "
 Next
 Return $feed_data
EndFunc
Func isMouseOverRSS()
 Local $mouse_info = GUIGetCursorInfo($rss_gui)
 If $mouse_info[4] = $rss_label Then Return True
 Return False
EndFunc

Its pretty simple really and I really should have been able to do it on my own. Still have fun playing with it.

Friday, March 23, 2012

Starting the Windows 7 RSS feed gadgets on logon

I've been asked to look at starting the windows 7 RSS feed gadget on logon for staff members. The management believe its a better way for rolling out information about the company than using emails. I had a bit of a google and there wasn't that much on it, so when I found out how to do it I thought I would share it with everyone.

Its actually quite simple.

First take a test machine and in Internet Explorer add the RSS feed you want to run through the gadget. Then browse yourself to c:\users\USERNAME\appdata\local\microsoft\feeds. In here you will find a file with the name of the feed. Copy this file to a new location as you will need to copy this file to everyones local area.

Second, again on your test machine, launch the RSS feed gadget by right clicking on the desktop and choosing 'gadgets'. Then select the 'Feeds Headlines' gadget. This should launch in the top right hand corner. Open its settings and choose the rss feed you want to run as default under the heading "Display this Feed". Now, with it still open browse to C:\Users\USERNAME\AppData\Local\Microsoft\Windows Sidebar. In here you will find a 'settings.ini'. You'll need to make a copy of this file as well.

Ok, now put these two files in a place that everyone has access to. The NETLOGON of your AD controller might be a good place. Now you can write a little bat file that will do the copying for you. eg....

echo off
xcopy \\SERVER\netlogon\rss\settings.ini "%userprofile%\appdata\Local\Microsoft\Windows Sidebar\" /y
xcopy "\\SERVER\netlogon\rss\FILE FOR RSSFEED " "%userprofile%\appdata\Local\Microsoft\feeds\" /y
c:
cd "C:\Program Files\Windows Sidebar\"
sidebar.exe
exit

Then you can set your group policy to run this bat file on logon (USER config -> policies ->windows settings -> scripts -> logon) and that should be it. It will start everytime someone logs on and runs the default RSS feed.

Monday, March 19, 2012

AutoIt countdown timer

So i've been playing around with AutoIt recently. Its a great little piece of software for writting automated programs. Its like a cross between C and python. But the best part about it is that as its comunity based anyone can write their own functions for it and add them to the site. Great!

Anyway, we've selected a few open access computers that are going to be used for electronic submission only. The higher manangement wanted a piece of software that would instruct the student logged on that they would have a maximum of 15 minutes on the PC, and then get logged off. After a bit of discussion I managed to get them to accept giving the students a warning that their time was up and then the counter would count backwards in big red writting.

So this is the code

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>

$ms = 900250 ;This is the time in milliseconds Adjust as needed
$timer = TimerInit()
traysetstate(2)
$labeltext = "This computer is primarily for electronic submission. You will be automatically logged off after 15 minutes"
GUICreate("Electronic Submission", 350, 330, -1, -1, $WS_DLGFRAME, $WS_EX_TOPMOST)
$Label = GUICtrlCreateLabel($labeltext, 10, 10, 330, 200, $SS_CENTER)
GUICtrlSetFont(-1, 18, 400, $labeltext)
$Input = GUICtrlCreateInput("", 125, 150, 90, 40, BitOr($SS_CENTER, $ES_READONLY, $WS_CLIPCHILDREN))
GUICtrlSetFont(-1, 18, 400)
GUISetState (@SW_SHOW)
WinSetTrans("Electronic Submission","", 127)
While (TimerDiff($timer) < $ms)
   $seconds = TimerDiff($timer)/1000
   $diff = $seconds - ($ms/1000);
   $minutes = Int($diff / 60)
   $secondsRem = $diff - ($minutes * 60)
   $minutes = $minutes * -1
   $secondsRem = $secondsRem * -1
   $time = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem)
   GUICtrlSetData($Input, $time)
   WEnd
 
   Global $reply = MsgBox(1, "TIMES UP", &@UserName " you have had 15 minutes on this computer. If someone is waiting please let them use it. CLICK OK TO LOG OFF",30)
   If $reply = 1  then run("shutdown.exe -l")
  
   $Input = GUICtrlCreateInput("", 25, 125, 300, 100, BitOr($SS_CENTER, $ES_READONLY, $WS_CLIPCHILDREN))
   GUICtrlSetColor(-1, 0xff0000)
   GUICtrlSetFont(-1, 50, 400)
  
   While (TimerDiff($timer) > $ms)
   $seconds = TimerDiff($timer)/1000
   $diff = $seconds - ($ms/1000)
   $minutes = Int($diff / 60)
   $secondsRem = $diff - ($minutes * 60)
   $minutes = $minutes * -1
   $secondsRem = $secondsRem * -1
   $time = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem)
   GUICtrlSetData($Input, $time)
   WEnd
   run("shutdown.exe -l")

Its not the best code, but im just learning it. feel free to adjust and use it for yourselves.