|
Heath,
Thanks for your answer. That sounds like a lot of work for the benefits (since the users would have used this feature only once in a while).
Thanks again!
Carl
|
|
|
|
|
Carl,
I don't think what Heath is suggesting would take alot of work. Just do this:
1) Hook into the MouseClick event and see if the right mouse has been clicked.
2) Create a simple form with the checkboxes and make it a non-sizable dialog.
3) The user checks to their hearts content then clicks the OKAY button
4) You process the results. Voila, you replace the context menu with what you need!!!
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
That may seem like a stupid solution, but it may be the only one you have. You are trying to change the nature of a context menu (or any menu for that matter). You either need to create your own control from scratch or you could just create a small dialog box with checkboxes instead. Just create a selection in your current context menu that says "Set Options", and then open a dialog box with your checkboxes in it when that option is selected. I know this isn't the answer you're looking for, but I can't think of any way to override context menu behaviour without some inelegant hack that, from a useability perspective, probably shouldn't be done anyhow.
Best Regards.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I’ve got a problem. That is, when we use those Windows APIs,such as SetupDiGetClassDevs() and SetupDiEnumDeviceInterfaces(),
to enumerate all the instances of the usb device class, what I wanna make sure are the answers to these questions:Is there a certain
rule which determines the order of being enumerated among all the instances? In other words,If we can depend on a certain rule to
foreknow which device instance will be enumerated first,which will be the next and which will be the last? If there is,then what
it is? If not,how can we let the first attached one be first enumerated,the next will be next,and the last will be last?
|
|
|
|
|
Your question has absolutely nothing to do with C#. You need to either read the documentation for the functions you're P/Invoking (in the Platform SDK at http://msdn.microsoft.com/library[^]) or pack the returned data into an array in C# and sort it using Array.Sort and an IComparer implementation (like Comparer.Default which works for the intrinsics and strings).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi...
I want my Application to run when windows start..!
I didn't know how to do it, so i searched the registry on my computer and found the key i think was the right ("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")
I tried to do this...
string path = Environment.CurrentDirectory + "\\MyApp.exe";
RegistryKey App = Registry.LocalMachine;
RegistryKey App = App.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\");
App.SetValue("MyApp", path);
But that did not work.... it throws a "'System.NullReferenceException' -
Additional information: Object reference not set to an instance of an object."
Then I tried this....
string path = Environment.CurrentDirectory + "\\MyApp.exe";
Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Run").SetValue("MyApp", path);
But it also thorws an error -> "'System.UnauthorizedAccessException' occurred in mscorlib.dll - Additional information: Cannot write to the registry key."
I have no idea what to do then!
Can anyone help me how to write to the registry or tell me a way so my application will run when windows start?
Thanks...!
QzRz
|
|
|
|
|
Put a shortcut in the startup folder of the start menu.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I dont understand what you mean...
is there a folder i can put a shortcut in so it automaticly will run it when windows start..?
if that is what you mean.... how can i find it...? (need to find it also if it is not on same drive on every computer)
QzRz
|
|
|
|
|
Click 'Start', go up to 'Programs', and expand the list if necessary. There's a folder there called 'Startup'. An install program should allow you to put a shortcut there, or alternatively, the folder structure is stored at <current user documents and settings location>\Start Menu\Programs\Startup. There are functions that help you find the location of special folders like the one windows is in, or the one where your documents and settings live.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
LOL. How can someone not know about this???
Alex Korchemniy
|
|
|
|
|
Adding to what Christian has said, the Startup folder executes everything in it when a user logs in, NOT when Windows starts. The same thing is true for the Run key your trying to use. The only way to get an application to start when Windows starts (and will run even if a user is not logged in) is to write your application as a Service.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
OKay.... but if I wants it to write a value to the registrykey, then is there a way for me to do that...?
QzRz
|
|
|
|
|
Using the original code you posted, take the two backslashes off the end of the path to the Run key:
string path = Application.StartupPath + "\\MyApp.exe";
RegistryKey App = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
App.SetValue("MyApp", path);
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well.... it still doesn't work... still it gives me a "'System.NullReferenceException' - Additional information: Object reference not set to an instance of an object."
The code looks like...
string path = Environment.CurrentDirectory + "\\MyApp.exe";
RegistryKey AppA = Registry.LocalMachine;
// Change the next line. Remove the two backslahes from the end of 'Run'...
RegistryKey App = AppA.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
App.SetValue("MyApp", path);
QzRz
|
|
|
|
|
My fault. There are a couple of problems, and are easily corrected if you, or I, would read the documentation on the RegistryKey class.
using System.Io;
using Microsoft.Win32;
string path = Path.Combine( Application.StartupPath, "MyApp.exe" );
RegistryKey myKey = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true );
myKey.SetValue( @"MyApp", path );
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks.... it works perfect now!
QzRz
|
|
|
|
|
I am writing an application that accesses a web page (the first page) with an httpget to retrieve the first page, issues an httppost with selection data and cookie from the first page httpget to retrieve a second page, then retrieves subsequent third pages with httpgets based on links in the second page. These third retrieves fail in the C# application.
If I use IE or Mozilla to make these third page retrieves, a proxy sniffer shows that on the third retrieve some additional data has been added to the cookie. The proxy sniffer also shows that some javascript routines have been downloaded on the first page retrieve and looking at the source from the second page retrieve it seems that it is one of these javascript routines that is adding the data to the httpget for the third page.
So in my C# application, what happens to the downloaded javascript routines and how do I access and run them in the same way my browsers do this?
Jerome K Jerome
|
|
|
|
|
The javascript files get downloaded the same was as everything else: data. What happens with the data is completely up to the client (your code).
Internet Explorer actually hosts the scripting engines (JScript, VBScript, and any other third-party scripts like PerlScript from ActiveState[^]). This doesn't happen just by downloading data (actually, nothing happens just by downloading data no matter what the client is - it's just a stream of bytes).
Hosting the scripting engines in such a way that you can simulate what the browser does is more complicated than you could probably imagine. Not only do you have to implement the interfaces that the browser does (practically all the interfaces defined by both mshtml.dll and shdocvw.dll, but many, many other COM interfaces (i.e., you can't just implement these interfaces: they don't exist in .NET), not to mention the Windows Script Host interfaces. Believe me, as part of the team that develops and sustains Windows Script I can assure you that's it's a complicated and very long job that you may not want to emark on! If you do, you must completely understand COM interop, P/Invoke, and data marshaling between unmanaged and managed code, and understand COM and OLE and how COM clients and servers interact through sites, threading models, and more.
Your best bet is to use inflection to determine what the script file would do by detecting certain patterns.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Well, you are right that I don't want to reinvent IE in my code nor am I proficient enough to do that. I don't think the problem is all that complicated and I don't really need the application to react as if it were a browswer. The proxy sniffer reports that the cookie has appended to it a string very much like this: "ForeseeLoyalty_MID_dh4QBcM8h8=55". On subsequent retreives the last two digits change.
A Google search on "FORESEELOYALTY" brings up very little but the javascript comments indicates it is being used for survey purposes and controlls a pop up. But using IE, I have never seen such a pop up.
It looks to me as though the string between "Foreseeloyalty_MID" and "=" is being passed in with the javascript and the last two digits are being computed. But I don't really know how to capture the javascript or how to append the new string to the cookie. The webRequest and webResponse only pass back to me the html, not the javascript and in the case of redirects, not even the pre-redirected html
As I see it, I at least have to capture the javascript so I can extract the token for the foreseeloyalty key.
|
|
|
|
|
If the javascript is being sent to you in your HttpWebResponse (your original description isn't very clear between steps 2 and 3), then you already have it. You don't need to parse it as javascript - just parse it as text. With the HttpWebResponse.GetResponseStream<?code> method, use the <code>HttpWebResponse.CharacterSet passed to Encoding.GetEncoding to get the proper Encoding class (I recommend using the UTF8Encoding as a fallback since it'll handle both ANSI and most Unicode, and is becoming more and more common on the web anyway).
Use Encoding.GetString after reading in all your bytes (so long as your return data isn't too big) and parse the resulting string.
If this isn't applicable, please explain steps 2 and 3 in a little more detail.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Below find the code for my web retrieves, adapted from Johnvey's Gmail Agent (Code Project).
What is returned after calling this the first time is simply the html of the first page and with it a cookie. On the second retrieve, I simply make a retrieve identical to the first one, but this time there is a cookie to send that I got from the first response. The result of the second call is also simply an html page. No javascript either time. (Perhaps this double retrieve is unneccesary, it works and I've never tried retrieving it only once. Have to put that on the todo list...)
I should also mention that this first/second page retrieve involves one redirect. I think the redirect is used to pass the cookie and possibly the javascript as well, so maybe the javascript is coming in as a response to the page I am not seeing because it is redirected.
private string MakeNewWebRequest(Uri location, string method, string referrer, string postData, bool allowAutoRedirect)
{
// prepare HTTP request
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(location);
webRequest.CookieContainer = new CookieContainer();
if (cookieJar!=null)
{
webRequest.CookieContainer.Add(webRequest.RequestUri, this.cookieJar.GetCookies(webRequest.RequestUri));
}
else
{
System.Windows.Forms.MessageBox.Show("No CookieJar!", "Debug");
}
// if POSTing, add request page and modify the headers
byte[] encodedPostData = new byte[0];
if(method == "POST")
{
ASCIIEncoding encoding = new ASCIIEncoding();
encodedPostData = encoding.GetBytes(postData);
webRequest.Method = "POST";
webRequest.ContentType="application/x-www-form-urlencoded";
webRequest.ContentLength = encodedPostData.Length;
}
else
{
webRequest.Method = "GET";
webRequest.ContentType = "text/html";
}
webRequest.Timeout=295000; // 295 seconds (4 min 55 sec) supports long downloads
webRequest.Headers["Accept-Language"] = "en-us";
webRequest.Headers["Accept-Charset"] = "ISO-8859-1,utf-8;q=0.7,*;q=0.7";
webRequest.ProtocolVersion = HttpVersion.Version11;
webRequest.AllowAutoRedirect = allowAutoRedirect;
webRequest.KeepAlive = true;
webRequest.Referer = referrer;
webRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040626 Firefox/0.8";
webRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */* ";
//sample cookie "Cookie:WEBTRENDS_ID=68.255.78.35-1098489905.786792::588AC2E5087CF3F2AD7B775FB2116AB2; ForeseeLoyalty_MID_dh4QBcM8h8=55"
//note: cookie may also be JSESSIONID
//Attempt to send request stream to server if POSTing
if(method == "POST")
{
Stream requestStream = null;
try
{
requestStream = webRequest.GetRequestStream();
requestStream.Write(encodedPostData, 0, encodedPostData.Length);
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
}
finally
{
if(requestStream != null)
{
requestStream.Close();
}
}
}
// Attempt to get response from server
HttpWebResponse webResponse = null;
string output = "";
try
{
string
headers = "";
foreach(string key in webRequest.Headers.Keys)
{
headers += key + "=" + webRequest.Headers[key] + " | ";
}
Debug.WriteLine(" Request Headers: " + headers);
// get response
webResponse = (HttpWebResponse)webRequest.GetResponse();
webResponse.Cookies = webRequest.CookieContainer.GetCookies(webRequest.RequestUri);
this.cookieJar.Add(webResponse.Cookies);
string cooks="";
// Print the properties of each cookie.
foreach (Cookie cook in webResponse.Cookies)
{
cooks += "\n Name = " +cook.Name + "\n Value = " +cook.Value+"\n Domain = "+cook.Domain+"\n Path = "+cook.Path+"\n Port = "+cook.Port+"\n Secure = "+cook.Secure+"\n | ";
Debug.WriteLine(" Cookies: " + cooks);
//
foreach(Cookie ck in webResponse.Cookies)
{
Debug.WriteLine(" Adding cookie: " + ck.ToString());
}
// read response stream and dump to string
Stream streamResponse = webResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
output = streamRead.ReadToEnd();
streamRead.Close();
streamResponse.Close();
Debug.WriteLine("Received response (" + output.Length + " char(s))");
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
System.Windows.Forms.MessageBox.Show(ex.Message, "Exception Caught");
}
finally
{
if(webResponse != null)
{
webResponse.Close();
}
}
// return the response document
return output;
}//end string MakeNewWebRequest
|
|
|
|
|
In my last post I mistakenly said I made this first retrieve twice to get the cookie. That is not true, I only make it once to get the cookie for the next retrive which is a post.
|
|
|
|
|
After some further testing, I see I can manually add the loyalty factor cookie but for some reason it never gets sent out on the get, only posts seem to send out the cookie.
|
|
|
|
|
Have you watched your traffic through a packet monitor? I find it odd - as I know you do - that your cookie isn't being sent with the GET request. Perhaps it is but the server doesn't handle the GET request and, thus, doesn't process the cookie.
If you think the cookie is coming with the HTTP redirect (again, a packet monitor really helps in these situations; you can get them all over on the web, but most will require a packet driver that, for some reason, the name seems to elude me right now - sorry) you should set HttpWebRequest.AllowAutoRedirect to false and handle it yourself. If the HTTP status code is 302, 303, or 305 (see the HttpStatusCode or on the web for the HTTP RFC or something) an exception will be thrown (which one, they don't say so give it a test and handle only that exception (other exceptions could be thrown for other reasons), which you'd handle and get the Location: header to send a request for the redirection location.
BTW, for cleaner code, you might consider using the using block statement instead of your own try-finally. It really has more to do with readability, but the effect is the same (compiles to a try-finally just as you're doing it). That's just my opinion, though. What you're doing is correct coding practice.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I think I finally got it to work. Thanks so much for your help. Now I have a new problem. I posted it as a new thread, but it seems to be so much in your ball park, I want to repeat it here.
The application follows several links in a web site, finally arriving at a link to a pdf file. I issue an httpget for this file and receive a response like the following:
HTTP Response 200 (OK) "APPLICATION/PDF" (72'407 bytes)
But what is returned from the streamRead.ReadToEnd is just an html page that says the pdf is downloading and that this page will be updated every seven seconds until the download is complete. How do I navigate my way around this so that I end up with the pdf document? Is this status page interleaved with the pdf document stream or are they separate?
|
|
|
|
|