Need Help With a VB version of a batch function

NightsEvil

Member
Joined
May 1, 2010
Messages
10
Programming Experience
Beginner
hey all new here and to VB im working with VB 2010 express and i have this batch file with a function in it that i just LOVE! but i cant seem to find a equivalent in vb any ideas?? what my idea is that when the application is launched, it displays the OS in a textbox near the top of the form, under (or near) it would display the real time system time, ram, cpu speed, and Graphics card kinda how Ccleaner does, then there would be a button that says optimize when clicked it would do this kinda batch thing:

VER | findstr /i "5\.1\." > nul
IF %ERRORLEVEL% EQU 0 set version=XP
VER | findstr /i "6\.0\." > nul
IF %ERRORLEVEL% EQU 0 set version=Vista
VER | findstr /i "6\.1\." > nul
IF %ERRORLEVEL% EQU 0 set version=7

goto %version%

:xp
does this stuff if the os is xp

:vista
does this stuff if the os is vista

:7
does this stuff if the os is 7


then when that is all done (maybe some kinda progress bar or something to show its working) the button text would change to UnOptimize or something like that... can ya help a noobie out? =P
 
You can use Environment.OSVersion.Version to get the build numbers.

VB.NET:
        Dim os = Environment.OSVersion.Version
        If os.Major = 6 AndAlso os.Minor = 1 Then
            MessageBox.Show("Running Windows 7")
        ElseIf os.Major = 6 AndAlso os.Minor = 0 Then
            MessageBox.Show("Running Vista")
        ElseIf os.Major = 5 Then
            MessageBox.Show("Running XP")
        Else
            MessageBox.Show("Unspecified OS")
        End If
 
VB.NET:
 ElseIf os.Major = 5 Then
            MessageBox.Show("Running XP")
That will mark Windows2000 as being WindowsXP

Win2k: 5.0
WinXP: 5.1
Vista/Server2008: 6.0
Win7/Server2008 RC2 : 6.1
 
wow thanks!!!

now.. im making a small program for gaming performance so it detects what version is running then it shuts specific services down in the background (which is working AWSOME thanks alot but is there a way i can have it show what its doing? like with a progress bar or a small text field to show it shutting them down?
 
ok thanks

alright ill look at it, also is there a way i can input the code

Dim os = Environment.OSVersion.Version
If os.Major = 6 AndAlso os.Minor = 1 Then
MessageBox.Show("Running Windows 7")
ElseIf os.Major = 6 AndAlso os.Minor = 0 Then
MessageBox.Show("Running Vista")
ElseIf os.Major = 5 AndAlso os.Minor = 1 Then
MessageBox.Show("Running XP")
Else
MessageBox.Show("Unspecified OS")
End If

into a label perhaps? so it will display at the top of the screen what OS is being ran?
 
Just set the form's .Text property so whatever you want the text to be.

VB.NET:
        If os.Major = 6 AndAlso os.Minor = 0 Then
            Me.Text = "Running on Windows Vista"
        End If
 
not enough room

theres not enough room for it in the form1 "text" box .. i tried putting it in the label where you can expand it and put in how ever much you want but it just displays the code..
 
well hmm..

well im working with vb 2010 express and you said to go into the form1 properties and paste that code right? well for some reason it doesnt fit i even tried it in a label..
 
I said set the .Text property to whatever string you wanted. The example code I provided shows you how to do that.
 
trial and error

lol i figured it out thanks alot for the help, also is there a way to run a program with command line arguments through button click like say i have a 7zip file archived as a .exe and it has a password, well in a batch file i just have

start /wait test.exe -o%TMP% -y -Pthisispassword

where test.exe is the archive, -o%TMP% is to extract to the system enviornment variable for the temp directory, -y is a silent yes and -P followed by the pass is the password.
 
Have a look around the web at Process.Start. You'll find that if you can do it from a command line you can call it from Visual Basic.
 
ok cool

Ok cool thanks forf all the help, also how can I have it so that say when its in gaming mode that button is greyed out and same for in normal mode, also I need it to check when the program starts if specific services exist, if not it checks the next on the list, if that one exists it checks if its running, if its running it greys out normal mode if its not running, gaming mode is greyed out.. or have is check multiple services at once lol I'm used to batch scripting so I don't know how powerful vb.net is
 
Back
Top