<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9</title>
    <atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Niners/c4f.Shoban-Kumar/Posts/RSS"></atom:link>
    <itunes:summary></itunes:summary>
    <itunes:author>Microsoft</itunes:author>
    <itunes:subtitle></itunes:subtitle>
    <image>
      <url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
      <title>Channel 9</title>
      <link>http://channel9.msdn.com/Niners/c4f.Shoban-Kumar/Posts</link>
    </image>
    <itunes:image href=""></itunes:image>
    <itunes:category text="Technology"></itunes:category>
    <description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
    <link>http://channel9.msdn.com/Niners/c4f.Shoban-Kumar/Posts</link>
    <language>en</language>
    <pubDate>Mon, 20 May 2013 12:32:14 GMT</pubDate>
    <lastBuildDate>Mon, 20 May 2013 12:32:14 GMT</lastBuildDate>
    <generator>Rev9</generator>
    <c9:totalResults>1</c9:totalResults>
    <c9:pageCount>1</c9:pageCount>
    <c9:pageSize>25</c9:pageSize>
  <item>
      <title>Shutdown/Restart/Logoff your PC using TweetMyPC</title>
      <description><![CDATA[
<p>In this article I will show you how you can use Twitter API to Shutdown/Restart/Logoff your PC remotely using VB.net.</p>
<h3>Introduction</h3>
<p>I have a very slow internet connection at home and most of the time Downloads takes hours to complete. I decided to write an application which will help me Shutdown my PC from a remote location. I wanted to use it to shutdown when I go out when some downloading
 is going on in my laptop. Instead of using a server and client architecture I decided to use Twitter API and use “My Timeline” to supply commands. One other reason to use Twitter is that I will be able to tweet from my mobile as well. I don't need to look
 for a computer with an internet connection when I am on the move.</p>
<h4>Why Yedda Twitter framework?</h4>
<p>The <a href="http://apiwiki.twitter.com/Twitter-API-Documentation">Twitter REST API</a> methods allow developers to access core Twitter data. This includes update timelines, status data, and user information. It's very easy to connect to Twitter and get
 user time line using .net. But I dint wanted to reinvent wheel and decided to use an existing Twitter library. Yedda Twitter framework is the best open source Twitter library available in the internet. You can learn more and download the library from
<a href="http://devblog.yedda.com/index.php/2007/05/16/twitter-c-library/">yedda's home page</a>.</p>
<h4>Designing the Interface</h4>
<p>I wanted the interface to be as simple as possible. Below is the screenshot of TweetMyPC's interface which does not have more than 2 Text Boxes, 1 Check Box, Label and a Button.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9709252/clip_image001_2.jpg"><img title="clip_image001" border="0" alt="clip_image001" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9709252/clip_image001_thumb.jpg" width="288" height="250"></a></p>
<p>The form also has a Notify Icon, Context Menu Strip and a Timer. Following are the names of all the controls in the form.</p>
<ul>
<li>From : <b>frmTweetMyPc</b> </li><li>Text Boxes : <b>txtUserName</b>, <b>txtPassword</b> </li><li>Button : <b>btnSave</b> </li><li>Check Box : <b>chkStartAutomatic</b> </li><li>Timer : <b>tmrTweet</b> (Interval : 10000) </li><li>Label : <b>lblSatus</b> </li></ul>
<p>There are few <a href="http://msdn.microsoft.com/en-us/library/saa62613(VS.80).aspx">
My.settings</a> properties to store user information. These properties are shown below.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9709252/clip_image002_2.jpg"><img title="clip_image002" border="0" alt="clip_image002" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9709252/clip_image002_thumb.jpg" width="388" height="139"></a></p>
<p><b>The Code</b><b> <br>
</b>Add the following code which minimizes the Form on Load and Enable Timer to check for Tweets every 1 minute.
</p>
<pre class="csharpcode"><span class="kwrd">Me</span>.WindowState = FormWindowState.Minimized
<span class="kwrd">Me</span>.ShowInTaskbar = <span class="kwrd">False</span>
tmrTweet.Enabled = True</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p></p>
<p>The following code in Button's Click event will validate Twitter username, Password and save it to My.Settings.</p>
<pre class="csharpcode"><span class="kwrd">If</span> txtUserName.Text.Trim = <span class="str">&quot;&quot;</span> <span class="kwrd">Then</span>
    lblSatus.Text = <span class="str">&quot;Please enter Twitter Username&quot;</span>
    txtUserName.Focus()
    <span class="kwrd">Exit</span> <span class="kwrd">Sub</span>
<span class="kwrd">End</span> <span class="kwrd">If</span>
<span class="kwrd">If</span> txtPassword.Text.Trim = <span class="str">&quot;&quot;</span> <span class="kwrd">Then</span>
    lblSatus.Text = <span class="str">&quot;Please enter Twitter Password&quot;</span>
    txtPassword.Focus()
    <span class="kwrd">Exit</span> <span class="kwrd">Sub</span>
<span class="kwrd">End</span> <span class="kwrd">If</span>

lblSatus.Text = <span class="str">&quot;&quot;</span>


<span class="rem">'Check for valid Username and Password and then Save Settings</span>
<span class="kwrd">Dim</span> objTwitter <span class="kwrd">As</span> <span class="kwrd">New</span> Yedda.Twitter
<span class="kwrd">Dim</span> Updates <span class="kwrd">As</span> XmlDocument

<span class="kwrd">Try</span> <span class="rem">'Try Logging in</span>
    Updates = objTwitter.GetUserTimelineAsXML(txtUserName.Text.Trim, txtPassword.Text.Trim)
    My.Settings.UserName = txtUserName.Text.Trim
    My.Settings.Password = txtPassword.Text.Trim
    <span class="kwrd">Me</span>.WindowState = FormWindowState.Minimized
    <span class="kwrd">Me</span>.ShowInTaskbar = <span class="kwrd">False</span>
    tmrTweet.Enabled = <span class="kwrd">True</span>
<span class="kwrd">Catch</span> ex <span class="kwrd">As</span> Exception
    MsgBox(<span class="str">&quot;Failed to Login to Twitter with the values supplied. Please check your login details.&quot;</span>)
    txtUserName.Focus()
    <span class="kwrd">Exit</span> <span class="kwrd">Sub</span>
<span class="kwrd">End</span> Try</pre>
<p>Yedda library is used to login to Twitter to check for valid username and password. The Label
<b>lblSatus</b> is used to display any error messages.</p>
<p>Add the following code to the Checkbox's <strong>CheckChanged</strong> event which will add the required registry keys to start this app on Window's startup</p>
<pre class="csharpcode"><span class="kwrd">If</span> chkStartAutomatic.Checked = <span class="kwrd">True</span> <span class="kwrd">Then</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; My.Settings.AutomaticStart = <span class="kwrd">True</span>
      <span class="kwrd">Dim</span> regKey <span class="kwrd">As</span> RegistryKey
      regKey = Registry.CurrentUser.OpenSubKey(<span class="str">&quot;Software\Microsoft\Windows\CurrentVersion\Run&quot;</span>, <span class="kwrd">True</span>)
      regKey.SetValue(Application.ProductName, Application.ExecutablePath)
      regKey.Close()
<span class="kwrd">Else</span>
      My.Settings.AutomaticStart = <span class="kwrd">False</span>
      <span class="kwrd">Dim</span> regKey <span class="kwrd">As</span> RegistryKey
      regKey = Registry.CurrentUser.OpenSubKey(<span class="str">&quot;Software\Microsoft\Windows\CurrentVersion\Run&quot;</span>, <span class="kwrd">True</span>)
      regKey.DeleteValue(Application.ProductName)
      regKey.Close()
<span class="kwrd">End</span> If</pre>
<p>The following code in Timer's Tick event will do the job of checking Twitter Timeline every one minute and Shutdown/Restart/Log off the system based on the Tweet.</p>
<pre class="csharpcode"><span class="kwrd">If</span> My.Settings.UserName.Trim = <span class="str">&quot;&quot;</span> <span class="kwrd">Then</span>
    <span class="kwrd">Exit</span> <span class="kwrd">Sub</span>
<span class="kwrd">Else</span>
    <span class="rem">'Check for new Tweet </span>
    <span class="kwrd">Dim</span> objTwitter <span class="kwrd">As</span> <span class="kwrd">New</span> Yedda.Twitter
    <span class="kwrd">Dim</span> Updates <span class="kwrd">As</span> XmlDocument
    <span class="kwrd">Dim</span> node <span class="kwrd">As</span> XmlNode
    <span class="kwrd">Try</span> <span class="rem">'Try Logging in</span>
        Updates = objTwitter.GetUserTimelineAsXML(My.Settings.UserName.Trim, My.Settings.Password.Trim)
        <span class="kwrd">Catch</span> ex <span class="kwrd">As</span> Exception
        MsgBox(<span class="str">&quot;Error : Failed to Login to Twitter with the values supplied. Please check your login details.&quot;</span>)
        <span class="kwrd">Exit</span> <span class="kwrd">Sub</span>
    <span class="kwrd">End</span> <span class="kwrd">Try</span>
    <span class="kwrd">Try</span>
        node = Updates.SelectSingleNode(<span class="str">&quot;/statuses/status/id&quot;</span>)
        <span class="kwrd">If</span> node.InnerText.Trim &lt;&gt; My.Settings.LastID.Trim <span class="kwrd">Then</span> 
            <span class="rem">'Compare the Tweet ID to check for new tweets</span>
            My.Settings.LastID = node.InnerText.Trim
            node = Updates.SelectSingleNode(<span class="str">&quot;/statuses/status/text&quot;</span>)
            ProcessTweet(node.InnerText.Trim)
          <span class="kwrd">End</span> <span class="kwrd">If</span>
    <span class="kwrd">Catch</span> ex <span class="kwrd">As</span> Exception
        <span class="kwrd">Exit</span> <span class="kwrd">Sub</span>
    <span class="kwrd">End</span> <span class="kwrd">Try</span>
<span class="kwrd">End</span> If</pre>
<p>If the Tweet is new then we process the tweet.</p>
<pre class="csharpcode"><span class="kwrd">Private</span> <span class="kwrd">Sub</span> ProcessTweet(<span class="kwrd">ByVal</span> Tweet <span class="kwrd">As</span> <span class="kwrd">String</span>)
    <span class="kwrd">If</span> Tweet = <span class="str">&quot;Shutdown&quot;</span> <span class="kwrd">Then</span>
        System.Diagnostics.Process.Start(<span class="str">&quot;shutdown&quot;</span>, <span class="str">&quot;-s -f -t 100&quot;</span>) <span class="rem">'Shutdown</span>
    <span class="kwrd">ElseIf</span> Tweet = <span class="str">&quot;Logoff&quot;</span> <span class="kwrd">Then</span>
        System.Diagnostics.Process.Start(<span class="str">&quot;shutdown&quot;</span>, <span class="str">&quot;-l -f -t 100&quot;</span>) <span class="rem">'Logoff</span>
    <span class="kwrd">ElseIf</span> Tweet = <span class="str">&quot;Restart&quot;</span> <span class="kwrd">Then</span>
        System.Diagnostics.Process.Start(<span class="str">&quot;shutdown&quot;</span>, <span class="str">&quot;-r -f -t 100&quot;</span>) <span class="rem">' Restart</span>
    <span class="kwrd">End</span> <span class="kwrd">If</span>
<span class="kwrd">End</span> Sub</pre>
<p>The Context Menu strip has two menu items. They are Edit Setting and Exit.</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9709252/clip_image003_2.jpg"><img title="clip_image003" border="0" alt="clip_image003" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9709252/clip_image003_thumb.jpg" width="292" height="253"></a></p>
<p>Add the following code the “Edit Settings” Client event and Notify Icon's Mouse Double Click Event.
</p>
<pre class="csharpcode">tmrTweet.Enabled = <span class="kwrd">False</span>
txtUserName.Text = My.Settings.UserName.Trim
txtPassword.Text = My.Settings.Password.Trim
<span class="kwrd">If</span> My.Settings.AutomaticStart = <span class="kwrd">True</span> <span class="kwrd">Then</span> chkStartAutomatic.Checked = <span class="kwrd">True</span>
<span class="kwrd">Me</span>.WindowState = FormWindowState.Normal
<span class="kwrd">Me</span>.ShowInTaskbar = True</pre>
<p>TweetMyPC runs silently on startup. To Edit Settings double click/Right Click the notify icon.</p>
<h4>Working</h4>
<div id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:60558cb3-f672-4422-85cf-fea80c9effce" class="wlWriterEditableSmartContent">
<div id="28e191ed-c541-4d5a-85ef-992feaf927fd">
<div><a href="http://www.youtube.com/watch?v=yPxd2IwWjoU" target="_new"><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9709252/video770b8dbba191.jpg" alt=""></a></div>
</div>
</div>
<h3>Conclusion</h3>
<p>Even though TweetMyPC is a simple app it has lot of interesting potential. Think about switching off your TV or washing machine using Twitter. It is possible with a little extra hardware and a simple .net program. TweetMyPC is free and open source. Feel
 free to download the sour code and add more functionality.</p>
<h3>About The Author</h3>
<p>Shoban Kumar is a Senior Software Engineer working for Allianz Cornhill India. Programming is his passion. He also writes about .net in
<a href="http://www.dotnetcurry.com/">http://www.dotnetcurry.com/</a> and an active participator in
<a href="http://stackoverflow.com/users/12178/shoban">stackoverflow</a> and speaker in
<a href="http://k-mug.org/">Microsoft user group</a> sessions. You also can follow him in
<a href="http://twitter.com/shobankr">Twitter</a>.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Shoban-Kumar/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:4081804374e84ff6a1939e7600cc2876">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC</comments>
      <itunes:summary>
In this article I will show you how you can use Twitter API to Shutdown/Restart/Logoff your PC remotely using VB.net. 
Introduction
I have a very slow internet connection at home and most of the time Downloads takes hours to complete. I decided to write an application which will help me Shutdown my PC from a remote location. I wanted to use it to shutdown when I go out when some downloading
 is going on in my laptop. Instead of using a server and client architecture I decided to use Twitter API and use “My Timeline” to supply commands. One other reason to use Twitter is that I will be able to tweet from my mobile as well. I don&#39;t need to look
 for a computer with an internet connection when I am on the move. 
Why Yedda Twitter framework?
The Twitter REST API methods allow developers to access core Twitter data. This includes update timelines, status data, and user information. It&#39;s very easy to connect to Twitter and get
 user time line using .net. But I dint wanted to reinvent wheel and decided to use an existing Twitter library. Yedda Twitter framework is the best open source Twitter library available in the internet. You can learn more and download the library from
yedda&#39;s home page. 
Designing the Interface
I wanted the interface to be as simple as possible. Below is the screenshot of TweetMyPC&#39;s interface which does not have more than 2 Text Boxes, 1 Check Box, Label and a Button. 
 
The form also has a Notify Icon, Context Menu Strip and a Timer. Following are the names of all the controls in the form. 

From : frmTweetMyPc Text Boxes : txtUserName, txtPassword Button : btnSave Check Box : chkStartAutomatic Timer : tmrTweet (Interval : 10000) Label : lblSatus 
There are few 
My.settings properties to store user information. These properties are shown below. 
 
The Code 
Add the following code which minimizes the Form on Load and Enable Timer to check for Tweets every 1 minute.
 
Me.WindowState = FormWindowState.Minimized
Me.ShowInTaskbar = False
tmrTweet.Enab</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC</link>
      <pubDate>Tue, 23 Jun 2009 16:01:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/9709252_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/9709252_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Shoban Kumar </dc:creator>
      <itunes:author>Shoban Kumar </itunes:author>
      <slash:comments>10</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC/RSS</wfw:commentRss>
      <category>utility</category>
      <category>Windows</category>
      <category>Home Automation</category>
    </item>    
</channel>
</rss>