<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>API Programming &#187; Microsoft</title>
	<atom:link href="http://www.brangle.com/wordpress/tag/microsoft/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brangle.com/wordpress</link>
	<description>Just another computer weblog</description>
	<lastBuildDate>Tue, 08 Sep 2009 05:41:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to Use the Progress Bar in VB.NET and C#</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-use-the-progress-bar-in-vb-net-and-c-sharp/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-use-the-progress-bar-in-vb-net-and-c-sharp/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 03:32:38 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=566</guid>
		<description><![CDATA[The progress bar is one of those universal objects that everyone recognizes, it's useful when doing a large or long task.  For example, if your updating/deleting/copying a bunch of files you can update the progress bar as you modify each file.]]></description>
			<content:encoded><![CDATA[<p>The progress bar is one of those universal objects that everyone recognizes, it&#8217;s useful when doing a large or long task.  For example, if your updating/deleting/copying a bunch of files you can update the progress bar as you modify each file.<span id="more-566"></span></p>
<div id="attachment_567" class="wp-caption aligncenter" style="width: 298px"><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/ProgressBarApp.jpg" alt="Progress Bar App with VB.NET and C#" title="Progress Bar App with VB.NET and C#" width="288" height="121" class="size-full wp-image-567" /><p class="wp-caption-text">Progress Bar App with VB.NET and C#</p></div>
<p>There are several lines of code to pay attention to, let me outline them here in further detail.<br />
<b>Line 7</b> &#8211; we can think of the maximum as how many steps their are.  We can say we want a 1000 steps, or only 20 steps.  This makes it useful if you want to update a random number of objects stored in an array, in that case we could store the <i>ProgressBar1.Maximum = UBound(arrSomeArray)</i>.<br />
<b>Line 9</b> &#8211; we are just initializing our progress bar to 0<br />
<b>Line 11</b> &#8211; we make the progress bar visible.  This step is up to you, I infrequently use the progress bar and I usually keep it hidden until I have a reason to display it.  If your progress bar is already visible you can delete this line of code<br />
<b>Line 13</b> &#8211; this line is completely unrelated to the progress bar, whatever value is specified in the <i>Sleep</i> argument is how long your application will wait to update.  In this application, I decided to wait 1000 milliseconds (or 1 second) before I goto the next step, this will allow us to see the progress bar update so we can simulate a test scenario.<br />
<b>Line 15-29</b> &#8211; This is just updating the progress bar, then waiting some more, nothing to special going on here. As you can see the value I am raising the progress bar is completely arbitrary.<br />
<b>Line 30</b> &#8211; Print out a message box saying complete<br />
<b>Line 31</b> &#8211; Hide the progress bar so that it is no longer visible, we&#8217;ve already told the user that the task is complete, there&#8217;s no need to continue showing the progress bar. Again, this line of code is entirely up to you.</p>
<p><b>This is the code for a VB.NET progress bar example</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'This code was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #008080; font-style: italic;">'Complete source code is available at:</span>
<span style="color: #008080; font-style: italic;">'http://www.brangle.com/wordpress/2009/08/how-to-use-the-progress-bar-in-vb-net-and-c-sharp/</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> Button1_Click<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> Button1.<span style="color: #0000FF;">Click</span>
    <span style="color: #008080; font-style: italic;">'Set the total number of steps to 100 (or 100%)</span>
    ProgressBar1.<span style="color: #0000FF;">Maximum</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>
    <span style="color: #008080; font-style: italic;">'Set the initial value of the progress bar to 0% completed</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>
    <span style="color: #008080; font-style: italic;">'If your progress bar is already visible you don't need this. But this is one of those objects I like to hide when I'm not using it</span>
    ProgressBar1.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
    <span style="color: #008080; font-style: italic;">'This next line tells your application to wait or go to sleep for 1000ms / 1 second</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    <span style="color: #008080; font-style: italic;">'Update the progress bar to 15% completed</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span>
    <span style="color: #008080; font-style: italic;">'Wait for another second</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    <span style="color: #008080; font-style: italic;">'Update to 30% complete</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">30</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">45</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">60</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">75</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">90</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>
    <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Complete!&quot;</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

<p><b>This is the source code for a C# progress bar example</b><br />
The code only varies slightly in C#, I&#8217;ll make sure to explain any differences.  Besides the semicolons at the end of every line, only lines 12, 31, and 32 differ from the VB.NET example.<br />
<b>Line 12, Line 32</b> &#8211; Boolean values must be in lower case.<br />
<b>Line 31</b> &#8211; Showing a message box is slightly different in VB.NET, if you didn&#8217;t add the following headers <i>using System.Windows.Forms;</i> in your source code, then you will need to specify the full class name.  I included it so that this example can work on as many peoples projects as possible.  If you are already including <i>Systems.Windows.Forms</i> then you can show a message box by replacing line 31 with: <i>MessageBox.Show(&#8220;Complete!&#8221;);</i></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//This code was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #666666;">//Complete source code is available at:</span>
<span style="color: #666666;">//http://www.brangle.com/wordpress/2009/08/how-to-use-the-progress-bar-in-vb-net-and-c-sharp/</span>
&nbsp;
<span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> button1_Click<span style="color: #008000;">&#40;</span>object sender, EventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">//Set the total number of steps to 100 (or 100%)</span>
    progressBar1.<span style="color: #007788;">Maximum</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">100</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//Set the initial value of the progress bar to 0% completed</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//If your progress bar is already visible you don't need this. But this is one of those objects I like to hide when I'm not using it</span>
    progressBar1.<span style="color: #007788;">Visible</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//This next line tells your application to wait or go to sleep for 1000ms / 1 second</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//Update the progress bar to 15% completed</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">15</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//Wait for another second</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//Update to 30% complete</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">30</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">45</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">60</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">75</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">90</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">100</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Windows</span>.<span style="color: #007788;">Forms</span>.<span style="color: #007788;">MessageBox</span>.<span style="color: #007788;">Show</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Complete!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Visible</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-use-the-progress-bar-in-vb-net-and-c-sharp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Center A Form in VB.NET and C#</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-center-a-form-in-vb-net-and-c-sharp/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-center-a-form-in-vb-net-and-c-sharp/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 05:41:30 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=550</guid>
		<description><![CDATA[I've often found it necessary to center a form on my screen using the pure code, but it's not as easy as <i>Me.center</i> in VB or <i>this.center()</i> in C# so I wrote some code to work around that. Using the code below you can center you application on your monitor in just 3 lines of code using either VB.NET or C#.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve often found it necessary to center a form on my screen using the pure code, but it&#8217;s not as easy as <i>Me.center</i> in Visual Basic or <i>this.center()</i> in C# so I wrote some code to work around that. Using the code below you can center you application on your monitor in just 3 lines of code using either VB.NET or C#.<span id="more-550"></span></p>
<p>The first thing you&#8217;ll notice is that I&#8217;m using <i>Screen.PrimaryScreen.WorkingArea</i> and not <i>Screen.PrimaryScreen.Bounds</i>, the bounds of the screen will give me the actual height/width of the monitor as coordinates.  But what it doesn&#8217;t take into account like the WorkingArea does are any docked items, such as the toolbar.  The WorkingArea returns the Bounds, and subtracts off any area unusable by the program to give us the &#8220;true&#8221; center.</p>
<p><b>(Source Code) Recenter your window using VB.NET</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'This code was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #008080; font-style: italic;">'Complete source code is available at:</span>
<span style="color: #008080; font-style: italic;">'http://www.brangle.com/wordpress/2009/08/how-to-center-a-form-in-vb-net-and-c-sharp/</span>
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> Button1_Click<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> Button1.<span style="color: #0000FF;">Click</span>
    <span style="color: #008080; font-style: italic;">'Get the working area of the screen and assign it to a rectangle object</span>
    <span style="color: #0600FF;">Dim</span> rect <span style="color: #FF8000;">As</span> Rectangle <span style="color: #008000;">=</span> Screen.<span style="color: #0000FF;">PrimaryScreen</span>.<span style="color: #0000FF;">WorkingArea</span>
    <span style="color: #008080; font-style: italic;">'Divide the screen in half, and find the center of the form to center it</span>
    <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Top</span> <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>rect.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>
    <span style="color: #FF8000;">Me</span>.<span style="color: #0600FF;">Left</span> <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>rect.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Me</span>.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

<p><b>(Source Code) Recenter your window using C#</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//This code was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #666666;">//Complete source code is available at:</span>
<span style="color: #666666;">//http://www.brangle.com/wordpress/2009/08/how-to-center-a-form-in-vb-net-and-c-sharp/</span>
<span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> button1_Click<span style="color: #008000;">&#40;</span>object sender, EventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">//Get the working area of the screen and assign it to a rectangle object   </span>
   Rectangle rect <span style="color: #000080;">=</span> Screen.<span style="color: #007788;">PrimaryScreen</span>.<span style="color: #007788;">WorkingArea</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//Divide the screen in half, and find the center of the form to center it</span>
   <span style="color: #0000dd;">this</span>.<span style="color: #007788;">Top</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>rect.<span style="color: #007788;">Height</span> <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">this</span>.<span style="color: #007788;">Height</span> <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
   <span style="color: #0000dd;">this</span>.<span style="color: #007788;">Left</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>rect.<span style="color: #007788;">Width</span> <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">this</span>.<span style="color: #007788;">Width</span> <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-center-a-form-in-vb-net-and-c-sharp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Cut/Copy/Paste into the Clipboard using VB.NET</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-cutcopypaste-text-into-clipboard-using-vb-net/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-cutcopypaste-text-into-clipboard-using-vb-net/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 04:45:56 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=527</guid>
		<description><![CDATA[In this example, I'll show you how to cut, copy, paste and clear text in the clipboard. Cutting and copying text is really straight forward, pasting text requires just a little bit of checking.  For example, we want to check to see what the clipboard contains before we try and do something like pasting an image into a text box.]]></description>
			<content:encoded><![CDATA[<p>In this example, I&#8217;ll show you how to cut, copy, paste and clear text in the clipboard. Cutting and copying text is really straight forward, pasting text requires just a little bit of checking.  For example, we want to check to see what the clipboard contains before we try and do something like pasting an image into a text box.<span id="more-527"></span></p>
<p>To copy text, its just a simple one-liner:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">Clipboard.<span style="color: #0000FF;">SetText</span><span style="color: #000000;">&#40;</span>txtTextBox.<span style="color: #0000FF;">SelectedText</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>To cut text, it&#8217;s almost as simple as copying it, but we need to remember to delete the data from the text box once it&#8217;s been copied:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">Clipboard.<span style="color: #0000FF;">SetText</span><span style="color: #000000;">&#40;</span>txtTextBox.<span style="color: #0000FF;">SelectedText</span><span style="color: #000000;">&#41;</span>
txtTextBox.<span style="color: #0000FF;">SelectedText</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span></pre></div></div>

<p>To paste text there&#8217;s several things we have to worry about like I mentioned above.  We first want to check what&#8217;s in the clipboard and verify that the contents of the clipboard can be pasted into whatever field/object we are trying to paste them into.  In this example, I&#8217;m going to use the GetText method to make sure I only get the text from the clipboard and paste it into the text field.  In the example below, I&#8217;ll get the data from the clipboard, then check to see if it is text before pasting it.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">txtTextBox.<span style="color: #0000FF;">SelectedText</span> <span style="color: #008000;">=</span> Clipboard.<span style="color: #0000FF;">GetText</span></pre></div></div>

<p><div id="attachment_529" class="wp-caption aligncenter" style="width: 228px"><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/CutCopyPasteApp.jpg" alt="Cut Copy Paste for .NET Applications" title="Cut Copy Paste for .NET Applications" width="218" height="140" class="size-full wp-image-529" /><p class="wp-caption-text">Cut Copy Paste for .NET Applications</p></div> Here are the names for each of the objects in the above photo, txtTextBox, btnCut, btnCopy, btnPaste each represent the text box, cut button, copy button, and paste button respectively.  I&#8217;ll use the same variable names in each programming language below.</p>
<h2>&nbsp; </h2>
<p><b>This is the code for the above program written in VB.NET</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'This code was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #008080; font-style: italic;">'Complete source code is available at:</span>
<span style="color: #008080; font-style: italic;">'http://www.brangle.com/wordpress/2009/08/how-to-cutcopypaste-text-into-clipboard-using-vb-net/</span>
&nbsp;
<span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> Form1
    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> btnCut_Click<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> btnCut.<span style="color: #0000FF;">Click</span>
        <span style="color: #008080; font-style: italic;">'Checks to see if the user selected anything</span>
        <span style="color: #0600FF;">If</span> txtTextBox.<span style="color: #0000FF;">SelectedText</span> &lt;&gt; <span style="color: #808080;">&quot;&quot;</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #008080; font-style: italic;">'Good, the user selected something</span>
            <span style="color: #008080; font-style: italic;">'Copy the information to the clipbaord</span>
            Clipboard.<span style="color: #0000FF;">SetText</span><span style="color: #000000;">&#40;</span>txtTextBox.<span style="color: #0000FF;">SelectedText</span><span style="color: #000000;">&#41;</span>
            <span style="color: #008080; font-style: italic;">'Since this is a cut command, we want to clear whatever </span>
            <span style="color: #008080; font-style: italic;">'text they had selected when they clicked cut</span>
            txtTextBox.<span style="color: #0000FF;">SelectedText</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span>
        <span style="color: #FF8000;">Else</span>
            <span style="color: #008080; font-style: italic;">'If there was no text selected, print out an error message box</span>
            <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;No text is selected to cut&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> btnCopy_Click<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> btnCopy.<span style="color: #0000FF;">Click</span>
        <span style="color: #008080; font-style: italic;">'Checks to see if the user selected anything</span>
        <span style="color: #0600FF;">If</span> txtTextBox.<span style="color: #0000FF;">SelectedText</span> &lt;&gt; <span style="color: #808080;">&quot;&quot;</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #008080; font-style: italic;">'Copy the information to the clipboard</span>
            Clipboard.<span style="color: #0000FF;">SetText</span><span style="color: #000000;">&#40;</span>txtTextBox.<span style="color: #0000FF;">SelectedText</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Else</span>
            <span style="color: #008080; font-style: italic;">'If no text was selected, print out an error message box</span>
            <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;No text is selected to copy&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> btnPaste_Click<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> btnPaste.<span style="color: #0000FF;">Click</span>
        <span style="color: #008080; font-style: italic;">'Get the data stored in the clipboard</span>
        <span style="color: #0600FF;">Dim</span> iData <span style="color: #FF8000;">As</span> IDataObject <span style="color: #008000;">=</span> Clipboard.<span style="color: #0000FF;">GetDataObject</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #008080; font-style: italic;">'Check to see if the data is in a text format</span>
        <span style="color: #0600FF;">If</span> iData.<span style="color: #0000FF;">GetDataPresent</span><span style="color: #000000;">&#40;</span>DataFormats.<span style="color: #0000FF;">Text</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #008080; font-style: italic;">'If it's text, then paste it into the textbox</span>
            txtTextBox.<span style="color: #0000FF;">SelectedText</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span>iData.<span style="color: #0000FF;">GetData</span><span style="color: #000000;">&#40;</span>DataFormats.<span style="color: #0000FF;">Text</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Else</span>
            <span style="color: #008080; font-style: italic;">'If it's not text, print a warning message</span>
            <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Data in the clipboard is not availble for entry into a textbox&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></pre></td></tr></table></div>

<p>Now in general, I don&#8217;t think that the clipboard should be cleared by the programmer, it should be cleared by the user.  But if you have a legitimate reason to clear the clipboard, here&#8217;s the code to do just that:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">Clipboard.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-cutcopypaste-text-into-clipboard-using-vb-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Make Your Computer Talk with VB.NET Application (and Source Code)</title>
		<link>http://www.brangle.com/wordpress/2009/08/make-your-computer-talk-with-vb-net-application-and-source-code/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/make-your-computer-talk-with-vb-net-application-and-source-code/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 02:57:25 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Downloads]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[XP]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=502</guid>
		<description><![CDATA[I was playing around with COM objects in Windows and discovered that I could access the SAPI.SpVoice interface and make Microsoft Windows talk to me.  Well needless to say I had to rush and develop and application to do just that.  I uploaded a simple applicaton which will just say whatever you type in as an argument.  For example <i>SpeakToMeConsole.exe Hello World</i> will make your computer speak the words "Hello World."  The part that really amazes me is that the guts of this program is only 2 lines long, and it can even that can reduced down to 1 line if we create an anonymous instance of SAPI.SpVoice object.]]></description>
			<content:encoded><![CDATA[<p>I was playing around with COM objects in Windows and discovered that I could access the SAPI.SpVoice interface and make Microsoft Windows talk to me.  Well needless to say I had to rush and develop and application to do just that.  I uploaded a simple applicaton which will just say whatever you type in as an argument.  For example <i>SpeakToMeConsole.exe Hello World</i> will make your computer speak the words &#8220;Hello World.&#8221;  The part that really amazes me is that the guts of this program is only 2 lines long, and it can even that can reduced down to 1 line if we create an anonymous instance of SAPI.SpVoice object.<span id="more-502"></span></p>
<p>The reason I created it as a console application and not a windows app is because I envisioned this program only really only having a valid function when it&#8217;s called from another application. Or even better, you want to spook your girlfriend or parents by making their laptop talk to them when it turns on!  Whatever your reasons are, enjoy! Oh and let me know how you use this program in the comments.</p>
<div id="attachment_506" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.brangle.com/downloads/SpeakToMe/v1.0/SpeakToMeConsole.exe"><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/download-button.jpg" alt="Download SpeakToMe App" title="Download SpeakToMe App" width="150" height="144" class="size-full wp-image-506" /></a><p class="wp-caption-text">Download SpeakToMe App</p></div>
<p>Here is the complete source code to the above application. Let me know what you think in the comments!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'This application was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #008080; font-style: italic;">'Complete source code is available at:</span>
<span style="color: #008080; font-style: italic;">'http://www.brangle.com/wordpress/2009/08/make-your-computer-talk-with-vb-net-app-source-code/</span>
&nbsp;
&nbsp;
Module Module1
    <span style="color: #008080; font-style: italic;">'We want to make sure we grab any arguments as args so that we speak them    </span>
    <span style="color: #0600FF;">Sub</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> args <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #008080; font-style: italic;">'If there are no arguments UBound will return -1</span>
        <span style="color: #008080; font-style: italic;">'Therefore we want to make sure to let the user know how to run the app if </span>
        <span style="color: #008080; font-style: italic;">'they don't enter any arguments</span>
        <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">UBound</span><span style="color: #000000;">&#40;</span>args<span style="color: #000000;">&#41;</span> &gt; <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span> <span style="color: #FF8000;">Then</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'Generate an empty string, we'll use this to concatenate all of our arguments </span>
            <span style="color: #008080; font-style: italic;">'together so we can pass it to the narrator</span>
            <span style="color: #0600FF;">Dim</span> <span style="color: #FF8000;">input</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'Concat all of our arguments together and make sure to put a space in </span>
            <span style="color: #008080; font-style: italic;">'between them so the words don't run together</span>
            <span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> arg <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> In args
                <span style="color: #FF8000;">input</span> <span style="color: #008000;">=</span> <span style="color: #FF8000;">input</span> <span style="color: #008000;">+</span> arg <span style="color: #008000;">+</span> <span style="color: #808080;">&quot; &quot;</span>
            <span style="color: #FF8000;">Next</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'Create an object and gain access to the narrator</span>
            <span style="color: #0600FF;">Dim</span> voice <span style="color: #008000;">=</span> <span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;SAPI.SpVoice&quot;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #008080; font-style: italic;">'Tells the narrator what to say</span>
            voice.<span style="color: #0000FF;">Speak</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">input</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Else</span>
            <span style="color: #008080; font-style: italic;">'The is where we tell the user what to say if they didn't enter any arguments</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;No arguments specified&quot;</span><span style="color: #000000;">&#41;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Try this instead: SpeakToMe.exe Hello World&quot;</span><span style="color: #000000;">&#41;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>vbCrLf <span style="color: #008000;">+</span> vbCrLf <span style="color: #008000;">+</span> <span style="color: #808080;">&quot;Visit www.brangle.com for other apps&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
<span style="color: #0600FF;">End</span> Module
<span style="color: #008080; font-style: italic;">'The End</span></pre></td></tr></table></div>

<p>To run this program from the command line, you can type in something like the following:</p>
<pre>SpeakToMeConsole.exe Hello World</pre>
<p>And here is the beautiful one-liner!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;SAPI.SpVoice&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Speak</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;hello from brangle.com&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/make-your-computer-talk-with-vb-net-application-and-source-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Shutdown, Restart, Log off your computer with VB.NET or C#</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-shutdown-restart-log-off-your-computer-with-vb-net-or-c/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-shutdown-restart-log-off-your-computer-with-vb-net-or-c/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 08:27:06 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Sever 2003]]></category>
		<category><![CDATA[Vista]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[XP]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=458</guid>
		<description><![CDATA[This is extremely easy using VB.NET or C# (pronounced C sharp) and using the built in windows EXE file <i>shutdown.exe</i>.  To shutdown, restart, or log off your computer is as simple as entering 1 line into your program, it just so happens that the 1 line is identical whether you're using VB.NET or C#.]]></description>
			<content:encoded><![CDATA[<p>This is extremely easy using VB.NET or C# (pronounced C sharp) and the built in windows EXE file <i>shutdown.exe</i>.  To shutdown, restart, or log off your computer is as simple as entering 1 line into your program, it just so happens that the 1 line is identical whether you&#8217;re using VB.NET or C#.<span id="more-458"></span></p>
<p>To shutdown/turn off your computer, just execute the following line of code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">System.Diagnostics.Process.Start(<span style="color: #800000;">&quot;shutdown.exe&quot;</span>, <span style="color: #800000;">&quot;-s -t 0&quot;</span>)</pre></td></tr></table></div>

<p>To restart/reboot your computer, just execute the following line of code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">System.Diagnostics.Process.Start(<span style="color: #800000;">&quot;shutdown.exe&quot;</span>, <span style="color: #800000;">&quot;-r -t 0&quot;</span>)</pre></td></tr></table></div>

<p>To log off your computer, just execute the following line of code (and yes, that&#8217;s a lowercase L, not the number 1):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">System.Diagnostics.Process.Start(<span style="color: #800000;">&quot;shutdown.exe&quot;</span>, <span style="color: #800000;">&quot;-l -t 0&quot;</span>)</pre></td></tr></table></div>

<p>The number zero at the end of each of those examples is how long the computer should wait in seconds before shutting down/restarting/etc&#8230; In this example, I&#8217;m going to shutdown the computer in 5 minutes (5 minutes * 60 seconds = 300 seconds)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">System.Diagnostics.Process.Start(<span style="color: #800000;">&quot;shutdown.exe&quot;</span>, <span style="color: #800000;">&quot;-s -t 300&quot;</span>)</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-shutdown-restart-log-off-your-computer-with-vb-net-or-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Create Message Box Pop Ups in VB.NET</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-create-message-box-pop-ups-in-vbnet/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-create-message-box-pop-ups-in-vbnet/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 07:25:00 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=431</guid>
		<description><![CDATA[Creating different types of messages boxes in Visual Basic is a simple one line statement.  I'm going to run through how to create several different types of message boxes in this tutorial, including OK Only, OK/Cancel, Abort/Retry/Ignore, and a Critical message box.]]></description>
			<content:encoded><![CDATA[<p>Creating different types of messages boxes in Visual Basic is a simple one line statement.  I&#8217;m going to run through how to create several different types of message boxes in this tutorial, including OK Only, OK/Cancel, Abort/Retry/Ignore, and a Critical message box.<span id="more-431"></span></p>
<p>The simplest message box, it only includes an OK button&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Hello World!&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/MsgBoxOnly.jpg" alt="MsgBoxOnly" title="MsgBoxOnly" width="161" height="100" class="alignnone size-full wp-image-434" /><br />
<br /><br /><br /></p>
<p>Ok, so the title of the message box the name of the project, let&#8217;s add our own title as the third argument, but first we&#8217;ll need to tell VB that we want to have this message box act as an OK only.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Hello World!&quot;</span>, MsgBoxStyle.<span style="color: #0600FF;">OkOnly</span>, <span style="color: #808080;">&quot;www.brangle.com&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/MsgBoxOnlyWithTitle.jpg" alt="MsgBoxOnlyWithTitle" title="MsgBoxOnlyWithTitle" width="143" height="100" class="alignnone size-full wp-image-435" /><br />
<br /><br /><br /></p>
<p>The next message box is the OK/Cancel with a custom title.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Visit brangle.com?&quot;</span>, MsgBoxStyle.<span style="color: #0600FF;">OkCancel</span>, <span style="color: #808080;">&quot;www.brangle.com&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/MsgBoxOKCancelWithTitle.jpg" alt="MsgBoxOKCancelWithTitle" title="MsgBoxOKCancelWithTitle" width="185" height="100" class="alignnone size-full wp-image-439" /><br />
<br /><br /><br /></p>
<p>OK great, but this time lets detect whether the user clicked OK or Cancel.  If the user clicks OK, We&#8217;ll launch my website <img src='http://www.brangle.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  otherwise we&#8217;ll do nothing.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">If</span> <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Visit brangle.com?&quot;</span>, MsgBoxStyle.<span style="color: #0600FF;">OkCancel</span>, <span style="color: #808080;">&quot;www.brangle.com&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> MsgBoxResult.<span style="color: #0600FF;">Ok</span> <span style="color: #FF8000;">Then</span>
     Process.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;http://www.brangle.com/&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span></pre></td></tr></table></div>

<p><br /><br /><br /></p>
<p>Let&#8217;s try using an Abort/Retry/Ignore message box.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Dim</span> result <span style="color: #FF8000;">As</span> DialogResult
result <span style="color: #008000;">=</span> <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Corrupt File. Try Again?&quot;</span>, MsgBoxStyle.<span style="color: #0600FF;">AbortRetryIgnore</span>, <span style="color: #808080;">&quot;www.brangle.com&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">If</span> result <span style="color: #008000;">=</span> Windows.<span style="color: #0000FF;">Forms</span>.<span style="color: #0000FF;">DialogResult</span>.<span style="color: #0600FF;">Abort</span> <span style="color: #FF8000;">Then</span>
   <span style="color: #008080; font-style: italic;">'Do some action to abort opening the file</span>
   <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;You clicked abort&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">ElseIf</span> result <span style="color: #008000;">=</span> Windows.<span style="color: #0000FF;">Forms</span>.<span style="color: #0000FF;">DialogResult</span>.<span style="color: #0600FF;">Retry</span> <span style="color: #FF8000;">Then</span>
   <span style="color: #008080; font-style: italic;">'Do some action to retry opening the file</span>
   <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;You clicked retry&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">ElseIf</span> result <span style="color: #008000;">=</span> Windows.<span style="color: #0000FF;">Forms</span>.<span style="color: #0000FF;">DialogResult</span>.<span style="color: #0600FF;">Ignore</span> <span style="color: #FF8000;">Then</span>
   <span style="color: #008080; font-style: italic;">'Do some action to ignore</span>
   <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;You clicked ignore&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span></pre></td></tr></table></div>

<p><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/MsgBoxAbortRetryIgnore.jpg" alt="MsgBoxAbortRetryIgnore" title="MsgBoxAbortRetryIgnore" width="266" height="100" class="alignnone size-full wp-image-450" /><br />
<br /><br /><br /></p>
<p>Now let&#8217;s launch a message box as critical, this will display the red icon with x thru it</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;File not found!&quot;</span>, MsgBoxStyle.<span style="color: #0600FF;">Critical</span>, <span style="color: #808080;">&quot;Error&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/MsgBoxCritical.jpg" alt="MsgBoxCritical" title="MsgBoxCritical" width="146" height="119" class="alignnone size-full wp-image-452" /><br />
<br /><br /><br /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-create-message-box-pop-ups-in-vbnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Combine or Join Two Text Files Using PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/08/combine-join-two-text-files-using-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/combine-join-two-text-files-using-powershell/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 03:28:37 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=422</guid>
		<description><![CDATA[Merging files together, or to a seperate file, is a snap with PowerShell using the <i>Get-Content</i> cmdlet.  If you've never used the Add-Content cmdlet, I would suggest first reading my other article <a href="/wordpress/2009/08/append-text-to-a-file-using-add-content-in-powershell/" target="_top">Append Text to a File Using Add-Content</a>.  The first thing we need to do is identify our two files, in my case I'll be using <i>file1.log</i> and <i>file2.log</i>.  In the first example, I append all the text of <i>file2.log</i> into the end of <i>file1.log</i>.  In the second example, I'll create a completely new file and dump the contents of both the files into the newly created file.  In the last example, I'll add the current date to the filename of a completly new log file.]]></description>
			<content:encoded><![CDATA[<p>Merging files together, or to a seperate file, is a snap with PowerShell using the <i>Get-Content</i> cmdlet.  If you&#8217;ve never used the Add-Content cmdlet, I would suggest first reading my other article <a href="/wordpress/2009/08/append-text-to-a-file-using-add-content-in-powershell/" target="_top">Append Text to a File Using Add-Content</a>.  The first thing we need to do is identify our two files, in my case I&#8217;ll be using <i>file1.log</i> and <i>file2.log</i>.  In the first example, I append all the text of <i>file2.log</i> into the end of <i>file1.log</i>.  In the second example, I&#8217;ll create a completely new file and dump the contents of both the files into the newly created file.  In the last example, I&#8217;ll add the current date to the filename of a completly new log file.<span id="more-422"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$file2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file2.log&quot;</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file1.log&quot;</span> $file2</pre></td></tr></table></div>

<p>Now, what if we want to copy the contents of <i>file1.log</i> and <i>file2.log</i> into a completely new file called <i>file3.log</i></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">New-Item</span> <span style="color: #008080; font-style: italic;">-ItemType</span> file <span style="color: #800000;">&quot;file3.log&quot;</span>
<span style="color: #800080;">$file1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file1.log&quot;</span>
<span style="color: #800080;">$file2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file2.log&quot;</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> <span style="color: #800080;">$file1</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> $file2</pre></td></tr></table></div>

<p>What if we want to erase everything in file3.log before we add new content? In this case, instead of creating a new file, we&#8217;ll use the Clear-Contents cmdlet.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Clear-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span>
<span style="color: #800080;">$file1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file1.log&quot;</span>
<span style="color: #800080;">$file2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file2.log&quot;</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> <span style="color: #800080;">$file1</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> $file2</pre></td></tr></table></div>

<p>Ok, well, what if I don&#8217;t know if file3.log already exists? If it doesn&#8217;t exist and I run the Clear-Contents cmdlet then I&#8217;ll get an error. And if it does exist and I try to create it as a new file I&#8217;ll still get an error.  There&#8217;s an easy way to do this, we&#8217;ll use the New-Item cmdlet from the example above, but we&#8217;ll add the -force argument, so even if the file exists it will overwrite it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">New-Item</span> <span style="color: #008080; font-style: italic;">-ItemType</span> file <span style="color: #800000;">&quot;file3.log&quot;</span> <span style="color: #008080; font-style: italic;">-force</span>
<span style="color: #800080;">$file1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file1.log&quot;</span>
<span style="color: #800080;">$file2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file2.log&quot;</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> <span style="color: #800080;">$file1</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> $file2</pre></td></tr></table></div>

<p>Alright, so I guess I got the hang of this, now lastly since these are log files, how can I append the date to the file name? Simple, with the <i>Get-Date</i> cmdlet.  Let&#8217;s output our file name as YYYYMMDD-WebAccess.log in this example.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$date</span><span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.ToString<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;yyyyMMdd&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$NewFileName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;$date-WebAccess.log&quot;</span>
<span style="color: #008080; font-weight: bold;">New-Item</span> <span style="color: #008080; font-style: italic;">-ItemType</span> file <span style="color: #800080;">$NewFileName</span>
<span style="color: #800080;">$file1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file1.log&quot;</span>
<span style="color: #800080;">$file2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file2.log&quot;</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800080;">$NewFileName</span> <span style="color: #800080;">$file1</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800080;">$NewFileName</span> $file2</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/combine-join-two-text-files-using-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Add or Map a Custom Hostnames to IP Address without a DNS Server</title>
		<link>http://www.brangle.com/wordpress/2009/08/add-or-map-custom-hostnames-to-ip-address-without-dns-server/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/add-or-map-custom-hostnames-to-ip-address-without-dns-server/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 07:32:14 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iTouch]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Registry]]></category>
		<category><![CDATA[Sever 2003]]></category>
		<category><![CDATA[Vista]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[XP]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=400</guid>
		<description><![CDATA[There's been several times where I had an Apache server running locally on my computer as a development (or dev) server.  Now if this is on my home network, or if your system administrator won't give you your own custom host name then you have to go the DIY (do it yourself) route.  But, often times, I have to hard code host names, or I need several different websites hosted on my personal machine.  Well that's where the <i>hosts</i> file comes into play.]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s been several times where I had an Apache server running locally on my computer as a development (or dev) server.  Now if this is on my home network, or if your system administrator won&#8217;t give you your own custom host name then you have to go the DIY (do it yourself) route.  But, often times, I have to hard code host names, or I need several different websites hosted on my personal machine.  Well that&#8217;s where the <i>hosts</i> file comes into play.<span id="more-400"></span></p>
<p>Another example of needing a custom ip address is at my company, I&#8217;ve needed to check the status of a printer and if I want to try the access it via its hostname <i>http://printername</i> it wont work because the SysAdmin has shared the printer on the network without adding a custom dns host name, even though it has a static IP address on the network. So I added the name of each printer to my <i>hosts</i> file so now I have no problem accessing any printer via its name, without having to first look up its IP address.<!--more--></p>
<p>Also, if you intend to <b>block a website by its hostname</b> then this is also the solution for you.</p>
<p>You can find the <i>hosts</i> file in the following folder&#8230;<br />
Windows 95, 98, and ME in the %WinDir%\ directory<br />
NT, 2000, XP, 2003, Vista, 7 in the %SystemRoot%\system32\drivers\etc\ directory (%SystemRoot% is almost always C:\Windows)<br />
iPhone and iTouch in the /private/etc/hosts directory<br />
Linux in the /etc/hosts directory</p>
<p>Also, a note for 0.1% of Windows NT, 2000, XP, 2003, Vista, and Windows 7 users, the actual location may differ, to find the real location you&#8217;ll need to dig into the registry key, give the following a look up</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="regedit" style="font-family:monospace;">HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters</pre></td></tr></table></div>

<p> and look for the following string key <i>DataBasePath</i>.  On my computer it was declared as <i>%SystemRoot%\System32\drivers\etc</i>  I know that&#8217;s what I said it would be above, I just want all you SysAdmins to be aware of that 0.1% chance.</p>
<p>Lastly once, you finish making any modifications you&#8217;ll need to flush your locally cached DNS on your computer. </p>
<p>In WinXP you can edit the <i>c:\windows\system32\drivers\etc\hosts</i> file by opening it in notepad or any ascii text editor. By default the last line you&#8217;ll see is
<pre>127.0.0.1       localhost</pre>
<p> but other programs can change this.  The IP address 127.0.0.1 is always the ip address of the local computer.  It doesn&#8217;t matter if the computer has a different IP address on the network, 127.0.0.1 is considered a loop back address, in other words, it always points to your computer.</p>
<p>you can add a new hostname followed by the ip address in the text file that&#8217;s it, it&#8217;s just that simple!  Let&#8217;s add example.com to our local host names, now if we had apache installed, this ip address would always map to our computer just by adding the following line to the end of your <i>hosts</i> file&#8230; </p>
<pre>127.0.0.1    example.com</pre>
<p>Now what if you want to block a website like MySpace? Add the following line </p>
<pre>0.0.0.0       myspace.com</pre>
<p>The problem with this approach is it only blocks the hostname myspace.com, it leaves www.myspace.com and login.myspace.com completely accessible, and other hostname that I don&#8217;t know about (or worse yet, any future host names that they decide to add).  So let&#8217;s block all we we can by pointing them to a null IP address</p>
<pre>0.0.0.0       myspace.com
0.0.0.0       www.myspace.com
0.0.0.0       login.myspace.com</pre>
<p>Ok great, I added my login.myspace.com to the <i>hosts</i> file, but I can still access it, what gives?!? There is two possible fixes for this solution. First close all of your browsers, for example, if you can still access the domain in Internet Explorer or FireFox it&#8217;s because the IP address has been cached, close the browser so that the browser can &quot;forget&quot; the IP address.  Now before you reopen the application we also need to clear the DNS entry from Windows.  We can clear a DNS entry from windows by clicking <i>Start</i>, <i>Run</i> typing <i>ipconfig /flushdns</i> then clicking ok.  This will flush the ip address address stored by the operating system.  You should now by able to open FireFox and Internet Explorer and verify that they no longer have the IP address cached.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/add-or-map-custom-hostnames-to-ip-address-without-dns-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Retrieve File Permissions using Get-Acl with PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/08/retrieve-file-permissions-using-get-acl-with-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/retrieve-file-permissions-using-get-acl-with-powershell/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 06:30:24 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=385</guid>
		<description><![CDATA[Retrieving the owner and permissions of a file, folders and even registry keys is a breeze with PowerShell's Get-Acl cmdlet.  Let's try checking to see who has access to to the <i>C:\Documents and Settings\Administrator</i> folder.]]></description>
			<content:encoded><![CDATA[<p>Retrieving the owner and permissions of a file, folders and even registry keys is a breeze with PowerShell&#8217;s Get-Acl cmdlet.  Let&#8217;s try checking to see who has access to to the <i>C:\Documents and Settings\Administrator</i> folder.<span id="more-385"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Acl</span> <span style="color: #800000;">&quot;C:\Documents and Settings\Administrator&quot;</span></pre></div></div>

<p> Now this return everything that I would expect it to, but I prefer the <i>Format-List</i> view, so let&#8217;s check the permissions on the the file <i>C:\Windows\clock.avi</i> and output it in a list view.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Acl</span> <span style="color: #800000;">&quot;C:\Windows\clock.avi&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span></pre></div></div>

<p>Ok, now I did say we could check the permissions of a registry key, so let&#8217;s go for it&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Acl</span> HKLM:\Software\Microsoft</pre></td></tr></table></div>

<p>Now if you just want to find out the owner of the file you could pull back just that value</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Acl</span> <span style="color: #800000;">&quot;C:\Windows\clock.avi&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Owner</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/retrieve-file-permissions-using-get-acl-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Ping a Computer using PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-ping-a-computer-using-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-ping-a-computer-using-powershell/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 04:22:19 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=380</guid>
		<description><![CDATA[Pinging a computer is really simple, and of course since this is PowerShell we don't want to just use something as primitive as <i>ping.exe</i>, we want to use .NET and take advantage of all the method calls and filters.]]></description>
			<content:encoded><![CDATA[<p>Pinging a computer is really simple, and of course since this is PowerShell we don&#8217;t want to use something as primitive as <i>ping.exe</i>, we want to use .NET and take advantage of all the method calls and filters.<span id="more-380"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$ping</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Net.NetworkInformation.Ping
<span style="color: #800080;">$ping</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;www.brangle.com&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>We can also set a timeout so that our computer doesn&#8217;t hang to long on a server that won&#8217;t respond. Let&#8217;s add a timeout of a 5 seconds, we will first need to convert this to milliseconds, so that&#8217;s 5,000ms. Of course 5 seconds may not be a resonable timeout, you need to figure out what&#8217;s appropriate for you and what you&#8217;re willing to tolerate.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$ping</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Net.NetworkInformation.Ping
<span style="color: #800080;">$ping</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;www.brangle.com&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">5000</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>Technical details: System.Net.NetworkInformation.Ping requires that you have .NET 2.0 or greater.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-ping-a-computer-using-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
