<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tan Yu Xuan</title>
    <description>The latest articles on DEV Community by Tan Yu Xuan (@weareblahs).</description>
    <link>https://dev.to/weareblahs</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F737271%2F3ac96551-af43-446e-9d99-ad9121de37e1.jpeg</url>
      <title>DEV Community: Tan Yu Xuan</title>
      <link>https://dev.to/weareblahs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/weareblahs"/>
    <language>en</language>
    <item>
      <title>I found it. The "most-complex" way to check operating system build number before running an batch script.</title>
      <dc:creator>Tan Yu Xuan</dc:creator>
      <pubDate>Sat, 06 Nov 2021 02:55:59 +0000</pubDate>
      <link>https://dev.to/weareblahs/i-found-it-the-most-complex-way-to-check-operating-system-build-number-before-running-an-batch-script-1cmc</link>
      <guid>https://dev.to/weareblahs/i-found-it-the-most-complex-way-to-check-operating-system-build-number-before-running-an-batch-script-1cmc</guid>
      <description>&lt;p&gt;So, technically, days ago, when I was doing stuffs for my own project, which is &lt;code&gt;WSATools&lt;/code&gt;, and then I think I made the most complex way to check operating system's build number before running stuffs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why did you do this?
&lt;/h2&gt;

&lt;p&gt;So, Windows Subsystem for Android requires Windows 11, and it requires Windows 11. I also asked Stack Overflow, but technically no solution, which the only ones are just checking the OS version through Command Prompt, but didn't continue running.&lt;/p&gt;

&lt;h2&gt;
  
  
  The actual command that I used to run it. Modified a little bit so I can explain it
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Before you try running
&lt;/h3&gt;

