|
Major_A398 wrote: I'm looking for a way in C#.NET 2.0 to not allow my application from being closed by Task Manager by doing an End Task. Was thinking about displaying an error message saying you can't close this task. Any Ideas?
On your parent form, implement a handler for the Closing event. The Closing EventArg allows you to set e.Cancel = true;
Major_A398 wrote: Also I'm looking for a way to detect certain applications are started and not allow them to start with a message box that says something like "Not aloud to run this app".
This would require unsafe code hooked into the WinAPI. Can't help you there. An alternative is to have all applications as MDI children and the controller is the MDIParent. In this scenario you can do your security handling for each child application within you.
|
|
|
|
|
I already have a Closing Event:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.Hide();
e.Cancel = true;
}
and when I do a Ctrl + Alt + Del then select the EXE and click end task it allows me to do this.
As for the alternative what you are saying is have like a control panel / menu that has all the applications and they can launch them from there? What prevents someone from just going to c:\windows\system32\notepad.exe from the start --> run, or start --> Programs doing it this way?
|
|
|
|
|
You can use ACL's to disallow users from running Task Manager to kill your application. When task manager kills a process, it KILLS the process.
Major_A398 wrote: As for the alternative what you are saying is have like a control panel / menu that has all the applications and they can launch them from there?
Well...actually you would have a controller for you application which is written as a Form and defined as an MDIParent. (Properties in the Windows.Form properties)
It would present a menu or panel that lists application (actually you can control what gets listed in the menu by rights!!!) When the application is chosen from the menu it runs inside the MDIParent as one of its' children. This is similar to running the document editor instances in Word....except you are running all of the application instances.
You would probably have to have each application implement an interface so that you can easily create an instance of each application and a consistant naming standard for the form that starts the application (like Main).
A user would switch between the applications via the Window option in the Menu or would just tile the applications and pick the one they want. This also has an added benefit in that you can easily control which applications can be run as a single instance or multiple instances.
Your application just changes by being defined as an MDIParent. And as I said in an earlier post, you would create an instance of each object, set yourself as the MDIParent, and then call the Show() method. The application is now an independant child inside your frame.
All your applications get compiled as classes instead of as Windows applications. So they exist as DLL's in your library folder which prevents anyone from randomly running whatever they want. Use an external config file or a Resource file that defines an ID for each application and the namespace:assembly for each library. Then your code for launching is something like this: (I'm writing this by memory at home so don't take it as perfect, ready-to-compile:
IApplication instance = (IApplication)Application.CreateInstance( manager.GetResource(appID) );
runList.Add(instance);
instance.MDIParent = this;
instance.Show();
Have fun with it.
|
|
|
|
|
theRealCondor wrote: You can use ACL's to disallow users from running Task Manager to kill your application. When task manager kills a process, it KILLS the process.
There has to be another way to do this, as I have seen this with some other apps where you can't end task on the exe.
theRealCondor wrote: Well...actually you would have a controller for you application which is written as a Form and defined as an MDIParent. (Properties in the Windows.Form properties)
It would present a menu or panel that lists application (actually you can control what gets listed in the menu by rights!!!) When the application is chosen from the menu it runs inside the MDIParent as one of its' children. This is similar to running the document editor instances in Word....except you are running all of the application instances.
You would probably have to have each application implement an interface so that you can easily create an instance of each application and a consistant naming standard for the form that starts the application (like Main).
A user would switch between the applications via the Window option in the Menu or would just tile the applications and pick the one they want. This also has an added benefit in that you can easily control which applications can be run as a single instance or multiple instances.
Your application just changes by being defined as an MDIParent. And as I said in an earlier post, you would create an instance of each object, set yourself as the MDIParent, and then call the Show() method. The application is now an independant child inside your frame.
All your applications get compiled as classes instead of as Windows applications. So they exist as DLL's in your library folder which prevents anyone from randomly running whatever they want. Use an external config file or a Resource file that defines an ID for each application and the namespace:assembly for each library. Then your code for launching is something like this: (I'm writing this by memory at home so don't take it as perfect, ready-to-compile:
IApplication instance = (IApplication)Application.CreateInstance( manager.GetResource(appID) ); runList.Add(instance); // make sure it does not get disposed instance.MDIParent = this; instance.Show();
Have fun with it.
This isn't what I want to do at all. If someone launches Notepad.exe from where ever, start --> run notepad.exe, start --> programs --> accessories --> notepad.exe it doesn't allow them to do this. I don't want my application calling notepad
|
|
|
|
|
MSDN gives this code as an example to create a callback function for
UdpClient.BeginReceive. It doesn't compile because the compiler does
not recognize "UdpState". I can't find any info on it either. Does
anyone know what "UdpState" is or could you point me to some sample
code on how to properly implement a ReceiveCallback function for a UdpClient? Any help would be appreciated.
public static bool messageReceived = false;
public static void ReceiveCallback(IAsyncResult ar)
{
UdpClient u = (UdpClient)((UdpState)(ar.AsyncState)).u;
IPEndPoint e = (IPEndPoint)((UdpState)(ar.AsyncState)).e;
Byte[] receiveBytes = u.EndReceive(ar, ref e);
string receiveString = Encoding.ASCII.GetString(receiveBytes);
Console.WriteLine("Received: {0}", receiveString);
messageReceived = true;
}
MSDN link:
ms-help://MS.MSDN.vAug06.en/cpref10/html/M_System_Net_Sockets_UdpClient_BeginReceive_1_2bb042b2.htm
Craig
|
|
|
|
|
It's a custom class they created for this example (unfortunetaly didn't include it) that simply encapsulates a UdpClient and IPEndpoint object so they can be passed to the callback method as state parameter of BeginReceive (becomes IAsyncResult.AsyncState in the callback).
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thanks for clearing that up. I know Microsoft has the resources to produce good documentation, too bad they don't have the talent.
Thanks again.
Craig
|
|
|
|
|
Sounds like your server code closed the connection in a call from the client that was expecting a reply.
|
|
|
|
|
I'm sure this question has been asked before, but after 2 or so minutes of searching, I figured I'd ask anyways. What's everybody's opinions on good mock object libraries. I'm currently looking in to NMock, which looks pretty good. Opinions?
Thanks.
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
I'd recommend you do a Google for mock objects. There is a product out there that does better object mocking than NMock but I do not remember the product name.
|
|
|
|
|
Thanks for the reply. I haven't actually downloaded it yet, but I've seen several references to DotNetMock. There doesn't seem to be very much documentation on it, though, thus my hesitency. NMock so far has been cool, if not strange in syntax, but does the trick.
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
Hi,
Is it possible to get the relative path of the current process ?If yes how?
Luck is Opportunity with hardwork
|
|
|
|
|
Check out
Environment.CurrentDirectory
Application.ExecutablePath
Application.StartupPath
For a detailed description of those paths see the MSDN documentation
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
what code i write to my form to make lines when i selected it and click button bold or italic the lins it begin bold or italic like what happend in word or this form i can make this line bold or ialik or underline
mostafasafy
|
|
|
|
|
Hello
Use RichTextBox class.
Regards
|
|
|
|
|
When I call the OCR Function through C# on a computer with office 2000 it gives an error message in trying to load the COM object. It seems to work fine with office 2003. Is there something special I need to do for office 2000.
|
|
|
|
|
Hello
Maybe that function is available only in 2003 or later. Did you revise the documentaion for that? And what error message do you get?
Regards
|
|
|
|
|
hi again guys, still same problem, this time i'll post my code:
(the previous thread : Link
<br />
m_prsAlgorithm = new Process();<br />
<br />
m_prsAlgorithm.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;<br />
m_prsAlgorithm.StartInfo.FileName = "Lottery.exe";<br />
m_prsAlgorithm.StartInfo.UseShellExecute = false;<br />
m_prsAlgorithm.StartInfo.RedirectStandardInput = true;<br />
m_prsAlgorithm.StartInfo.RedirectStandardOutput = true;<br />
<br />
m_prsAlgorithm.OutputDataReceived += new DataReceivedEventHandler(prsAlgorithm_OutputDataReceived);<br />
<br />
m_prsAlgorithm.Start();<br />
<br />
m_prsAlgorithm.BeginOutputReadLine();<br />
<br />
System.IO.StreamWriter swWriter = m_prsAlgorithm.StandardInput;<br />
<br />
swWriter.WriteLine(m_strArgList + " d");<br />
<br />
swWriter.Close();<br />
<br />
m_prsAlgorithm.WaitForExit();<br />
<br />
}<br />
<br />
void prsAlgorithm_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)<br />
{<br />
this.txtOutput.Text += e.Data;<br />
}<br />
the code above couses my program to freeze (just hangs), if i uncomment the code in
<br />
void prsAlgorithm_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)<br />
and comment out the:
<br />
this.txtOutput.Text += e.Data;<br />
it works but it's not thread safe and it only shows me the output when the other process has finished...
any suggestions?
Thanks in advance,
Erik.
|
|
|
|
|
prsAlgorithm_OutputDataReceived<br /> might be executing on a different thread so you need to check and Invoke the UI thread call to transfer the data.
led mike
|
|
|
|
|
hi guys, finally i have something that works:
<br />
<br />
private void RunAlgorithm()<br />
{<br />
m_prsAlgorithm = new Process();<br />
<br />
m_prsAlgorithm.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;<br />
m_prsAlgorithm.StartInfo.FileName = "Lottery.exe";<br />
m_prsAlgorithm.StartInfo.UseShellExecute = false;<br />
m_prsAlgorithm.StartInfo.RedirectStandardInput = true;<br />
m_prsAlgorithm.StartInfo.RedirectStandardOutput = true;<br />
m_prsAlgorithm.StartInfo.CreateNoWindow = true;<br />
<br />
m_prsAlgorithm.OutputDataReceived += new DataReceivedEventHandler(prsAlgorithm_OutputDataReceived);<br />
m_prsAlgorithm.Start();<br />
<br />
m_prsAlgorithm.BeginOutputReadLine();<br />
<br />
System.IO.StreamWriter swWriter = m_prsAlgorithm.StandardInput;<br />
<br />
swWriter.WriteLine(m_strArgList);<br />
<br />
swWriter.Close();<br />
<br />
m_prsAlgorithm.WaitForExit();<br />
<br />
ProcessExitedCallback pecProcessExited = new ProcessExitedCallback(OnProcessExited);<br />
<br />
m_prsAlgorithm.WaitForExit();<br />
<br />
btnRun.Invoke(pecProcessExited, new object[] { });<br />
}<br />
i've inserted this into a function and called this function in a new thread (from the main thread) and it seems to work like a charm... does anyone know why this solved the problem?
Thanks in advance,
Erik.
|
|
|
|
|
ok this almost solved the problem
The program works perfectly if the process executed runs for a short amount of time,
but if that process works a couple of minutes than it takes a pretty long time for the redirected output to show in the textbox (output in the other process is written continuously while calculating)
any suggestions?
Thanks in advance,
Erik
|
|
|
|
|
I am sorting an array of object arrays (string,int). It will work fine is the string is only one character long, but if it is two it will error. I'm not sure why or how it errors. I have done some testing, but still don't understand how to fix it. Any help is appreciated. Thanks in advance.
private object[,] SortByFirst (object[,] RevAr) {
object[,] NewAr = new object[3,2];
for (int i = 0; i < (RevAr.Length / 2); ++i) {
int NewArLoc = (RevAr.Length / 2);
--NewArLoc;
string TestStr = RevAr[i,0].ToString();
for (int j = 0; j < (RevAr.Length / 2); ++j) {
if (i != j) {
string tempStr = RevAr[j,0].ToString();
int intTest = string.Compare(TestStr, tempStr, true);
if (TestStr.Length < tempStr.Length || (intTest < 0 && tempStr != "")) {
--NewArLoc;
}
}
}
NewAr[NewArLoc,0] = RevAr[i,0];
NewAr[NewArLoc,1] = RevAr[i,1];
}
//MessageBox.Show (NewAr[0,0].ToString() + NewAr[0,1].ToString() + "\n" + NewAr[1,0].ToString() + NewAr[1,1].ToString() + "\n" + NewAr[2,0].ToString() + NewAr[2,1].ToString());
//MessageBox.Show (NewAr[2,0].ToString());
return NewAr;
}
The inital array could look like
{ {"A",0} {"C",6} {"B",12} }
This array would work, and would be returned like
{ {"A",0} {"B",12} {"C",6} }
ps. I don't know how to post code correctly still, so sorry for the way my post looks.
Tim
|
|
|
|
|
What error message do you get?
If you use framework 2.0 you could use a sorted dictionary instead:
SortedDictionary<string, int> items = new SortedDictionary<string, int>();<br />
items.Add("A", 0);<br />
items.Add("C", 6);<br />
items.Add("B", 12);
Voila. Sorted.
---
b { font-weight: normal; }
|
|
|
|
|
It doesn't really stop the code, it's just that the finished product isn't correct if the string has more than one character. I'm still on framework 1.1.
This code is use to update revision levels. So if the current revision is A, the new one is B. So if the current one is Z, the new one is AA. We show three revision levels on our drawings. Sometimes they are in the correct order, and sometimes they are not, so I'm sorting them first before I update the revisions.
So say I have revisions 'AA', 'Z', 'Y' (in order top to bottom). It will say that the new revision is 'Z' and will order them 'Z', 'Y', 'Z', in this order from top to bottom, when it should be 'AB', 'AA', 'Z'.
This is why I'm thinking something is wrong in the sorting code I posted.
Tim
|
|
|
|
|
If you want to sort them in that way, you have to first compare the length of the strings, then compare the values. If you just compare the values, "AA" comes before "Z".
---
b { font-weight: normal; }
|
|
|
|