<?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>Comment Feed for Channel 9 - Shutdown/Restart/Logoff your PC using TweetMyPC</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC/RSS"></atom:link>
	<image>
		<url>http://ecn.channel9.msdn.com/o9/c4f/images/9709252_100.jpg</url>
		<title>Channel 9 - Shutdown/Restart/Logoff your PC using TweetMyPC</title>
		<link></link>
	</image>
	<description>
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.Enabled = True



 
The following code in Button&#39;s Click event will validate Twitter username, Password and save it to My.Settings. 
If txtUserName.Text.Trim = &amp;quot;&amp;quot; Then
    lblSatus.Text = &amp;quot;Please enter Twitter Username&amp;quot;
    txtUserName.Focus()
    Exit Sub
End If
If txtPassword.Text.Trim = &amp;quot;&amp;quot; Then
    lblSatus.Text = &amp;quot;Please enter Twitter Password&amp;quot;
    txtPassword.Focus()
    Exit Sub
End If

lblSatus.Text = &amp;quot;&amp;quot;


&#39;Check for valid Username and Password and then Save Settings
Dim objTwitter As New Yedda.Twitter
Dim Updates As XmlDocument

Try &#39;Try Logging in
    Updates = objTwitter.GetUserTimelineAsXML(txtUserName.Text.Trim, txtPassword.Text.Trim)
    My.Settings.UserName = txtUserName.Text.Trim
    My.Settings.Password = txtPassword.Text.Trim
    Me.WindowState = FormWindowState.Minimized
    Me.ShowInTaskbar = False
    tmrTweet.Enabled = True
Catch ex As Exception
    MsgBox(&amp;quot;Failed to Login to Twitter with the values supplied. Please check your login details.&amp;quot;)
    txtUserName.Focus()
    Exit Sub
End Try
Yedda library is used to login to Twitter to check for valid username and password. The Label
lblSatus is used to display any error messages. 
Add the following code to the Checkbox&#39;s CheckChanged event which will add the required registry keys to start this app on Window&#39;s startup 
If chkStartAutomatic.Checked = True Then&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; My.Settings.AutomaticStart = True
      Dim regKey As RegistryKey
      regKey = Registry.CurrentUser.OpenSubKey(&amp;quot;Software\Microsoft\Windows\CurrentVersion\Run&amp;quot;, True)
      regKey.SetValue(Application.ProductName, Application.ExecutablePath)
      regKey.Close()
Else
      My.Settings.AutomaticStart = False
      Dim regKey As RegistryKey
      regKey = Registry.CurrentUser.OpenSubKey(&amp;quot;Software\Microsoft\Windows\CurrentVersion\Run&amp;quot;, True)
      regKey.DeleteValue(Application.ProductName)
      regKey.Close()
End If
The following code in Timer&#39;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. 
If My.Settings.UserName.Trim = &amp;quot;&amp;quot; Then
    Exit Sub
Else
    &#39;Check for new Tweet 
    Dim objTwitter As New Yedda.Twitter
    Dim Updates As XmlDocument
    Dim node As XmlNode
    Try &#39;Try Logging in
        Updates = objTwitter.GetUserTimelineAsXML(My.Settings.UserName.Trim, My.Settings.Password.Trim)
        Catch ex As Exception
        MsgBox(&amp;quot;Error : Failed to Login to Twitter with the values supplied. Please check your login details.&amp;quot;)
        Exit Sub
    End Try
    Try
        node = Updates.SelectSingleNode(&amp;quot;/statuses/status/id&amp;quot;)
        If node.InnerText.Trim &amp;lt;&amp;gt; My.Settings.LastID.Trim Then 
            &#39;Compare the Tweet ID to check for new tweets
            My.Settings.LastID = node.InnerText.Trim
            node = Updates.SelectSingleNode(&amp;quot;/statuses/status/text&amp;quot;)
            ProcessTweet(node.InnerText.Trim)
          End If
    Catch ex As Exception
        Exit Sub
    End Try
