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
 
also how can i have my program reference system environment variables such as %TMP% %TEMP% %SYSTEMROOT% ect... i tried to have a 7zip exe archive extract with -o%TMP% which works perfect in command line but doesnt wanna work with this

Process.Start("test.exe ", "-o%TMP% -y -Ptest1")
 
The Processes StartInfo has EnvironmentVariables which you can access.

VB.NET:
        Dim p1 As New Process
        p1.StartInfo.UseShellExecute = False
        p1.StartInfo.FileName = "Notepad.exe"
        p1.StartInfo.Arguments = p1.StartInfo.EnvironmentVariables.Item("TMP") & "\Test.txt"
        p1.Start()

You'll have set UseShellExecute to False to use the EnvironmentVariables for the process you're trying to run.

You can cheat and create a StringDictionary of all of the environment variables.

VB.NET:
        Dim psi As New ProcessStartInfo
        Dim ev = psi.EnvironmentVariables

        Dim p1 As New Process
        p1.StartInfo.FileName = "Notepad.exe"
        p1.StartInfo.Arguments = ev.Item("TMP") & "\Test.txt"
        p1.Start()
 
is there a way that i can have it get the system environment variables when the program starts then have them refrenced later? cause what i need this for is so that it will extract my commandline antivirus to the %tmp% directory then start the exe with commandline arrguments which also requires a environment variable %systemroot%
 
Just get the EnvironmentVariables on form load and put them in an object with a scope your methods can use.

VB.NET:
Public Class Form1

    Dim psi As ProcessStartInfo

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        psi = New ProcessStartInfo
    End Sub

    Private Sub btnDoSomething_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoSomething.Click
        MessageBox.Show(psi.EnvironmentVariables.Item("Systemroot"))
    End Sub

End Class
 
what i need

i got it to show the environment variables correctly but i need it to extract the 7zip exe archive useing command line arguments, then run a extracted file with (sometimes without) command line arguments such as this in a batch

start /wait Programs\Optimize\AusLogics_Defrag.exe -o%TMP% -y -Ptestpass

::where -o is extract to %TMP% is the Environment Variable -y is yes and -P(password)

%TMP%\AusLogics_Defrag\cdefrag.exe -dt -o c:

::then it needs to call the environment variable to access the exe and run it with arguments

IF EXIST "%TMP%\Auslogics_Defrag\" (RMDIR /S /Q "%TMP%\Auslogics_Defrag\")

::then when its done it needs to delete the directory quietly.
 
Back
Top