|
-
May 29th, 2011, 02:08 PM
#1
Thread Starter
Frenzied Member
Yet another way to check the OS name.
The application that I'm working on needs to work different OS's.
For example the glass effect that I have posted inside
This is a very simple, and easy way to check the OS name.
If Microsoft did not have 6 different version of each major release. 
Then this would have not been necessary.
vb.net Code:
Dim Full_Os_Name As String = My.Computer.Info.OSFullName Dim User_Os As String Sub Get_OS_NAME() If Full_Os_Name.Contains("Windows 7") Then User_Os = "Windows 7" ElseIf Full_Os_Name.Contains("Windows Vista")Then User_Os = "Windows Vista" ElseIf Full_Os_Name.Contains("Windows XP")Then User_Os = "Windows XP" Else MessageBox.Show(Full_Os_Name & " is not supported by: " & My.Application.Info.ProductName & ", Version " & My.Application.Info.Version.ToString) Application.Exit() End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Get_OS_Name() End Sub
Now you only have to compare "Windows 7", for example without comparing Windows Stater, Ultimate, Professional, Super Ultimate, Ultimate X2, and, Ultimate V5. You get the point. 
If you like it, please vote my rep is struggling.
Last edited by Pc_Not_Mac; Jun 12th, 2011 at 02:26 PM.
Reason: Removed some bugs. Thanks minitech.
-
Jun 8th, 2011, 12:22 AM
#2
Fanatic Member
Re: Yet another way to check the OS name.
 Originally Posted by Pc_Not_Mac
The application that I'm working on needs to work different OS's.
For example the glass effect that I have posted inside
This is a very simple, and easy way to check the OS name.
If Microsoft did not have 6 different version of each major release. 
Then this would have not been necessary.
vb.net Code:
Dim Full_Os_Name As String = My.Computer.Info.OSFullName
Dim User_Os As String
Sub Get_OS_NAME()
If Full_Os_Name.Contains("Windows 7") Then
User_Os = "Windows 7"
ElseIf Full_Os_Name.Contains(Windows Vista")Then
User_Os = "Windows Vista"
ElseIf Full_Os_Name.Contains(Windows XP")Then
User_Os = "Windows XP"
Else
MessageBox.Show(Full_Os_Name & " is not supported by: " & My.Application.Info.ProductName & ", Version " & My.Application.Info.Version.ToString)
Application.Exit()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Get_OS_Name()
End Sub
Now you only have to compare "Windows 7", for example without comparing Windows Stater, Ultimate, Professional, Super Ultimate, Ultimate X2, and, Ultimate V5. You get the point. 
If you like it, please vote my rep is struggling. 
hi pc not mac. your program looks awesome but i will check until i understand it clearly. this time i am not understanding the line No 1, 2 and 11. so if you please assist me that i could use it.
-
Jun 10th, 2011, 09:38 PM
#3
Re: Yet another way to check the OS name.
You forgot a few quotes... also, you should note that "Call" is redundant in this case (though not always).
A couple of suggestions: don't check for "Windows" each time. We know if it's "7", "XP", or "Vista" it's Windows, especially since .NET only truly runs on Windows right now. Also you should use an enumeration, to increase efficiency and avoid that annoying case-sensitivity. Or at least use constants so people don't have to check back.
-
Jun 12th, 2011, 02:31 PM
#4
Thread Starter
Frenzied Member
Re: Yet another way to check the OS name.
 Originally Posted by minitech
don't check for "Windows" each time. We know if it's "7", "XP", or "Vista" it's Windows, especially since .NET only truly runs on Windows right now
Not sure if I completely understand that.
This example is useful when something works on one, but not the other.
For example, the progress bar on each task in the taskbar only works on "7".
The glass effect would only work on "Vista", or "7".
Try loading the glass effect on XP and you will error out.
 Originally Posted by minitech
Also you should use an enumeration, to increase efficiency and avoid that annoying case-sensitivity. Or at least use constants so people don't have to check back.
I might look into that when my SSD gets here.
 Originally Posted by minitech
You forgot a few quotes... also, you should note that "Call" is redundant in this case (though not always).
Thanks btw.
-
Jun 12th, 2011, 02:37 PM
#5
Thread Starter
Frenzied Member
Re: Yet another way to check the OS name.
 Originally Posted by ADQUSITADQUSIT
hi pc not mac. your program looks awesome but i will check until i understand it clearly. this time i am not understanding the line No 1, 2 and 11. so if you please assist me that i could use it.
Line 1 gets the users full OS name:
for example,
Microsoft Windows 7 Professional Edition.
Line 11, is just a message box.
Line 2, is a simple sting to store shorted name of the OS. Like "Windows 7".
-
Jun 13th, 2011, 02:26 AM
#6
Fanatic Member
Re: Yet another way to check the OS name.
 Originally Posted by Pc_Not_Mac
Line 1 gets the users full OS name:
for example,
Microsoft Windows 7 Professional Edition.
Line 11, is just a message box.
Line 2, is a simple sting to store shorted name of the OS. Like "Windows 7".
thats fine now.
If i got some other problem so i'll ask for assistance. 
now please tell me that where do i write this code. i mean just simply on form load event or somewhere else.
-
Jun 13th, 2011, 02:59 PM
#7
Thread Starter
Frenzied Member
Re: Yet another way to check the OS name.
 Originally Posted by ADQUSIT
now please tell me that where do i write this code. i mean just simply on form load event or somewhere else.
You can but I made a sub for the method.
Just call Full_Os_Name anytime you want to run it.
You only need to run it ones so keep it in the load event.
I personal avoid having any code inside the load event as it gets cultured with methods.
-
Jun 14th, 2011, 01:23 AM
#8
Fanatic Member
Re: Yet another way to check the OS name.
-
Jul 22nd, 2011, 08:46 AM
#9
Lively Member
Re: Yet another way to check the OS name.
vb Code:
Label1.Text = My.Computer.Info.OSFullName
That's it.
-
Jul 23rd, 2011, 02:15 PM
#10
Thread Starter
Frenzied Member
Re: Yet another way to check the OS name.
 Originally Posted by rami0
1.
Label1.Text = My.Computer.Info.OSFullName
That's it.
Nice. That was completely irrelevant and off-topic.
Next time try reading the first post rather than, the title and skipping to the code.
-
Aug 5th, 2014, 07:21 AM
#11
New Member
Re: Yet another way to check the OS name.
Hey, PC_not_Mac,
I am using your code. I will run it and see what it does!
vbdotnetfan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|