locked
BAT Command to Buttons? RRS feed

  • Question

  • I am new to VB. I was wondering how can I get this .bat command to run after my button is clicked

    I can make it like, "Run a certain .bat when button is clicked" , but I don't want that because people can go inside my .bat and hack my IP. So I was wondering is there a way I can put that .bat command into my VB 2010 Express

    start .\release\GAME.EXE /NoGsm /LaunchByLauncher /ServerAddr:""MY IP"" /ServerPort:""PORT"" /SiteName:""""
    exit

    Friday, April 20, 2012 10:54 PM

Answers

All replies

  • That appears to be a single line batch file that runs an EXE.   You can take the command part of that line and load it into the StartInfo object of a Process class instance and then use the Process Start method to start the EXE with those arguments.  The references all have examples.

    Note that you will have to change .\release\GAME.EXE so that it is the correct path to the application, because you are no longer specifying where the batch file is executing from (which is how the '.\' part of that path is being set).

    This is the StartInfo object:
    http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx
    This is the constructor you will likely use (there are a number of ways of doing the same thing):
    http://msdn.microsoft.com/en-us/library/b5zzxthe.aspx

    This is the process class:
    http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx
    and the Start method that takes a StartInfo object.
    http://msdn.microsoft.com/en-us/library/0w4h05yb.aspx

    Friday, April 20, 2012 11:25 PM
  • In addition to what Acamar is saying it appears that this uses Arguments, so you'll need to define them with your StartInfo as well.

    Dim PInfo As New ProcessStartInfo
    With PInfo
    	.Arguments = "/NoGsm /LaunchByLauncher /ServerAddr:""MY IP"" /ServerPort:""PORT"" /SiteName:"""""
    	.FileName = "FilePath\Game.exe"
    End With
    Using Proc As New Process
    	Proc.StartInfo = PInfo
    	Proc.Start()
    End Using

    Rule: If you ever see a need to use a batch file for your program, there's always a better way that you haven't thought of. Unless you want to use a batch file, but being forced to use one, should never happen.


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    Visit the Forum: TechLifeForum




    • Edited by Troy Garner Saturday, April 21, 2012 1:39 AM
    Saturday, April 21, 2012 1:33 AM