 




<?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>The VBScript Network and Systems Administrator&#039;s Cafe &#187; regread</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/tag/regread/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator</link>
	<description></description>
	<lastBuildDate>Tue, 11 Oct 2011 18:36:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>A simple way to read the registry with VBScript</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-simple-way-to-read-the-registry-with-vbscript/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-simple-way-to-read-the-registry-with-vbscript/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 14:57:34 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[regread]]></category>
		<category><![CDATA[regread method]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[wscript.shell]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-simple-way-to-read-the-registry-with-vbscript/</guid>
		<description><![CDATA[On occasion when administering a group of systems you need to preform certain tasks depending on if something is installed or a particular setting is a certain value and the only way to determine if a system needs attention is to look in the registry. So, In this installment we will look at reading the registry with [...]]]></description>
				<content:encoded><![CDATA[<p>On occasion when administering a group of systems you need to preform certain tasks depending on if something is installed or a particular setting is a certain value and the only way to determine if a system needs attention is to look in the registry. So, In this installment we will look at reading the registry with the <em>Wscript.shell</em> object.</p>
<p>This is a simple task, as you can see from the function below in the example code. However, it&#8217;s something that will save you a ton of time in troubleshooting when you have to first check to ensure a particular system has the setting you need to change or that is creating a problem!</p>
<p>In the example code below, I have attempted to keep it pretty generic in an effort to demonstrate the code on as many systems as possible&#8211; so it doesn&#8217;t do much because I&#8217;ve kept my registry checks limited to components I think should be installed on most all systems. However, it does present the concepts and I&#8217;ve added the major registry keys&#8217; abbreviations you would use to reference them as comments in the code.</p>
<p>Additionally, remember that you reference the path all the way to the data you want including the value name, if you are specifying a value. If you reference a registry key, but no value, you will get back the <em>(default)</em> value. Both examples are shown below, I encourage you to break out regedit and take a look at the values I referenced in the code below so you can better see what the code is doing. Also, you can look <a target="_blank" href="http://msdn.microsoft.com/en-us/library/x05fawxd(VS.85).aspx">here </a>to learn more about the regread method of the wscript.shell object.</p>
<p>So, lets get to the code!</p>
<p><font color="#0000ff">Option Explicit<br />
Dim Temp</font></p>
<p><font color="#008000">&#8216;HKEY_CURRENT_USER = HKCU<br />
&#8216;HKEY_LOCAL_MACHINE = HKLM<br />
&#8216;HKEY_CLASSES_ROOT = HKCR<br />
&#8216;HKEY_USERS = HKEY_USERS<br />
&#8216;HKEY_CURRENT_CONFIG = HKEY_CURRENT_CONFIG</font></p>
<p><font color="#0000ff">Temp = ReadReg(&#8220;HKLM\System\CurrentControlSet\Services\lanmanworkstation\DisplayName&#8221;)<br />
WScript.Echo Temp<br />
Temp = ReadReg(&#8220;HKCU\Control Panel\Desktop\Wallpaper&#8221;)<br />
WScript.Echo Temp<br />
Temp = ReadReg(&#8220;HKCR\.txt\&#8221;)<br />
WScript.Echo Temp</font><font color="#0000ff">Function ReadReg(RegPath)<br />
     Dim objRegistry, Key<br />
     Set objRegistry = CreateObject(&#8220;Wscript.shell&#8221;)<br />
     Key = objRegistry.RegRead(RegPath)<br />
     ReadReg = Key<br />
End Function</font></p>
<p><font color="#0000ff"><font color="#000000">As always, this code works perfectly. However, sometimes the formatting of the blog breaks the code if you copy and paste it into your editor. So, if you’d like to not type or troubleshoot any syntax errors due to the copy and paste problems&#8211; I’ve provided the code for download, plus example output files  from my final tests for you. You’ll find the code and other files available for download from my website’s (<a href="http://www.websystemsadministration.com/">www.websystemsadministration.com</a>) File Depot under the <font color="#0000ff"><em>ITKE Blog Scripts</em></font> category.<font color="#0000ff"> </font><font color="#0000ff"><font color="#0000ff"><font color="#000000">Enjoy and happy scripting!</font></font></font></font></font></p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/a-simple-way-to-read-the-registry-with-vbscript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
