Click here to Skip to main content
15,883,901 members
Home / Discussions / C#
   

C#

 
Questionaccessing image by bit in c # Pin
waqar rashid7-Apr-12 21:56
waqar rashid7-Apr-12 21:56 
AnswerRe: accessing image by bit in c # Pin
Pete O'Hanlon7-Apr-12 22:49
mvePete O'Hanlon7-Apr-12 22:49 
GeneralRe: accessing image by bit in c # Pin
Vipin_Arora8-Apr-12 21:36
Vipin_Arora8-Apr-12 21:36 
Questionlog into a website Pin
DanYELL7-Apr-12 8:15
DanYELL7-Apr-12 8:15 
AnswerRe: log into a website Pin
Not Active7-Apr-12 11:08
mentorNot Active7-Apr-12 11:08 
GeneralRe: log into a website Pin
DanYELL7-Apr-12 13:47
DanYELL7-Apr-12 13:47 
GeneralRe: log into a website Pin
DanYELL9-Apr-12 3:46
DanYELL9-Apr-12 3:46 
QuestionGetting values from tasklist.exe /v Pin
CCodeNewbie7-Apr-12 6:24
CCodeNewbie7-Apr-12 6:24 
Hi,

I think it is possible to do this but before I spend another 8 hours on it I would like to ask for some advice please.

Basically I am trying to get the values from tasklist /v into my C# code.

I have tried retrieving the indexes but they are not output as recurring values or some form of table they just keep going until the end of the output.

I am thus trying to send the output of the split string to a foreach value but am ending up with the individual values (as expected). Is there some way I can concatenate these values into a coherent string whose values can be meaningfully separated.

C#
string output = "";
try
    {
//set up and start the process
        Process p = new Process();
        p.StartInfo = new ProcessStartInfo("tasklist");
        p.StartInfo.Arguments = " /v";
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.UseShellExecute = false;
        p.Start();
//clean up the output
        output = (p.StandardOutput.ReadToEnd());
        output = output.Remove(0,453);// the first 453 char values are column headings, spaces and '=' signs
        output = output.Trim();
        output = output.Replace("           ", " ");
        output = output.Replace("          ", " ");
        output = output.Replace("         ", " ");
        output = output.Replace("        ", " ");
        output = output.Replace("       ", " ");
        output = output.Replace("      ", " ");
        output = output.Replace("     ", " ");
        output = output.Replace("    ", " ");
        output = output.Replace("   ", " ");
        output = output.Replace("  ", " ");
        output = output.Replace('\r', ' ');
        output = output.Replace('\n', ' ');
        while (true)// keep it alive
        {
            string[] s = output.Split(' ');
            {
                foreach (string value in s)
                {
                    if (!string.IsNullOrEmpty(value))
                    {
                        Console.WriteLine(value);
                        Console.ReadLine();
                    }
                }
            }
            p.WaitForExit();
        }
         
    }
    catch (Exception se)
    {
        Console.WriteLine(se.Message + output.ToString() + se.InnerException);
        Console.ReadLine();
    }


from this I get:
System

Idle

Process

0

Console

0

28

K

Running

NT

AUTHORITY\SY

33:30:14

N/A

Is there a way to "convert" this to:

s[0] = SystemIdleProcess
s[1] = 0
s[2] = Console
s[3] = 0
s[4] = 28K
s[5] = Running
s[6] = NTAUTHORITY\SYSTEM
S[7] = 33:30:14
S[8] = N/A

Thank you for your time..
AnswerRe: Getting values from tasklist.exe /v Pin
Richard Andrew x647-Apr-12 6:42
professionalRichard Andrew x647-Apr-12 6:42 
GeneralRe: Getting values from tasklist.exe /v Pin
CCodeNewbie7-Apr-12 6:55
CCodeNewbie7-Apr-12 6:55 
AnswerRe: Getting values from tasklist.exe /v Pin
Alan N7-Apr-12 9:55
Alan N7-Apr-12 9:55 
AnswerRe: Getting values from tasklist.exe /v Pin
Richard Andrew x647-Apr-12 10:23
professionalRichard Andrew x647-Apr-12 10:23 
GeneralRe: Getting values from tasklist.exe /v Pin
CCodeNewbie7-Apr-12 11:18
CCodeNewbie7-Apr-12 11:18 
GeneralRe: Getting values from tasklist.exe /v Pin
Luc Pattyn7-Apr-12 11:35
sitebuilderLuc Pattyn7-Apr-12 11:35 
GeneralRe: Getting values from tasklist.exe /v Pin
CCodeNewbie7-Apr-12 11:55
CCodeNewbie7-Apr-12 11:55 
AnswerRe: Getting values from tasklist.exe /v Pin
Luc Pattyn7-Apr-12 12:56
sitebuilderLuc Pattyn7-Apr-12 12:56 
GeneralRe: Getting values from tasklist.exe /v Pin
CCodeNewbie7-Apr-12 14:01
CCodeNewbie7-Apr-12 14:01 
GeneralRe: Getting values from tasklist.exe /v Pin
Eddy Vluggen8-Apr-12 8:53
professionalEddy Vluggen8-Apr-12 8:53 
GeneralRe: Getting values from tasklist.exe /v Pin
CCodeNewbie8-Apr-12 9:06
CCodeNewbie8-Apr-12 9:06 
GeneralRe: Getting values from tasklist.exe /v Pin
CCodeNewbie8-Apr-12 9:11
CCodeNewbie8-Apr-12 9:11 
GeneralRe: Getting values from tasklist.exe /v - update Pin
CCodeNewbie7-Apr-12 23:24
CCodeNewbie7-Apr-12 23:24 
Questionprogrammatically log into yahoo or godaddy Pin
DanYELL6-Apr-12 16:55
DanYELL6-Apr-12 16:55 
Questionuse select statement inside insert statement in ado.net Pin
mrx1006-Apr-12 12:22
mrx1006-Apr-12 12:22 
AnswerRe: use select statement inside insert statement in ado.net Pin
PIEBALDconsult6-Apr-12 12:55
mvePIEBALDconsult6-Apr-12 12:55 
AnswerRe: use select statement inside insert statement in ado.net Pin
JOAT-MON6-Apr-12 14:07
JOAT-MON6-Apr-12 14:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.