|
|
Troops,
I've read several messages in several places and what seems to be a simple task is not giving me much love. I'm simply trying to launch the default mail client in C#. I've tried the following:
string mailToAddress = "mailto:joe.mama@exception.net";
System.Diagnostics.Process.Start( mailToAddress );
and also...
string mailToAddress = "mailto:joe.mama@exception.net";
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = mailToAddress;
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.Start();
Both give me the following rash (exception):
The requested lookup key was not found in any active activation context
* We're using version 1.1 of the Framework.
* We have a Help, About form that has a 'Customer Service' label on it. When the user clicks it we want to open the default mail client with the 'To' address filled-in. From that 'About' form is where we are trying to run the above code.
* I read an article that claimed switching the UseShellExecute to false would help. It got rid of that exeception and gave me a 'file not found' in it's place.
I've read articles about 'how easy this is' and other articles claiming a threading problem. It seems like it should be a simple thing to accomplish.
Any help is greatly appreciated. We're all counting on you.... Good luck.
Stretch
|
|
|
|
|
Hello Stretch,
I tested out the code you put in your question text: the second version, where you actually create a Process object, and it worked out fine: Thunderbird (my default email client) opened up without a problem, with a new mail addressed to joe.mama@exception.net.
This probably means that the issue you are having is caused by not having a default email client set, or not having one setup properly. The proper handler for the "mailto" keyword is actually defined in the Windows Registry. If you go to Start > Run and then type "regedit" you will be able to view the registry. Open up to "HKEY_LOCAL_MACHINE" and then go to the following path under there "SOFTWARE" > "Clients" > "Mail". Now you should have that registry key open (i.e. selected in the left pane). When that key is selected in the left pane, then in the right pane, you will see a value whose name is "(Default)" and whose value is your default mail client. Mine says "Mozilla Thunderbird". You may not have this set, which could be causing the problem. If it IS set, then continue reading!
Just a phrase like "Mozilla Thunderbird" is not enough to tell Windows what to do if it encounters the "mailto" keyword. Let's look a little deeper into the registry! Open up the key called "Mail" in the left pane and find the sub-key with the same name as the value of the "(Default)" key which you just found. For me, I have a key called "Mozilla Thunderbird". Alright, open that one up. You will probably see a variety of other keys, but the one we are interested in is "protocols" (it does not matter if it is capitalized or not). If you do not have that key, then that should explain your problem - Windows does not know what to do with the "mailto" protocol on your client. If you do have that key, keep reading!
Open up the "protcols" key and under it you should see "mailto". This is the key which will tell Windows how to deal with a mailto command. Open up that key as well, and you should get to a key called "shell". Under "shell" there should be a key called "open" and under that a key called "command". Select "command" in the left pane, and look at the various values in the right pane. There is probably only one listed, another "(Default)" value. Mine has this as the associated data: "C:\PROGRA~1\MOZILL~2\THUNDE~1.EXE -compose %1". This is the command which Windows executes whenever it sees "mailto".
I will quickly recap and you can then try and identify where your problem lies:
1) Inside the key "Clients" > "Mail" You should have the "(Default)" value set to a mail client on your machine.
2) There should be another key with that mail-client's name underneath the "Mail" key.
3) Inside that key, there should be the following set of keys: "protocols" > "mailto" > "shell" > "open" > "command"
4) The value called "(Default)" in the "command" key should be set to a valid executable with some command line parameters, like "-compose".
At each of these four places, you could have an invalid registry key or missing value. Check that and see if it is all in place. Reply to this message with the results of your finding, and then I will try to help you fix it.
Hope that helps start you out in the right direction!
Sincerely,
Alexander Wiseman
|
|
|
|
|
Hi Alexander,
Thanks for the thorough research. I should have mentioned that running "mailto:user@yahoo.com" (or similar) works from the Start, Run box. Outlook opens with the To: info filled in.
I checked all your points above just for kicks and I have data in all places. I'm using Outlook 2003 and the last entry had some cryptic parameters:
"C:\PROGRA~1\MICROS~2\OFFICE11\OUTLOOK.EXE" -c IPM.Note /m "%1"
Other than that, I think the rest is ok and like I said, it works from the Start, Run box... which is why this is driving me nuts.
I'll make a smaller test app and try it from there and let you know what I find. We've had some strange things happen with threading.. depending on where we spawn threads in the code. Our application is pretty complex and I'll try to step back and use small test app. We've heard some strange things with regard to threading in version 1.1 of the Framework.
I'll let you know what I found...
Thanks!
Stretch
|
|
|
|
|
Alrighty then!... I just did a quick tester application and used the same code I'm having problems with in our company's app. Works just peachy. As I mentioned, our company app is pretty complex and one thing we had to do was switch from STAThread to MTAThread to accommodate a legacy system in Europe on Windows 98 (gag). Anyways, I tried switching STA to MTA in the tester app and bingo... same exception.
We 'should' not need to support that legacy system in Win 98 and I'm looking into that... but does anyone know why I have this issue using MTAThread and this type of Process that I'm running?
Thanks,
Stretch
|
|
|
|
|
Stretch,
Thanks for your reply. This is a very interesting issue, to say the least! I do not know enough about the Multi-Threaded Apartment state to say for sure what is going on, but I'm guessing, by the error message, that it has something to do with not being able to access part of the registry, or accessing the wrong part of the registry when in a multi-threaded aparatment model. I need to do a few more searches for information about this; I hope it is documented somewhere.
In the meantime, if you want a quick and dirty workaround, you can run cmd.exe and execute the command that way. Since the Command Line Interpreter won't understand the "mailto" keyword, you have to use the "start" command to have it execute properly. This is the code I tried in a test application with the MTAThread attribute set, and it worked fine:
string mailToAddress = "mailto:joe.mama@exception.net";
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.Arguments = "/C start " + mailToAddress;
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
myProcess.Start(); Like I said, it's a little bit ungainly, but it does work. If I think of anything else, I'll let you know.
Sincerely,
Alexander Wiseman
|
|
|
|
|
I wish to transfer a session state from one page to another. Is there a simple way to transfer the state without storing it and then taking it back out in some complex almost useless way?
Thanks for all the help!
|
|
|
|
|
i want to start programming neural nets using c#.
plz help me
|
|
|
|
|
|
|
|
I am new to C# and .Net. I am trying to execute a bat file from inside a C# application. I continue to get a security error and no one here can help me out. Any ideas?
Thanks in advance.
|
|
|
|
|
ProcessStartInfo pi = new System.Diagnostics.ProcessStartInfo(@"batchfile.bat", @"arguments here");
pi.UseShellExecute = true;
Process.Start(pi); Difficult, me thinks not, of couse Security Error is probably something to do with the permissions set up on your computer and I can't help you with that since I'm the Administrator on mine.
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
|
|
|
|
|
using Microsoft.Win32;<br />
<br />
...<br />
<br />
string fileName = "c:\\MYBATFILE.BAT";<br />
string args = "YOUR ARGUMENTS GO HERE";<br />
System.Diagnostics.Process proc = new System.Diagnostics.Process();<br />
proc.EnableRaisingEvents=true;<br />
proc.StartInfo.FileName=fileName;<br />
proc.StartInfo.Arguments=args;<br />
proc.Start();<br />
proc.WaitForExit();<br />
proc.Close();
|
|
|
|
|
Make sure that the bat file has permission for "Everyone"
|
|
|
|
|
This is the error message from DOS.
"
The action that failed was:
LinkDemand
The type of first permission that failed was:
System.Security.PermissionSet
The demand was for:
<permissionset class="System.Security.PermissionSet"
version="1"
Unrestricted="true"/">"
There was more if I need to send it..
thanks in advance
|
|
|
|
|
The below is the entire error...
Thanks and I truely appreciate any help.
Unhandled Exception: System.Security.SecurityException: Request failed.
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly a
sm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, Secur
ityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object ass
emblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle
rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet gran
ts, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Objec
t assemblyOrString, SecurityAction action, Boolean throwException)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs
, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMet
hodHandle rmh, Assembly asm, SecurityAction action)
at ConsoleApplication_uisftp.HelloWorld.Main()
The action that failed was:
LinkDemand
The type of the first permission that failed was:
System.Security.PermissionSet
The demand was for:
<permissionset class="System.Security.PermissionSet"
version="1"
unrestricted="true">
The granted set of the failing assembly was:
<permissionset class="System.Security.PermissionSet"
version="1">
<ipermission class="System.Security.Permissions.EnvironmentPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
read="USERNAME">
<ipermission class="System.Security.Permissions.FileDialogPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
unrestricted="true">
<ipermission class="System.Security.Permissions.FileIOPermission, mscorlib, Vers
ion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
read="R:\C#2\ConsoleApplication uisftp\ConsoleApplication uisftp\bin\Debug\"
pathdiscovery="R:\C#2\ConsoleApplication uisftp\ConsoleApplication uisftp\bin\De
bug\">
<ipermission class="System.Security.Permissions.IsolatedStorageFilePermission, m
scorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
allowed="AssemblyIsolationByUser"
userquota="9223372036854775807"
expiry="9223372036854775807"
permanent="True">
<ipermission class="System.Security.Permissions.ReflectionPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
flags="ReflectionEmit">
<ipermission class="System.Security.Permissions.SecurityPermission, mscorlib, Ve
rsion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
flags="Assertion, Execution, BindingRedirects">
<ipermission class="System.Security.Permissions.UIPermission, mscorlib, Version=
2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
unrestricted="true">
<ipermission class="System.Security.Permissions.UrlIdentityPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
url="file:///R:/C#2/ConsoleApplication uisftp/ConsoleApplication uisftp/bin/Debu
g/ConsoleApplication uisftp.exe">
<ipermission class="System.Security.Permissions.ZoneIdentityPermission, mscorlib
, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
zone="Intranet">
<ipermission class="System.Net.DnsPermission, System, Version=2.0.0.0, Culture=n
eutral, PublicKeyToken=b77a5c561934e089"
version="1"
unrestricted="true">
<ipermission class="System.Drawing.Printing.PrintingPermission, System.Drawing,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
version="1"
level="DefaultPrinting">
The assembly or AppDomain that failed was:
ConsoleApplication uisftp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The Zone of the assembly that failed was:
Intranet
The Url of the assembly that failed was:
file:///R:/C#2/ConsoleApplication uisftp/ConsoleApplication uisftp/bin/Debug/Con
soleApplication uisftp.exe
Press any key to continue . . .
|
|
|
|
|
are you programming in a limited xp account? is so then dont.
or is this running in a secure NT network? if so... what kind of premissions do you have and what external(things other than your computer) resources are you trying to reach.
|
|
|
|
|
I have an issue with stopping threads in a windows service application I was wondering if anyone can help. let me set it up for you. In a windows service you have to use the OnStart method to initialize your application... but you cannot run any loops or sequence of events that contain loops or the state of the application will be in an "starting" service mode indefinitely. So I start a thread call Maint to handle the application. The application has threee main functions at the moment that interface with WAN file shares and a sql db. I run these parallel each in there own thread(and they dont interact with eachother). so in the OnStart method:
maint Maint = new maint();<br />
maintThread = new Thread(new ThreadStart(Maint.start));<br />
maintThread.Start();
in that start method i call:
importassets ia = new importassets();<br />
importThread = new Thread(new ThreadStart(ia.importasset));<br />
importThread.Start();<br />
<br />
updatereg ur = new updatereg();<br />
updateThread = new Thread(new ThreadStart(ur.runupdate));<br />
updateThread.Start();<br />
<br />
forcelogins fl = new forcelogins();<br />
loginThread = new Thread(new ThreadStart(fl.runlogins));<br />
loginThread.Start();<br />
<br />
int startTime = System.Environment.TickCount; <br />
int runTime = startTime+3600000;<br />
while(true)<br />
{<br />
int nowTime = System.Environment.TickCount;<br />
FAISservice fs = new FAISservice();<br />
if(!fs.isRunning)<br />
break;<br />
if(runTime < nowTime)<br />
{<br />
importThread.Abort();<br />
Thread.Sleep(3000);<br />
startImport();<br />
runTime = nowTime+3600000;<br />
}<br />
Thread.Sleep(10000);<br />
<br />
}
Now, all works fine until the OnStop() method gets called by the service being stopped or restarted. in the OnStop() method i run:
isRunning = false;<br />
<br />
maintThread.Abort();<br />
<br />
maint Maint = new maint();<br />
Maint.stop();
and in the stop() method i call:
importThread.Abort();<br />
updateThread.Abort();<br />
loginThread.Abort();
Now I'm locked in a "STOPPING" state and i have to kill the process... any clues? also... my above 3 threads start while(true) loops that only BREAK when isRunning=false.
|
|
|
|
|
We have a similar situation, and basically, in our thread classes, we have created a Shutdown() method.
The threads themselves this method at different points in their loops (where it is practical for them to gracefully stop), and simply shut themselves down when this method returns true. The threads do not stop immediately, like from a Thread.Abort(), but this way they are given a chance to terminate gracefully.
In the thread proc, the method is coded as so:
public class SomeThread
{
// This variable is used by multiple threads, so it must be thread-safe.
// Do not access it directly -- use the ShutDown property instead.
private bool m_bTimeToShutdown = false;
private Object ShutDownLock = new Object();
// Other variables and methods go here......
/// <summary>
/// This property can be set to tell the main loop to stop processing.
/// The main loop continues to run as long as this property is false.
/// </summary>
public bool ShutDown {
get {
bool rslt;
lock (ShutDownLock) {
rslt = m_bTimeToShutdown;
}
return rslt;
}
set {
lock (ShutDownLock) {
m_bTimeToShutdown = value;
}
}
}
}
Calling example (in the Main service):
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
log.Info("Shutting down some thread"); // This is just a sample logging call.
SomeThreadThrdProc.ShutDown = true;
}
I hope this helps you.
Tom Delany
|
|
|
|
|
Greetings,
I have the need to place an arraylist into a pageddataset that fills a repeater. The command buttons and total number of pages is all there, however, the pagelimit is not working. I have resolved the data source to iEnumerable, to no avail.
Can anyone assist? Here is the code...Thanks!!!
override
protected void OnLoad(EventArgs e)
{
EnsureChildControls();
// Populate the repeater control with the Items DataSet
PagedDataSource objPds = new PagedDataSource();
objPds.PageSize = 10;
objPds.AllowPaging = true;
objPds.CurrentPageIndex = CurrentPage - 1;
if (Confirm && PledgeID != -1)
{
objPds.DataSource = (IEnumerable) ResolveDataSource(array list );
}
else
{
//objPds.DataSource = PledgeUtility.GetAllPledges(ModerationStatus.Pending);
objPds.DataSource = (IEnumerable) ResolveDataSource(array list));
}
// Set the PagedDataSource's current page
lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of "
+ objPds.PageCount.ToString();
// Disable Prev or Next buttons if necessary
cmdPrev.Enabled = !objPds.IsFirstPage;
cmdNext.Enabled = !objPds.IsLastPage;
rptPledgeList.DataSource = objPds.DataSource;
rptPledgeList.DataBind();
pnlNoPledges.Visible = (rptPledgeList.Items.Count == 0);
}
// *****************************************************************
// *****************************************************************
// Resolve the data source and normalize it to IEnumerable
private IEnumerable ResolveDataSource(object dataSource)
{
IListSource listSource;
IList list;
if (dataSource == null)
return null;
listSource = (dataSource
as IListSource);
if (listSource != null)
{
list = listSource.GetList();
return list;
}
if ((dataSource as IEnumerable) != null)
return (IEnumerable) dataSource;
return null;
}
// *****************************************************************
|
|
|
|
|
i want to start programming neural nets using c#???
adsf e ed w we we w
|
|
|
|
|
Are you sure?
If so, search this site and you will find some articles about neural networks in C#. Some recently added articles were very good.
Josh
|
|
|
|
|
I suppose this might be appropriate in the web development forum too, but this seemed better.
In trying out this[^], I notice it works fine in .NET 1.1, but the text never gets set when I click on Change Text when the dll is compiled in .NET 2.0.
Someone else[^] had a similar problem with an article here on CP.
Any ideas?
Marc
Pensieve
Some people believe what the bible says. Literally. At least [with Wikipedia] you have the chance to correct the wiki -- Jörgen Sigvardsson
|
|
|
|
|
Never mind, found the answer. You have to make the assembly COM visible.
Marc
Pensieve
Some people believe what the bible says. Literally. At least [with Wikipedia] you have the chance to correct the wiki -- Jörgen Sigvardsson
|
|
|
|
|