- To execute their commands 1 at a time, only add the command:
cmd /c
.
Is this the interpreter of commando, and it is he who will "use/interpret
” your commands
O layout do seu código ficaria dessa forma :
#include <stdlib.h>
int main ()
{
system("cmd /c ipconfig /release");
system("cmd /c ipconfig /renew");
system("cmd /c ipconfig /flushdns");
system("cmd /c ipconfig /registerdns");
system("cmd /c nbtstat -RR");
system("cmd /c netsh int ip reset all");
system("cmd /c netsh winsock reset");
}
Ou de uma forma concatenada em uma só linha, o interpretador vai “entender” que é parar chamar/executar comando por comando, um após o outro obedecendo o operador "&"!
Onde o código ficaria com esse layout "cmd /c Comando & comando & comando &..." :
#include <stdlib.h>
int main ()
{
system("cmd /c ipconfig /release & ipconfig /renew & ipconfig /flushdns & ipconfig /registerdns & nbtstat -RR & netsh int ip reset all & netsh winsock reset");
}
• Observações sobre os operadores: &, |, && e ||
According to the scenario/behaviour of their commands, you can do use when:
execute & execute & execute
execute | recebe _saída_do_comando_anterior
execute | recebe _saída_do_comando_anterior & execute
executou_sem_erro && então_execute_também
executou_com_erro || execute_também_porque_deu_erro
executou_com_erro || executou_com_erro || executou_com_erro
executou_sem_erro && executou_sem_erro && executou_sem_erro
executou_sem_erro && então_execute || execute_esse_no_primeiro_deu_erro
Sorry, I didn’t understand how to apply this command to the code
– Lucas
Do a test with the second command, in it you do not have the HWND just copy and paste, if it works from a look at the documentation to mean how it works.
– Lodi
I used the second command, compiled but it gives "Process returned 0" so I saw in the documentation this return is a mistake. Also, apparently the cmd commands are not executed correctly, I have already revised all but still failing. Error giving is "unrecognized or incomplete command line."
– Lucas
tries to replace the fourth parameter with this
/c ipconfig /release ipconfig /renew ipconfig /flushdns ipconfig /registerdns nbtstat -RR netsh int ip reset all winsock reset
– Lodi
Thank you! is still failing but this way I could find the syntax that cmd understands, I changed "/c" to "/k" to visualize what was happening and saw that for "ipconfig" when it has more than one command should be written like this: "/k ipconfig [/release | /Renew | /flushdns | /registerdns]". Thus compiled, only gave error in "Renew", says '/Renew' is not recognized as an internal or external command, a program operable or a batch file.
– Lucas