how to Add multiple cmd shell command lines vb.net - vb.net

I want to run a few command lines by shell after I run the first command
I use the following command but it does not work
Shell("cmd.exe /k" + "<adb shell 1> & <su 2> & <mv /data/local/tmp/build2.prop /system/build.prop 3>")
For example, I execute the following commands in cmd
adb shell
su
mv /data/local/tmp/build2.prop /system/build.prop
How can I run vb.net?
edite -----------------------------------------------------
Honestly, we need to transfer the file to vb.net into the Android device /system folder
We use androidlib by the following command, but it does not work
Adb.ExecuteAdbCommand(Adb.FormAdbCommand("shell", "su", "-c", "mount -o remount, rw /system"))
Adb.ExecuteAdbCommand(Adb.FormAdbCommand("shell", "su", "-c", "cat /data/local/tmp/build2.prop > /system/build.prop"))
This command executes the read-only file system error

What you appear to be after is executing additional commands inside adb, in which case what you're currently doing will not work. Combining commands with the ampersand & will execute each command separately, not in a previously opened process.
To do what you want you've got to redirect standard input for the adb process, not CMD.
Redirecting the input is simply a way of changing where the process gets its input from. Instead of getting it from the keyboard input stream (the user) you can redirect it to a different stream which you have control over.
Untested, but something like this should work:
Dim psi As New ProcessStartInfo("adb", "shell 1")
psi.UseShellExecute = False
psi.RedirectStandardInput = True
Dim p As Process = Process.Start(psi)
Dim InputStream As StreamWriter = psi.StandardInput
InputStream.WriteLine("su 2")
InputStream.WriteLine("mv /data/local/tmp/build2.prop /system/build.prop 3")

Related

PowerShell doesn't recognize string correctly

I'm passing a command to powershell
Dim command As String
command = "ffmpeg -vsync 0 –hwaccel cuvid -c:v h264_cuvid –resize 1280x720 -i D:\Imagens\nova\bol.mkv -c:a copy -c:v h264_nvenc -b:v 5M D:\Imagens\nova\bol_encod.mkv"
with
Dim powerShell As String = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
Process.Start("powershell", "-noexit " + command)
but powershell returns
Unable to find a suitable output format for 'ÔÇôhwaccel' ÔÇôhwaccel:
Invalid argument
where I believe 'ÔÇôhwaccel' to be –hwaccel; That's completely strange, once when I past the code directly on PowerShell it works fine.
Is that a problem with my string?
thank you!
I'm assuming powershell 5 and not core, I copied the test and pasted it into the terminal and found this u instead of a '-'. I would start by retyping and avoiding what looks like it may be a long hyphen or something else which is breaking the terminal.

Shell Command to launch application with parameters

I am trying to launch spotfire application from VBA like following
Dim retval As Double
retval = Shell("Path\Spotfire.Dxp.exe", vbNormalFocus)
It works. It launches spotfire with the default servername,username and password
But I want to launch the application by giving the servername, username and password as parameters in the script. How do I do it?
I tried this
retval = Shell("Path\Spotfire.Dxp.exe -s http://spotfire.abcd.com -u ABCD\A7 -p ABC", vbNormalFocus)
But it launched the application with default parameters and gives error at the end "Unable to load file. Could not find the specified file : -s"
Please suggest the possible solution.
after checking our support db, I found a few references to / notation instead of -. so the following command should work:
c:\path\Spotfire.Dxp.exe /server:http://localhost:8080/ /username:user /password:pass

Remote Netstat to STDOUT with WMIC?

I would like to use WMIC to retrieve the output of a "netstat" command on a remote computer. The actual execution of the following command executes without error and I see the output popup briefly within a new window:
wmic /node:server1 process call create "netstat.exe -ano"
With that being said, I need to pipe the output of the process window to STDOUT, and have tried:
wmic /node:server1 process call create "netstat.exe -ano > C:\temp\test.txt"
However, that does not work. I have also tried the /output:STDOUT option, however, that only reports the execution of the command:
Executing (Win32_Process)->Create() Method execution successful. Out Parameters: instance of __PARAMETERS {
ProcessId = 5044;
ReturnValue = 0; };
Does anyone know how I can go about using WMIC to retrieve the actual output from the new window that was opened in order to process the data?
Thanks in advance!
The > symbol behaves as operator of redirection in cmd.exe, not in netstat.exe.
In fact, wmic process call create "netstat.exe -ano > C:\temp\test.txt" is about to run the same as netstat.exe -ano ^> files\nstat.txt (try it from command line).
Next command works (unfortunately, I can't try it with /node:"server1" against a remote computer at the moment):
wmic process call create "cmd /C > C:\temp\test.txt 2>&1 netstat.exe -ano"

How to write a ping to a text file using VBS

If I am using VBS to run some CMD commands, in this example ping, how could I write the command to a text file using VBS not DOS?
Set objCmdTest = WScript.CreateObject ("WScript.Shell")
Set Output = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\vbs\test.txt",8,true)
Output.WriteLine (objCmdTest.run ("ping failboat"))
Output.WriteLine (objCmdTest.run ("ping 8.8.8.8"))
So this is what I'm working with however what happens is; The script runs, the file is made, 2 command prompts open to run the pings and finally the text inside the file reads:
0
0
When I'd much prefer it to have the ping output.
FYI: Please don't offer suggestions that require me to use DOS for the writing, I'd like to see how VBS can do what I need for multiple reasons, thanks!
The instruction Output.WriteLine (objCmdTest.run ("ping failboat")) will write the return value of the Run method to the output file. If you want to append the command output to an output file you have to either redirect the output in the command:
objCmdTest.run "%COMSPEC% /c ping failboat >>C:\vbs\test.txt", 0, True
or use Exec instead of Run:
Set ping = objCmdTest.Exec("ping failboat")
Do While ping.Status = 0
WScript.Sleep 100
Loop
Output.WriteLine ping.StdOut.ReadAll
WScript.Shell's run method returns the process's exit code. In order to get access to an application's output, you need to use the exec method instead, and use the object that returns to get access to the process's standard output through its StdOut property.

Executing more than one command with ssh2 exec

I have a script that runs one command. Based on that result, I can run the next command. Steps:run first script it puts me in global then from global I will run the next command.
First command:
$stream = ssh2_exec($connection, 'config global');
After this result I should run this cause I need to go into global
$stream = ssh2_exec($connection, 'get hardware cpu');
you can do like this
$stream = ssh2_exec($connection, 'command1;command2');