VB.NET sending command line.

Socius Decennalis
Decennium
Joined
Mar 30, 2013
Messages
474
Reaction score
56
I know of process.start();, but I also have been taught that it is not entirely reliable/secure.

Was wondering if there was any other methods around this.

Simply wanting to send a MSG command to user ablakely with information from three text boxes. Text boxes names are txtName, txtUnit, and txtClass

Example output: MSG ablakely Zachary Mitchell, 3.2.10, English 12-1.

If someone knows why process.start(); isn't secure, that would also be great. I just know in my VB class, the prof always said to never use it, but that was several years ago, and have not used VB since.



Also for the sake of learning, if anyone has an answer, how would you do the same in C++/Java?

Thanks in advance!
 
It depends on what you want to do with the process, if you want to only start a process, use a simple function to start it, if you want to start it and get its handle, to have control over it, use a more complex one.

To start a process with arguments you can do it with Process.Start(), the process Class has a Member(Process.StartInfo) of type "System.Diagnostics.ProcessStartInfo", which you specify some properties for the process you want to start
PHP:
Dim process As New Process
process.StartInfo.Arguments = "arg1 arg2"
process.StartInfo.FileName = "path\\to\\file.exe"
process.StartInfo.WorkingDirectory = "path\\to\\working\\directory\\"
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal
process.Start()

In C++ to start a process you can do it by 4 ways as far as I know(system(const char* cmd), CreateProcess, ShellExecute,ShellExecuteEx)
PHP:
//system, available in linux too
system( "path\\to\\file.exe arg1 arg2" );

//CreateProcess
PROCESS_INFORMATION processInfo = {0};
STARTUPINFO startupInfo = {0};
startupInfo.cb = sizeof(STARTUPINFO );
CreateProcess(
    "path\\to\\file.exe",
    "arg1 arg2", 
    NULL, 
    NULL, 
    FALSE,
    0, 
    NULL, 
    "path\\to\\working\\directory\\", 
    &startupInfo, 
    &processInfo
);

//Shell Execute
ShellExecute(NULL, "open", "path\\to\\file.exe", "arg1 arg2", "path\\to\\working\\directory\\", SW_SHOWDEFAULT);

//ShellExecuteEx 
SHELLEXECUTEINFO shExInfo= {0};
shExInfo.cbSize = sizeof(SHELLEXECUTEINFO);
shExInfo.lpFile = "path\\to\\file.exe";
shExInfo.lpParameters = "arg1 arg2";
shExInfo.lpDirectory = "path\\to\\working\\directory\\";
shExInfo.nShow =  SW_SHOWDEFAULT;
ShellExecuteEx(&shExInfo);

In Java is the java.lang.Process and java.lang.ProcessBuilder
PHP:
ProcessBuilder pb = new ProcessBuilder( "path\\to\\file.exe", "arg1", "arg2");
Process p = pb.start();
 
Back