End If
If the Tweet is new then we process the tweet. 
Private Sub ProcessTweet(ByVal Tweet As String)
    If Tweet = &amp;quot;Shutdown&amp;quot; Then
        System.Diagnostics.Process.Start(&amp;quot;shutdown&amp;quot;, &amp;quot;-s -f -t 100&amp;quot;) &#39;Shutdown
    ElseIf Tweet = &amp;quot;Logoff&amp;quot; Then
        System.Diagnostics.Process.Start(&amp;quot;shutdown&amp;quot;, &amp;quot;-l -f -t 100&amp;quot;) &#39;Logoff
    ElseIf Tweet = &amp;quot;Restart&amp;quot; Then
        System.Diagnostics.Process.Start(&amp;quot;shutdown&amp;quot;, &amp;quot;-r -f -t 100&amp;quot;) &#39; Restart
    End If
End Sub
The Context Menu strip has two menu items. They are Edit Setting and Exit. 
 
Add the following code the “Edit Settings” Client event and Notify Icon&#39;s Mouse Double Click Event.
 
tmrTweet.Enabled = False
txtUserName.Text = My.Settings.UserName.Trim
txtPassword.Text = My.Settings.Password.Trim
If My.Settings.AutomaticStart = True Then chkStartAutomatic.Checked = True
Me.WindowState = FormWindowState.Normal
Me.ShowInTaskbar = True
TweetMyPC runs silently on startup. To Edit Settings double click/Right Click the notify icon. 
Working