&lt;p&gt;Make sure you downloaded any version of &lt;code&gt;fart.exe&lt;/code&gt;. I built a version and included it on WSATools, and you can download v1.99c of fart for Windows &lt;a href="https://github.com/weareblahs/fart-builds/releases/tag/v1.99c"&gt;here&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;ver&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;checkver&lt;/span&gt;.bat
&lt;span class="kd"&gt;fart&lt;/span&gt; &lt;span class="kd"&gt;checkver&lt;/span&gt;.bat &lt;span class="s2"&gt;"Microsoft Windows [Version"&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kr"&gt;nul&lt;/span&gt;
&lt;span class="kd"&gt;fart&lt;/span&gt; &lt;span class="kd"&gt;checkver&lt;/span&gt;.bat &lt;span class="s2"&gt;"]"&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kr"&gt;nul&lt;/span&gt;
&lt;span class="kd"&gt;fart&lt;/span&gt; &lt;span class="na"&gt;-C &lt;/span&gt;&lt;span class="kd"&gt;checkver&lt;/span&gt;.bat \r\n &lt;span class="s2"&gt;" "&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kr"&gt;nul&lt;/span&gt;
&lt;span class="kd"&gt;fart&lt;/span&gt; &lt;span class="na"&gt;-C &lt;/span&gt;&lt;span class="kd"&gt;checkver&lt;/span&gt;.bat &lt;span class="s2"&gt;"   "&lt;/span&gt; &lt;span class="s2"&gt;"@echo off \r\n echo "&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kr"&gt;nul&lt;/span&gt;
&lt;span class="kd"&gt;fart&lt;/span&gt; &lt;span class="kd"&gt;checkver&lt;/span&gt;.bat &lt;span class="s2"&gt;"  "&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kr"&gt;nul&lt;/span&gt;
&lt;span class="kd"&gt;fart&lt;/span&gt; &lt;span class="na"&gt;-C &lt;/span&gt;&lt;span class="kd"&gt;checkver&lt;/span&gt;.bat &lt;span class="s2"&gt;".282 "&lt;/span&gt; &lt;span class="s2"&gt;".282\r\n"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kr"&gt;nul&lt;/span&gt;
&lt;span class="kd"&gt;fart&lt;/span&gt; &lt;span class="kd"&gt;checkver&lt;/span&gt;.bat &lt;span class="s2"&gt;" echo "&lt;/span&gt; &lt;span class="s2"&gt;"echo "&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kr"&gt;nul&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="na"&gt;/f &lt;/span&gt;&lt;span class="vm"&gt;%%N&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'checkver'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="s2"&gt;"check=&lt;/span&gt;&lt;span class="vm"&gt;%%N&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;%check%&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;.0.22000.282 &lt;span class="o"&gt;(&lt;/span&gt;
&lt;span class="nb"&gt;del&lt;/span&gt; &lt;span class="kd"&gt;checkver&lt;/span&gt;.bat
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="kd"&gt;Success&lt;/span&gt;
  &lt;span class="nb"&gt;pause&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kr"&gt;nul&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;
&lt;span class="nb"&gt;del&lt;/span&gt; &lt;span class="kd"&gt;checkver&lt;/span&gt;.bat
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="kd"&gt;Failed&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  And now, here's the explanation
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;ver &amp;gt;&amp;gt; checkver.bat&lt;/code&gt;: This is used for getting the &lt;code&gt;ver&lt;/code&gt; command output to a batch file. &lt;br&gt;
Which, of course, Opening checkver.bat on any editing software will give us this, which can't be runned directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Microsoft Windows [Version 10.0.22000.282]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in the next step, we will make it runnable by making it &lt;code&gt;echo&lt;/code&gt; the OS build number through command prompt and check with the terms at the original file. The output of the file will be something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight postscript"&gt;&lt;code&gt;&lt;span class="nf"&gt;G:\git-working\wsatools&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;checkver&lt;/span&gt;
&lt;span class="nf"&gt;10.0.22000.282&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  The &lt;code&gt;fart checkver.bat&lt;/code&gt; commands: a breakdown
&lt;/h4&gt;

&lt;p&gt;Here's what the commands will run, and the output itself:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fart checkver.bat "Microsoft Windows [Version" " "&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;\nMicrosoft Windows [Version 10.0.22000.282]&lt;/code&gt; to &lt;code&gt;\n10.0.22000.282]&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;fart checkver.bat "]" " "&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;\n10.0.22000.282]&lt;/code&gt; to &lt;code&gt;\n10.0.22000.282&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;fart -C checkver.bat \r\n " "&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove new line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;fart -C checkver.bat "   " "@echo off \r\n echo "&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transform it into a batch file by adding &lt;code&gt;echo&lt;/code&gt; command that we will use later. Replaced to &lt;code&gt;@echo off\n echo 10.0.22000.282&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;fart checkver.bat "  " " "&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove some spaces.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;fart -C checkver.bat ".282 " ".282\r\n"&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This also removes some spaces. You can replace &lt;code&gt;.282&lt;/code&gt; to the last numbers of the build number. For example: 

&lt;ul&gt;
&lt;li&gt;Windows 10 21H1 (10.0.19043.1202) should replace &lt;code&gt;.282&lt;/code&gt; to &lt;code&gt;.1202&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;fart checkver.bat " echo " "echo "&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Also removes spacing before &lt;code&gt;echo&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check output for &lt;code&gt;checkver.bat&lt;/code&gt;. It should return just the version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="na"&gt;/f &lt;/span&gt;&lt;span class="vm"&gt;%%N&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'checkver'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="s2"&gt;"check=&lt;/span&gt;&lt;span class="vm"&gt;%%N&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;%check%&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;.0.22000.282 &lt;span class="o"&gt;(&lt;/span&gt;
&lt;span class="nb"&gt;del&lt;/span&gt; &lt;span class="kd"&gt;checkver&lt;/span&gt;.bat
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="kd"&gt;Success&lt;/span&gt;
  &lt;span class="nb"&gt;pause&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kr"&gt;nul&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;
&lt;span class="nb"&gt;del&lt;/span&gt; &lt;span class="kd"&gt;checkver&lt;/span&gt;.bat
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="kd"&gt;Failed&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For &lt;code&gt;del checkver.bat&lt;/code&gt;, this deletes the &lt;code&gt;checkver.bat&lt;/code&gt; batch file for future uses.&lt;/p&gt;

&lt;p&gt;And finally, compare the output in &lt;code&gt;checkver.bat&lt;/code&gt; with the build number set. Change it to &lt;code&gt;if %check == (build number)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Change &lt;code&gt;echo Success&lt;/code&gt; to point to the file which you want to run, or just directly put the batch script right there.&lt;/p&gt;

&lt;p&gt;Or else, for &lt;code&gt;echo Failed&lt;/code&gt;, you can put a failed message there.&lt;/p&gt;

</description>
      <category>batch</category>
      <category>windows</category>
      <category>cmd</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
