06. februar 2009 - 12:52Der er
6 kommentarer og 1 løsning
Read %ERRORLEVEL%
Dav eksperter... har et mindre problem. har skrevet noget kode som skal pigne osv.. problemet er i 3 while sætning at jeg ikke kan få den til at læse ERRORLEVEL og få den til at arbejde på det i en switch
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics;
namespace Online_check { class Program {
static void Main(string[] args) { int a = 10; int b = 129; int c = 1; int d = 1;
string Errorlevelstring; int Errorlevel = 2;
while (a == 10 && b < 255 && c < 255 && d < 256) {
string ip = a + "." + b + "." + c + "." + d; Process p = new Process(); p.StartInfo = new ProcessStartInfo("cmd", "/c \"ping -n 1 " + ip + "\"")
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine(output); //Console.ReadLine(); if (output.Contains("TTL expired")) { Console.WriteLine("Nothing on "+ip); } if (output.Contains("TTL=")) { Console.WriteLine("Success "+ip); Console.WriteLine("Pinging network "+ip); while (a == 10 && d < 255) { string ip1 = a + "." + b + "." + c + "." + d; Process p1 = new Process(); p1.StartInfo = new ProcessStartInfo("cmd", "/c \"ping -n 1 " + ip1 + "\"")
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
p1.Start();
string output1 = p1.StandardOutput.ReadToEnd();
Process p3 = new Process(); p3.StartInfo = new ProcessStartInfo("cmd", "/c \"%ERRORLEVEL%") {
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
}; p3.Start();
Errorlevelstring = p.StandardOutput.ReadToEnd(); if (Errorlevelstring.Contains("1")) { Errorlevel = 1; } if (Errorlevelstring.Contains("2")) { Errorlevel = 2; }
Environment.GetEnvironmentVariable("ERRORLEVEL") virker ikke optimalt :/...
Hmm, kan godt være jeg skal tage mig sammen og gører det arne... Ville nu ellers være rart at kunne gøre det på denne måde ;).. er der også lidt mere udfordring i ;)!
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.