{"id":13,"date":"2008-01-05T13:19:05","date_gmt":"2008-01-05T21:19:05","guid":{"rendered":"http:\/\/www.installaware.com\/blog\/?p=13"},"modified":"2008-01-05T13:19:05","modified_gmt":"2008-01-05T21:19:05","slug":"online-serial-key-validation-with-installaware-the-code-part","status":"publish","type":"post","link":"https:\/\/www.installaware.com\/blog\/?p=13","title":{"rendered":"Online Serial Key Validation with InstallAware, the Code Part"},"content":{"rendered":"<p>Hi all! It&#8217;s been a few days since my last post about wrapping our update mechanism around your application and it&#8217;s time for some web server code samples; but first, I wanted to make an enhancement to the update script.<\/p>\n<p>If we want to change our &#8220;<span style=\"font-weight: bold\">Run Program As<\/span>&#8221; commands, we&#8217;ll have to edit multiple parts of the update script. At best, this is tedious; typically it will introduce errors with forgotten or misplaced commands. The solution is simple: we&#8217;ll use the <span style=\"font-weight: bold\">Label <\/span>and <span style=\"font-weight: bold\">GoTo Label <\/span>MSIcode commands to create a re-usable region of code. This way, we&#8217;ll remove all pairs of existing &#8220;<span style=\"font-weight: bold\">Run Program As<\/span>&#8221; and &#8220;<span style=\"font-weight: bold\">Terminate Installation<\/span>&#8221; commands, replacing them with a <span style=\"font-weight: bold\">GoTo Label <\/span>command that points to a new &#8220;<span style=\"font-weight: bold\">Label<\/span>&#8221; called &#8220;<span style=\"font-style: italic\">RunProgramSection<\/span>&#8220;, with the &#8220;<span style=\"font-weight: bold\">Run Program As<\/span>&#8221; and &#8220;<span style=\"font-weight: bold\">Terminate Installation<\/span>&#8221; commands underneath.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.installaware.com\/blog\/pics\/code-part\/before-label.png\" \/><\/p>\n<p>becomes:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.installaware.com\/blog\/pics\/code-part\/after-label.png\" \/><\/p>\n<p>So now, instead of making changes all over the place in the MSIcode script, I only have to make one change under the <span style=\"font-weight: bold\">Label<\/span> command. That way, I can re-use this code block in other projects:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.installaware.com\/blog\/pics\/code-part\/the-label.png\" \/><\/p>\n<p>I can also build in more sophisticated behavior, adding more MSIcode commands. Lets say you want to run two programs &#8211; one might be a tray application and the other one the &#8220;real&#8221; application.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.installaware.com\/blog\/pics\/code-part\/the-label-tray.png\" \/><\/p>\n<p>Quite easily done. Extensibility and scalability are everything these days!<\/p>\n<p><span style=\"font-weight: bold\">And now for some server side code.<\/span> First, please make sure you&#8217;re familiar with a server side scripting language like PHP or ASPX. Please visit <a href=\"http:\/\/www.asp.net\/\">www.asp.net<\/a> and <a href=\"http:\/\/www.php.net\/\">www.php.net<\/a> if you need a jumpstart. I&#8217;ll assume that you&#8217;ve done your homework and that you can follow the simple scripts provided below.<\/p>\n<p><span style=\"font-weight: bold\">First some PHP. <\/span>If you remember, I pass some parameters from my MSIcode Install<span style=\"font-weight: bold\">Aware<\/span> setup\/client script to the web\/server script as URL parameters. In PHP, URL parameters are stored inside a predefined variable called <span style=\"font-style: italic\">$_GET<\/span>, which is a global array. If you want to read a user&#8217;s serial number and your parameter is called <span style=\"font-style: italic\">serial<\/span>, you can try the following:<\/p>\n<p><em>$serial = strip_tags($_GET[&#8216;serial&#8217;]);<br \/>\n<\/em><\/p>\n<p>Now, the PHP script variable <span style=\"font-style: italic\">$serial<\/span> has our parameter&#8217;s value. Let&#8217;s see if the serial number provided is actually valid:<\/p>\n<p><em>if ( CheckIfLegimitate($serial) )<br \/>\nreturn &#8220;1,&#8221;.srand(time());<br \/>\nelse<br \/>\nreturn &#8220;0,&#8221;.srand(time());<\/em><\/p>\n<p>If the serial is valid, the PHP script above returns &#8220;1&#8221;, or &#8220;0&#8221; otherwise. Either way, the return value is appended with a comma delimited random number. Back on the Install<span style=\"font-weight: bold\">Aware<\/span> setup\/client side, I read this value using the &#8220;<span style=\"font-weight: bold\">Download File<\/span>&#8221; MSIcode command, and I then parse it using <span style=\"font-weight: bold\">Parse String<\/span>; which lets me obtain both the status code (&#8220;1&#8221; or &#8220;0&#8221;), and of course the random number.<\/p>\n<p>Next\u00c2\u00a0post: Database schema scripts and more code. It&#8217;s going to be the last post from these series so, stay tunned!<\/p>\n<p>Panagiotis Kefalidis<br \/>\nSoftware Design Team Lead<br \/>\nInstallAware Software Corporation<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi all! It&#8217;s been a few days since my last post about wrapping our update mechanism around your application and it&#8217;s time for some web server code samples; but first, I wanted to make an enhancement to the update script. If we want to change our &#8220;Run Program As&#8221; commands, we&#8217;ll have to edit multiple &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.installaware.com\/blog\/?p=13\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Online Serial Key Validation with InstallAware, the Code Part&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,1],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-msi-code-scripting","category-news"],"_links":{"self":[{"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":0,"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}