Conclusion
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. 
About The Author
Shoban Kumar is a Senior Software Engineer working for Allianz Cornhill India. Programming is his passion. He also writes about .net in
http://www.dotnetcurry.com/ and an active participator in
stackoverflow and speaker in
Microsoft user group sessions. You also can follow him in
Twitter. 
</description>
	<link></link>
	<language>en</language>
	<pubDate>Sun, 26 May 2013 04:20:05 GMT</pubDate>
	<lastBuildDate>Sun, 26 May 2013 04:20:05 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<item>
		<title>Re: Shutdown/Restart/Logoff your PC using TweetMyPC</title>
		<description>
			<![CDATA[ <p>So whats stopping me from say, joining twitter and constantly shutting down your computer? &nbsp;What a silly idea this is...</p><p>posted by John</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633814128000000000</link>
		<pubDate>Wed, 24 Jun 2009 04:00:00 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633814128000000000</guid>
		<dc:creator>John</dc:creator>
	</item>
	<item>
		<title>Re: Shutdown/Restart/Logoff your PC using TweetMyPC</title>
		<description>
			<![CDATA[ <p>Nice work. I haven't used Yedda, but I tried out Tweet# for my fun Twitter project: <a rel="nofollow" target="_new" href="http://blog.gadodia.net/twitter-profile-copier/">http://blog.gadodia.net/twitter-profile-copier/</a></p><p>posted by Vaibhav</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633814992000000000</link>
		<pubDate>Thu, 25 Jun 2009 04:00:00 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633814992000000000</guid>
		<dc:creator>Vaibhav</dc:creator>
	</item>
	<item>
		<title>Re: Shutdown/Restart/Logoff your PC using TweetMyPC</title>
		<description>
			<![CDATA[ <p>John, look at how he is handling the tweet. You won't be able to shutdown someone elses computer by sending them a tweet that says &quot;Shutdown&quot;</p><p>posted by Wayne</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633815856000000000</link>
		<pubDate>Fri, 26 Jun 2009 04:00:00 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633815856000000000</guid>
		<dc:creator>Wayne</dc:creator>
	</item>
	<item>
		<title>Re: Shutdown/Restart/Logoff your PC using TweetMyPC</title>
		<description>
			<![CDATA[ <p>Wow, this is cool. And @John, he is sending the tweet himself, so people can't send him a tweet with 'shutdown' like Wayne said. Gotta try this in C#</p><p>posted by Dominic</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633865104000000000</link>
		<pubDate>Sat, 22 Aug 2009 04:00:00 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633865104000000000</guid>
		<dc:creator>Dominic</dc:creator>
	</item>
	<item>
		<title>Re: Shutdown/Restart/Logoff your PC using TweetMyPC</title>
		<description>
			<![CDATA[ <p>@Ramana we have a few ideas on doing stuff like this <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif?v=c9' alt='Smiley' /></p><p>posted by Clint</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633876336000000000</link>
		<pubDate>Fri, 04 Sep 2009 04:00:00 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633876336000000000</guid>
		<dc:creator>Clint</dc:creator>
	</item>
	<item>
		<title>Re: Shutdown/Restart/Logoff your PC using TweetMyPC</title>
		<description>
			<![CDATA[ <p>Very cool app idea. Thanks.</p><p>Would love to see a follow up on switching on or off one's TV or other appliances remotely using VB.net and Twitter framework.</p><p>posted by Ramana</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633876336000000000</link>
		<pubDate>Fri, 04 Sep 2009 04:00:00 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633876336000000000</guid>
		<dc:creator>Ramana</dc:creator>
	</item>
	<item>
		<title>Re: Shutdown/Restart/Logoff your PC using TweetMyPC</title>
		<description>
			<![CDATA[ <p>@Rogue, click the &quot;Email Us&quot; link and I'll help debug this with you. &nbsp;It should just work as I've played with it but without seeing how you have yours set up, it could be some configuration Shoban didn't account for.</p><p>From the link we listed, there is a newer release as well. &nbsp;<a rel="nofollow" target="_new" href="http://tweetmypc.codeplex.com/Release/ProjectReleases.aspx">http://tweetmypc.codeplex.com/Release/ProjectReleases.aspx</a></p><p>posted by Clint</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633982644000000000</link>
		<pubDate>Tue, 05 Jan 2010 05:00:00 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633982644000000000</guid>
		<dc:creator>Clint</dc:creator>
	</item>
	<item>
		<title>Re: Shutdown/Restart/Logoff your PC using TweetMyPC</title>
		<description>
			<![CDATA[ <p>Not loving the lack of documentation on setup and using this thing. Like, it's obvious that you enter your authentication info then click save and then tweet your PC to shutdown. Well, I created a new account with twitter and it doesn't recognize it on the app. The &quot;what to expect&quot; would be helpful as a read me to the app. As far as coding it, and compiling my own version, it seems awesome and I'm looking forward to giving it a shot.</p><p>posted by Rogue</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633982644000000000</link>
		<pubDate>Tue, 05 Jan 2010 05:00:00 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c633982644000000000</guid>
		<dc:creator>Rogue</dc:creator>
	</item>
	<item>
		<title>Re: Shutdown/Restart/Logoff your PC using TweetMyPC</title>
		<description>
			<![CDATA[ <p>Nice Thinking and different approach <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif?v=c9' alt='Smiley' />.. Kudos </p><p>posted by Dhanesh</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c634003380000000000</link>
		<pubDate>Fri, 29 Jan 2010 05:00:00 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c634003380000000000</guid>
		<dc:creator>Dhanesh</dc:creator>
	</item>
	<item>
		<title>Re: Shutdown/Restart/Logoff your PC using TweetMyPC</title>
		<description>
			<![CDATA[ <p>Cool Shoban..I'll see if this works..I recently read of this being implemented using smses,but using twitter is a easy solution <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif?v=c9' alt='Smiley' /></p><p>posted by Raj</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c634005108000000000</link>
		<pubDate>Sun, 31 Jan 2010 05:00:00 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/articles/ShutdownRestartLogoff-your-PC-using-TweetMyPC#c634005108000000000</guid>
		<dc:creator>Raj</dc:creator>
	</item>
</channel>
</rss>