Opening notepad from own program
-
Hey, I'm trying to open notepad from my own application when i click a button. I already posted this, but the answer i got had a few problems, and there were no other answers. Thanks for the help[^] Luc Pattyn;), but I didn't get it. Well, actually, I think it was my fault it didn't work. (as in i screwed up when modifying it to be used on button_click). I'd figured I would need a reference, and it says I do ("the type or namespace 'Process' could not be found.( are you missing a using directive or an assembly reference?)") this error occured twice. Any help on correctly doing this or what reference I am missing would be greatly appreciated. Thanks!:)
-
Hey, I'm trying to open notepad from my own application when i click a button. I already posted this, but the answer i got had a few problems, and there were no other answers. Thanks for the help[^] Luc Pattyn;), but I didn't get it. Well, actually, I think it was my fault it didn't work. (as in i screwed up when modifying it to be used on button_click). I'd figured I would need a reference, and it says I do ("the type or namespace 'Process' could not be found.( are you missing a using directive or an assembly reference?)") this error occured twice. Any help on correctly doing this or what reference I am missing would be greatly appreciated. Thanks!:)
Hello again, the Process class is defined in namespace System.Diagnostics you can verify this in the MSDN help; it shows "System.Diagnostics.Process" in the section on Inheritance Hierarchy (at the top of the manual page when using Visual Studio 2003, at the bottom when VS 2005). This means: 1) you must provide a using statement at the beginning of every source file that wants to use the Process class, like so:
using System; // always present ! using System.Diagnostics;
- you MAY have to add a reference; you dont if the Intellisense showed the right stuff while you were typing the using statement (popup list at every period with the required item in it). If it does not show, then you must add a reference (right click your project's name in the Solutions panel). For System.Diagnostics it is automatic though. Once you took care of these issues, the Process constructor, methods and other class members should have full Intellisense support inside Visual Studio, and you are ready to (iterate on) edit, build and run. Same holds true for every other class you want to use (of course the most basic ones are always accessible, such as String). Hope this helps you on the right track. :)
Luc Pattyn
-
Hello again, the Process class is defined in namespace System.Diagnostics you can verify this in the MSDN help; it shows "System.Diagnostics.Process" in the section on Inheritance Hierarchy (at the top of the manual page when using Visual Studio 2003, at the bottom when VS 2005). This means: 1) you must provide a using statement at the beginning of every source file that wants to use the Process class, like so:
using System; // always present ! using System.Diagnostics;
- you MAY have to add a reference; you dont if the Intellisense showed the right stuff while you were typing the using statement (popup list at every period with the required item in it). If it does not show, then you must add a reference (right click your project's name in the Solutions panel). For System.Diagnostics it is automatic though. Once you took care of these issues, the Process constructor, methods and other class members should have full Intellisense support inside Visual Studio, and you are ready to (iterate on) edit, build and run. Same holds true for every other class you want to use (of course the most basic ones are always accessible, such as String). Hope this helps you on the right track. :)
Luc Pattyn
OK. Now it doesn't have a problem with the Process being unidentified. But when i run the code the program has a problem with the proc.Start(); part of the code. This happens after i click the source button. It says "Win32Exception was unhandled" and then below that "Access is denied". Thanks for the help! (And what is a Win32Exception?)
-
OK. Now it doesn't have a problem with the Process being unidentified. But when i run the code the program has a problem with the proc.Start(); part of the code. This happens after i click the source button. It says "Win32Exception was unhandled" and then below that "Access is denied". Thanks for the help! (And what is a Win32Exception?)
Hi, Win32Exception is "The exception that is thrown for a Win32 error code...", see MSDN help (e.g. inside Visual Studio). It means something deep down went wrong, a HRESULT error code was generated and rather than a regular Exception with speciifc meaning, a general Win32Exception was generated (with a field containing the HRESULT value, in this case, since access violation, is will end on hex 0005). In general, it means you try to access something you are not entitled to. One possible scenario is you want to open a file that is already open somewhere, or you want to open a file you are not allowed to open at all (someone elses file, a system file, ...). I fail to see what the connection is with your Process.Start() stuff, either it launches Notepad or it doesnt. Anything from there is Notepad's matter (e.g. if file does not exist or cannot be read, it should tell you). What makes you say the problem is with Process.Start() ? Did you catch an exception and got a reference to that specific line ? or did you single-step the code just till there ? or what. If it is and you need more help, one would have to see the source code... :)
Luc Pattyn
-
Hi, Win32Exception is "The exception that is thrown for a Win32 error code...", see MSDN help (e.g. inside Visual Studio). It means something deep down went wrong, a HRESULT error code was generated and rather than a regular Exception with speciifc meaning, a general Win32Exception was generated (with a field containing the HRESULT value, in this case, since access violation, is will end on hex 0005). In general, it means you try to access something you are not entitled to. One possible scenario is you want to open a file that is already open somewhere, or you want to open a file you are not allowed to open at all (someone elses file, a system file, ...). I fail to see what the connection is with your Process.Start() stuff, either it launches Notepad or it doesnt. Anything from there is Notepad's matter (e.g. if file does not exist or cannot be read, it should tell you). What makes you say the problem is with Process.Start() ? Did you catch an exception and got a reference to that specific line ? or did you single-step the code just till there ? or what. If it is and you need more help, one would have to see the source code... :)
Luc Pattyn
ok. here is the source:
Process openSource = new Process(); openSource.StartInfo.FileName = @"C:\WINDOWS\system32\notepad.exe"; openSource.StartInfo.Arguments = webBrowsing.DocumentText; openSource.StartInfo.UseShellExecute = true; openSource.Start();
when i click the button a window pops up saying what i said about the Win32Exception and it hightlights the "openSource.Start();" part of the code. thanks for the info and help. -
ok. here is the source:
Process openSource = new Process(); openSource.StartInfo.FileName = @"C:\WINDOWS\system32\notepad.exe"; openSource.StartInfo.Arguments = webBrowsing.DocumentText; openSource.StartInfo.UseShellExecute = true; openSource.Start();
when i click the button a window pops up saying what i said about the Win32Exception and it hightlights the "openSource.Start();" part of the code. thanks for the info and help.OK, I suggest you make your program show the value and some content of webBrowsing.DocumentText right before you create the new Process(), something like:
string fileSpec=webBrowsing.DocumentText;
log("fileSpec="+fileSpec);
try {
using (StreamReader sr=File.OpenText(fileSpec)) { // file closes automatically !
// try to read and show 3 lines of the text
for (int i=0; i<3; i++) {
string s=sr.ReadLine();
log(s);
}
}
} catch (Exception exc) {
log(exc.Message);
throw; // rethrows the exception towards debugger
}
Process openSource=...in the above replace log() by whatever function can show you a string; this could be Console.WriteLine() this will tell us: - whether the file spec is a valid windows file spec - whether the file exists - whether it is really readable Good luck ! :)
Luc Pattyn