|
Search through the Code Project articles. Look for ones by Christian Graus on image manipulation in C#.
|
|
|
|
|
+5 for suggesting nice articles..
Happy Coding...
|
|
|
|
|
I put together a simple web browser using c#. Its great, its simple. I
added a button. I click the button and I want to be able to log into a
particular website. I have this code:
string username = "username";
string password = "pass";
string commit = "Login";
string postData = string.Format("txtuserid={0}&txtpassword={1}&btnlogin={2}", username, password, commit);
ASCIIEncoding enc = new ASCIIEncoding();
webBrowser1.Navigate("new page.html", "", enc.GetBytes(postData), "Content-Type: application/x-www-form-urlencoded\r\n");
But it doesnt do anything. Is there a way to make the username and password
appear in there respective boxes? Is there another command that I use to
make it click that Login button and move onto the next page?
Please any response any one can give me will be greatly appreciated.
|
|
|
|
|
|
In reading that link that you provide, it almost seems like its possible
in C# to fill out a page and click "login" and log into that page.
If its possible, can I send you a sample project and can you help me log
into an account, any account?
|
|
|
|
|
Is there anything like this I can use:
http://www.netomatix.com/httppostdata.aspx
If I sent you a sample project, could you help me make it log into a site,
any site?
|
|
|
|
|
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.
string output = "";
try
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo("tasklist");
p.StartInfo.Arguments = " /v";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
output = (p.StandardOutput.ReadToEnd());
output = output.Remove(0,453);
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)
{
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..
|
|
|
|
|
Why don't you use the Diagnostics namespace to programmatically determine what processes are running?
Process.GetProcesses();
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I need the total elapsed time of "Idle" to calculate % cpu usage per process. WMI & performance counters are too slow because of their thread.sleep(1000) requirement.
|
|
|
|
|
Try opening a command window and type tasklist /? to get all the options.
You'll find that there is /NH to remove the column headers and /FO CSV to dump the output in comma separated value format.
The output from "tasklist /v /nh /fo csv" will be something like this:
"System Idle Process","0","Console","0","28 K","Running","NT AUTHORITY\SYSTEM","71:33:38","N/A"
"System","4","Console","0","256 K","Running","NT AUTHORITY\SYSTEM","0:24:32","N/A"
"smss.exe","1680","Console","0","924 K","Running","NT AUTHORITY\SYSTEM","0:00:00","N/A"
It will be advantageous to capture the output as lines rather than one long string. For this use ReadLine in a loop instead of ReadToEnd.
The final step is subdivision of each line at the comma delimiters to get the individual fields (use the String.Split method).
Alan
|
|
|
|
|
Excellent!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Alan,
Nice catch on the /nh /fo /csv thing.
Quick question though...
How would you suggest trimming the '"' quote marks from the values & given that you can't split on ',' commas because e.g. "csrss.exe","996","Console","0","7,372 K" (the comma in the memory component 7,732K) would cause a problem.
|
|
|
|
|
|
Hi Luc, gee thanks...didn't know you cared...
The issue is that if you run
Process p = new Process();
p.StartInfo = new ProcessStartInfo("tasklist");
p.StartInfo.Arguments = " /v /nh /fo csv";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
while (true)
{
string o = p.StandardOutput.ReadLine();
if (!string.IsNullOrEmpty(o))
{
string [] s = o.Split(',');
Console.WriteLine(o);
Console.ReadLine();
}
}
occasionally, you only get the last 2 values of the first line. Also, you can't do this
Console.WriteLine(a.Remove(0,1).Remove(a.Length -1,1)); without an exception 'System.ArgumentOutOfRangeException: Index and count must refer to a location within the string. Parameter name: count' which doesn't make much sense because if:-
string s = "bob";
s = s.Remove(s.length -1,1)
result = bo
why is Remove(a.Length -1,1) causing an exception?
Could anyone make any (relevant) suggestions...
|
|
|
|
|
CCodeNewbie wrote: Console.WriteLine(a.Remove(0,1).Remove(a.Length -1,1));
It is way better to write 5 simple lines you understand, than one complex one you think you understand but you don't.
|
|
|
|
|
There are a few things I don't understand with this.
Why does this...
string o = p.StandardOutput.ReadLine();
o = o.Replace("\n", string.Empty);
if (!string.IsNullOrEmpty(o))
{
Console.WriteLine(o);
}
...which gives me...
"System Idle Process","0","Console","0","28 K","Running","NT AUTHORITY\SYSTEM","46:49:36","N/A"
work perfectly, but this...
string o = p.StandardOutput.ReadLine();
o = o.Replace("\n", string.Empty);
if (!string.IsNullOrEmpty(o))
{
string [] s = o.Split(',');
string a = s[0];
string b = s[1];
string c = s[2];
Console.WriteLine(a + b + c);
}
give me a flashing cursor and when I hit enter I get...
"System""4""Console"
where has "System Idle Process" gone?...
and despite having this...
if (!string.IsNullOrEmpty(o))
I still get-
System.NullReferenceException: Object reference not set to an instance of an object.
Aargh!!!
|
|
|
|
|
CCodeNewbie wrote: and despite having this...
if (!string.IsNullOrEmpty(o))
I still get-
System.NullReferenceException: Object reference not set to an instance of an object.
..you're not getting the exception on that particular line, are you?
if (!string.IsNullOrEmpty(null))
This is allowed, and doesn't result in an exception.
It helps if you chop your function up into smaller bits. That way you'll also be looking at less code when there's a failure.
You might also want to dump the entire exception to the console;
try
{
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
The exception will tell you which line blew up.
..and as someone else mentioned in this thread, it's easier to write a lot of simple statements than to maintain a single complex one.
Bastard Programmer from Hell
|
|
|
|
|
That's the irritating part, it doesn't blow up. It just outputs only part of the first line.
just ran it, worked perfectly. ran it again & got Quote: "81:15:36","N/A" as the first line..
Quote: You might also want to dump the entire exception to the console; I always put everything inside try..catch, I am not experienced enough to be able to accurately predict what the code is going to do.
try
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo("tasklist");
p.StartInfo.Arguments = " /v /nh /fo csv";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
while (true)
{
string o = p.StandardOutput.ReadLine();
if (!string.IsNullOrEmpty(o))
{
Console.WriteLine(o);
string[] s = o.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string a = s[0];
string b = s[1];
string c = s[2];
Console.WriteLine(a + " : " + b + " : " + c);
Console.ReadLine();
}
}
}
catch (Exception se)
{
Console.WriteLine(se.ToString());
Console.ReadLine();
}
|
|
|
|
|
ran it again and got
81:33:06","N/A"
"System Idle Process" : "0" : "Console"
WT? Could it be that "while (true)" is exiting properly? I am noticing that the Console window doesn't close after the last Readline().
|
|
|
|
|
An illustration of what I mean:-
string o = p.StandardOutput.ReadLine();
if (!string.IsNullOrEmpty(o))
{
string[] s = o.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string a = s[0];
string b = s[1];
string c = s[2];
Console.WriteLine(o);
Console.WriteLine(a + " : " + b + " : " + c);
Console.ReadLine();
}
results in
"System Idle Process","0","Console","0","28 K","Running","NT AUTHORITY\SYSTEM","64:59:34","N/A"
"System","4","Console","0","264 K","Running","NT AUTHORITY\SYSTEM","0:11:53","N/A"
"System" : "4" : "Console"
Why is there no entry under the "System Idle Process" like the bolded entry under "System"?
|
|
|
|
|
I found this link:
http://www.dreamincode.net/forums/topic/152297-c%23-log-in-to-website-programmatically/
and it kinda shows how to log into a twitter account. Im trying to do
the same thing to a yahoo account or godaddy account or anything else
just to understand this more.
Can anyone show me how to log into something like yahoo or godaddy or
something else other than twitter? Please any response any one can
give me will be greatly appreciated.
|
|
|
|
|
i use this code
SqlCommand cmd1 = new SqlCommand("insert into '" + comboBox6.SelectedItem.ToString() + "' (name,address,telephone,website,email,info,place_id,cor_x,cor_y)values(" + "'" + textBox_name.Text + "','" + textBox_address.Text + "','" + textBox_telephone.Text + "','" + textBox_website.Text + "','" + textBox_email.Text + "','" + richTextBox_info.Text + "' , select id from places where name= '"+ comboBox6.SelectedItem.ToString() +"','" + textBox_corx.Text + "','" + textBox_cory.Text + "') ", con);
and this error showed
Incorrect syntax near the keyword 'select'.
Incorrect syntax near ','.
what should i do ?
|
|
|
|
|
I don't know, but that would be easier to read if you used String.Format and a parameterized query (which you should do anyway).
|
|
|
|
|
I don't think you want single quotes around your table name on the 'insert' command.
Jack of all trades ~ Master of none.
modified 6-Apr-12 20:25pm.
|
|
|
|
|
I would use two SQL statements, one to get the place ID from its name, then the big insert which needs the result of the former statement.
And I would:
- never publish code in a proportional font (they invented PRE tags to get readable code here);
- not build such complex statements; why not building a string first, so you can see it, log it, whatever;
- not take user input without validating it;
- use SqlParameters.
And finally you could consider creating a stored procedure to do this.
|
|
|
|
|