Read Mode
Default

Detect Current "Operating System" via CMD | OS Function | By Kvc

February 24, 2017
Detect Current "Operating System" via CMD | OS Function v.1.0 | By Kvc
Detect Current Operating System: Detection of different properties in a program can lead to different results of output. And, We are manipulating Different methods to achieve our goals in life. Similarly, we are here - manipulating various things to create a simple and Easy to use Batch Function, which can tell you the OS (Operating System) in which you'll Run it - via CMD console.


Please, keep one thing in mind. This is a Function, Not a Program. So, Don't Double click on it. Otherwise, It will Show the Output for fractions of seconds and Exits the Console screen. So, You need to open CMD and use the function as simply as the one line of this OS Function. Keep Reading to know more about using it, and its Need.

What is OS Function ?

As Discussed Above, it is simply a Batch Function which will allow you to Detect the Current Operating system in which you'll execute it. It's function is simple and it can do Quite simple operations. But, This doesn't mean - You'll never need it. Below is the case - when You might need to Use it in your Batch Programs. As, We had to create it because of that reason.

Why I'll Need it?

Consider a scenario, In Which - Your Creation (Batch Program) shows different Output in Windows 7 and Windows 10. Actually, this is exactly - what happened to Us, when We were trying to complete a Project in Batch. The main reason behind the different output is that the Character size in windows 7 and windows 10 is not same. I don't know why? But, The Command - Mode 80,25 will result into different console sizes because of this problem. And, Thus All the design of my Project is ruined (because, spacing between screen elements messed-up).

"If you are not part of the solution, 
You must be part of the problem!"
-Eldridge Cleaver

But, Then Keeping the above Quote of Eldridge Cleaver in mind. We started working on the Solution. And, Because the problem was only due to the different OS versions. We researched about detection of current OS within my Batch Program. So that, It can manage itself according to the OS in which it is executed. We've found very interesting pieces of Batch Codes on web. But, None of them was well organized. Thus, We fetched the required code and mixed up things to make a efficient and reliable OS Function. which is Portable, Easy to use, simple Output, and Small in Size

 Hence, The OS Function v.1.0 By Kvc Comes into Existence. So, I publicly admit that - this is not completely my creation. But, all I did is put the right line of code at the right place. And, At the end of Day - Everyone wants to sleep calm. That is what, our goal is. To be honest and Sleep peacefully. 

How to Use it?

Well, As you now know - 'why?' You Must have a 'How' in your mind. So, Lets Clear it out in this section. The Syntax of usage of OS Function is Quite simple. Just simply call it from your Main Batch Program. And, It'll return the required configuration of the Current OS.

"Call OS [_Result]"

Here, You Always don't need to Specify the _Result parameter. As, it is optional - And, If you don't want to print the result directly to the console. Then only You should specify this parameter, and your result will be saved into this variable. Then, you can use it as you want in the code.

Here's the Screenshot for the help Menu of This OS Function. You can read it anytime by typing: OS /? in your CMD Console. (Keeping OS Function in the Working Directory).

Detect Current "Operating System" via CMD | OS Function v.1.0 | By Kvc
OS Function - Help Menu!
That's the simple and easy usage of this OS Function. If You are still in doubt, You can watch the following video to clarify them. Otherwise, You can also leave a comment below - We'll try to help you out with your Query. Thanks for Your Time. Happy Coding!

[Video]

Keep Learning, Keep Sharing...
Be Happy, Spread Happiness...
#TheBATeam

3 comments:

  1. Great function for detecting the OS and without bugs!

    ReplyDelete
  2. Why not just use the ver command?

    ReplyDelete
    Replies
    1. That is exactly what we are using in this OS Function. But, as you know - remembering the windows versions is not easy (even though, they are in big numbers like 10.0.10586). Also, It also tells you the type of OS (32-bit or 64-bit). So, all n all - it is a small utility that makes all the complex code simpler in your main program.

      But, you can still use your way of programming too. :)

      Delete

Powered by Blogger.