How can I use the following CMD codes in Visual Studio Windows Form?
1-) nslookup xxxx.yyy.com | FIND /i "192.168.1.88" > c:\temp\nslookup.txt
2-) reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Symantec\Symantec Endpoint Protection\SMC\SYLINK\SyLink" /v "CurrentGroup" > C:\Temp\SymantecKontrol.txt
3-) find /i "Laptopimage" C:\temp\SymantecControl.txt >NUL if %errorlevel% equ 1 goto notfound1
FORM-1 OPEN<<<<<<
goto done
:notfound1
find /c "192.168" C:\temp\nslookup.txt >NUL if %errorlevel% equ 1 goto notfound
FORM-2 OPEN<<<<<<
goto done :notfound
FORM-3 OPEN<<<<<<
CodePudding user response:
If you want to run the commands separately you can do the following:
using System.Diagnostics;
string commandExample = "echo Hello!";
Process.Start($"cmd.exe /c {commandExample}");
or you can run the batch script:
Process.Start("script.bat");
Console.ReadLine();//not needed if you are running it under Windows
Forms template
By my knowledge I don't think it's possible to open a form from batch.
CodePudding user response:
The below command is not working
ProcessStartInfo ps = new ProcessStartInfo(); ps.FileName = "cmd.exe"; ps.WindowStyle = ProcessWindowStyle.Hidden; ps.Arguments = @"/c nslookup xxx.yyyyy.com | FIND /i "217.169" > C:\temp\nslookup.txt";
But this is successful;
ps.Arguments = @"/c echo Hello World ";