{"id":55843,"date":"2008-04-05T00:46:00","date_gmt":"2008-04-05T00:46:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2008\/04\/05\/hey-scripting-guy-how-can-i-determine-the-currency-symbol-in-use-on-a-computer\/"},"modified":"2008-04-05T00:46:00","modified_gmt":"2008-04-05T00:46:00","slug":"hey-scripting-guy-how-can-i-determine-the-currency-symbol-in-use-on-a-computer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-determine-the-currency-symbol-in-use-on-a-computer\/","title":{"rendered":"Hey, Scripting Guy! How Can I Determine the Currency Symbol in Use on a Computer?"},"content":{"rendered":"<p><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\" \/> <\/p>\n<p>Hey, Scripting Guy! Is there any way to determine the currency symbol that\u2019s in use on a computer?<br \/>&#8212; IR<\/p>\n<p><img decoding=\"async\" height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\" \/><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\" \/><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\" \/><\/a> <\/p>\n<p>Hey, IR. Before we get started today we wanted to mention that the Scripting Son picked up his second win in as many pitching starts the other day as the Juanita Rebels rolled past Franklin High School. The Scripting Son is now 2-0 for the season, with an earned-run average of 1.93.<\/p>\n<p>Oh, and he\u2019s also hitting .333 this year. Not that we\u2019re trying to brag or anything.<\/p>\n<p>Scratch that; we <i>are<\/i> trying to brag a little. In fact, the Scripting Guy who writes this column is so proud of the Scripting Son that he decided to bestow on his son scripting\u2019s highest honor: he\u2019s going to let the Scripting Son write today\u2019s <i>Hey, Scripting Guy!<\/i> column. Take it away, son!<\/p>\n<p>&nbsp;<\/p>\n<p>What? Where are you \u2013 wait, I don\u2019t want to \u2013 Dad, come back here, I don\u2019t want to do this, this is stupid, this \u2013 oh, man.<\/p>\n<p>Um, hi, everyone. My dad kind of dropped this on me so you\u2019re going to have to bear with me for a second. As far as I know, IR, there\u2019s no WMI class or COM object that can tell you which currency symbol is currently in use on a computer. That\u2019s probably the <i>real<\/i> reason my Dad is \u201cletting\u201d me write this column; he didn\u2019t know how to answer your question.<\/p>\n<p>But that\u2019s all right. As any high school kid knows you can determine the currency symbol currently in use on a computer by using WMI to read that value from the registry:<\/p>\n<pre class=\"codeSample\">Const HKEY_CURRENT_USER = &amp;H80000001\n\nstrComputer = \".\"\n \nSet objRegistry = GetObject(\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\default:StdRegProv\")\n \nstrKeyPath = \"Control Panel\\International\"\nstrValueName = \"sCurrency\"\n\nobjRegistry.GetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue\n\nMsgbox strValue\n<\/pre>\n<p>Admittedly, I\u2019ve never read any of my dad\u2019s articles, but if I know him he probably starts off by telling some long and pointless story. Along the way I\u2019m sure he also stops to tell jokes that no one else thinks are funny. You want to know the truth? Most of the time no one has any idea what he\u2019s even talking about. Like the time we went to Idaho for Vandal Preview Friday, and he starts going off on steroids in baseball and how he doesn\u2019t see any difference between taking steroids and sleeping in a hyperbaric chamber, and he just kept going on and on and on until I finally said, \u201cWould you just give it a <i>rest<\/i>? No one cares about your dumb opinions.\u201d And that was true: no one else in the car <i>did<\/i> care about his dumb opinions.<\/p>\n<p>No one else in the <i>world<\/i>, for that matter.<\/p>\n<p>You know, there are probably days when you guys read his column and you just kind of shake your head and think, \u201cWhoa.\u201d Well, you ought to try <i>living<\/i> with him.<\/p>\n<p>Anyway, unlike my dad, I\u2019ll just get right to the point here. This script thing starts off by defining a constant named HKEY_CURRENT_USER and setting the value to &amp;H80000001; we\u2019ll use this constant to tell the script which registry hive to work with.<\/p>\n<table class=\"dataTable\" id=\"E6D\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p><b>Note<\/b>. I\u2019ll give my dad a break here; HKEY_CURRENT_USER is really more the kind of name my <i>mom<\/i> would come up with. True story: she wanted to name me Iones but Dad talked her out of that.<\/p>\n<p><b>Ed<\/b><b>itor\u2019s Note:<\/b> To everyone out there named Iones, there\u2019s absolutely nothing wrong with your name and the Scripting Son did not mean to imply that there is. (Okay, yes he did, but apparently the Scripting Editor is going to have to make the same efforts to keep the son from getting us into a lot of trouble as she does to keep his dad from getting us into trouble.)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>After we define the constant we connect to the WMI service on the local computer. We then \u2013 just a second, please. You said you were going to let me write this all by myself; I don\u2019t need your help. Well, if you\u2019d quit bothering me I <i>would<\/i> tell them that. If you wanted to write today\u2019s column then just write it. Otherwise, leave me alone.<\/p>\n<p>Sheesh.<\/p>\n<p>Sorry. As my dad has \u2026 helpfully \u2026 pointed out, this script can also be run against a remote computer. All you need to do is assign the name of that remote computer to the variable strComputer (which, coincidentally enough, is yet <i>another<\/i> name my mom wanted to give me):<\/p>\n<pre class=\"codeSample\">strComputer = \"atl-fs-001\"\n<\/pre>\n<p>By the way, there are two things you should keep in mind when it comes to our WMI connection string. First, we connect to the <b>root\\default<\/b> namespace. That\u2019s a little unusual; for most system administration scripts we connect to the root\\cimv2 namespace. Also, note that we bind directly to the <b>StdRegProv<\/b> class. That\u2019s because WMI\u2019s methods for working with the registry are all \u201cstatic\u201d methods; that means that they work on the class itself and not on individual instances of the class. I don\u2019t know whether that\u2019s good or not; that\u2019s just the way it is.<\/p>\n<p>Just a second \u2013 because I\u2019m not stupid, Dad, <i>that\u2019s<\/i> how I know stuff like that. Geez, <i>everyone<\/i> knows about WMI namespaces and static methods. Don\u2019t you have anything else to do? Hey, look: some kids are playing in our yard! Why don\u2019t you go yell at them?<\/p>\n<p>That should keep him busy for awhile.<\/p>\n<p>OK. After we connect to the WMI service we use these two lines of code to assign values to a pair of variables:<\/p>\n<pre class=\"codeSample\">strKeyPath = \"Control Panel\\International\"\nstrValueName = \"sCurrency\"\n<\/pre>\n<p>The variable strKeyPath identifies the registry key (in the HKEY_CURRENT_USER registry hive) that we want to work with; the variable sCurrency is the registry value we want to read.<\/p>\n<p>Speaking of which \u2013 Dad, don\u2019t touch my stuff. Just leave it alone, OK? Thank you.<\/p>\n<p>Sorry. Anyway, to retrieve the currency symbol from the registry all we have to do now is call the <b>GetStringValue<\/b> method, passing this method the constant HKEY_CURRENT_USER and the variables strKeyPath, strValueName, and strValue:<\/p>\n<pre class=\"codeSample\">objRegistry.GetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue\n<\/pre>\n<p>Excuse me again. No, Dad, I did <i>not<\/i> make a mistake. We have to pass GetStringValue a third variable; in this case, that\u2019s a variable named strValue. (Which, by the way, is my middle name. Dad had to compromise on that one.) strValue happens to be an out parameter: we supply a variable name, and GetStringValue assigns the value read from the registry to this out parameter. In other words, GetStringValue will retrieve the currency symbol from the registry, then assign that symbol to the out parameter. That means we can determine the currency symbol simply by echoing back the value of strValue:<\/p>\n<pre class=\"codeSample\">Msgbox strValue\n<\/pre>\n<p>On our test machine, that message box looks a little something like this:<\/p>\n<p><img decoding=\"async\" height=\"115\" alt=\"Currency Symbol\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/currency.jpg\" width=\"113\" border=\"0\" \/> <\/p>\n<p>Did someone out there have a question? Why did we use a message box rather than just echoing back the value to the command window? Hey, Dad, why did we use a message box rather than just echoing back the value to the command window? Never mind; he has no idea. And yet he still thinks he\u2019s <i>the<\/i> Scripting Guy. <\/p>\n<p>Well, <i>I\u2019ll<\/i> tell you why we did that: we did that because, depending on your computer settings, there\u2019s a good chance that the Euro symbol won\u2019t display properly in the command window. For example, on our test machine echoing back the Euro symbol gives us output that looks like this:<\/p>\n<pre class=\"codeSample\">?\n<\/pre>\n<p>Cute, but not what we were hoping to see.<\/p>\n<p>By the way, if you want to <i>change<\/i> the currency symbol you can use a script similar to this one:<\/p>\n<pre class=\"codeSample\">Const HKEY_CURRENT_USER = &amp;H80000001\n\nstrComputer = \".\"\n \nSet objRegistry = GetObject(\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\default:StdRegProv\")\n \nstrKeyPath = \"Control Panel\\International\"\nstrValueName = \"sCurrency\"\nstrValue = \"$\"\n\nobjRegistry.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue\n<\/pre>\n<p>As you can see, this is very similar to the script for retrieving the currency symbol from the registry. In fact, there are only two differences. For one, we don\u2019t use an out parameter in this script; instead, we assign the desired currency symbol the variable strValue:<\/p>\n<pre class=\"codeSample\">strValue = \"$\"\n<\/pre>\n<p>Second, we use the <b>SetStringValue<\/b> method to write this new value to the registry:<\/p>\n<pre class=\"codeSample\">objRegistry.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue\n<\/pre>\n<p>It\u2019s as easy as that.<\/p>\n<p>That\u2019s all I have time for today; after all, we have practice this afternoon, even though it <i>is<\/i> spring break. But don\u2019t worry; my dad will be back tomorrow.<\/p>\n<p>Lucky you, huh?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Is there any way to determine the currency symbol that\u2019s in use on a computer?&#8212; IR Hey, IR. Before we get started today we wanted to mention that the Scripting Son picked up his second win in as many pitching starts the other day as the Juanita Rebels rolled past Franklin High [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[31,26,3,5],"class_list":["post-55843","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-operating-system","tag-registry","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Is there any way to determine the currency symbol that\u2019s in use on a computer?&#8212; IR Hey, IR. Before we get started today we wanted to mention that the Scripting Son picked up his second win in as many pitching starts the other day as the Juanita Rebels rolled past Franklin High [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/55843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=55843"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/55843\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=55843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=55843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=55843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}