|
You need to be very careful when you are using globally available mutexes running on limited OS accounts.
Maybe finding all processes with the same name like the current will be better and safer solution because doesn't require any special permissions.
Life is a stage and we are all actors!
|
|
|
|
|
Hristo Bojilov wrote: You need to be very careful when you are using globally available mutexes running on limited OS accounts
What problems are you seeing?
Best wishes,
Navaneeth
|
|
|
|
|
The method System.Threading.Mutex.OpenExisting could throw UnauthorizedAccessException for sample.Will this method work when the current account doesn't have the desired access and cannot acquire it?I've used this mutexes method for my current project but after discovering this exception is thrown to often when running on limited accounts I had removed it and used just simple scan for the running processes which queries Windows performance counter API.
Life is a stage and we are all actors!
|
|
|
|
|
Hi,
I haven't used the managed mutex class yet, however it seems to me the MutexSecurity parameter in one of the constructors should be the key to solving the problems you've had.
Anyway, relying on GetProcessesByName() does not seem right as:
1. when a user renames an EXE, the resulting process would also be getting a different name;
2. I expect the Process methods also can fail when you have insufficient rights.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
try this code.... this is for just check ur Exe application name is currently running or not
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
static extern IntPtr SetForegroundWindow(IntPtr hWnd);
private static bool AppIsAlreadyRunning()
{
Process c = Process.GetCurrentProcess();
foreach (Process p in Process.GetProcessesByName(c.ProcessName))
{
if (p.Id != c.Id)
{
if (p.MainModule.FileName.ToLower().Equals(c.MainModule.FileName.ToLower()))
{
SetForegroundWindow(p.MainWindowHandle);
return true;
}
}
}
return false;
}
|
|
|
|
|
|
thanks for your attention but the link is not refer correctly please to fix it!
|
|
|
|
|
Link works fine for me.
Google C# Single-Instance Windows Form by Sam Allen.
|
|
|
|
|
Hi,
I am trying to populate an excel sheet with some data .
I do the following to write to an excel:
StreamWriter stream = null;
string separator = " ";
string latitude = "31°49.4515437’S";
using (stream = new StreamWriter("C:\abc.xls", false))
{
StringBuilder builder = new StringBuilder();
builder.AppendLine();
builder.Append("Position");
builder.Append(separator);
builder.Append(latitude);
stream.WriteLine(builder.ToString());
}
stream.Flush();
}
When I do the above I see some junk values like 31°49.4515437’S in my excel sheet.
How do I avoid it and get to see "31°49.4515437’S" in my excel sheet.
Thanks
BV
|
|
|
|
|
You could set the encoding explicitly on the StreamWriter. Even though the default is UTF-8 on my machine, explicitly setting UTF-8 made the correct characters show up.
PS: That stream.Flush() is unnecessary because the using block has already taken care of flushing and closing the StreamWriter.
PPS: In the future, please use the "code block" button to enclose your code in <pre> tags to give it formatting and highlighting. This will make the code easier to read.
|
|
|
|
|
Hi Engelberth,
Thanks for the response,
I shall take care of PS and PPS sections.
WhenI tried the below:
using (stream = new StreamWriter("C:/abc.xls", false, Encoding.UTF8))
by doing so the formatting further detoriatted, earlier I was able to see each element in different cells in my excel sheet, By doing the above everything got clubbed in one cell, also more unknown characters got added
Initailly my separator was 'tab', but looks like after adding Encoding.UTF8 it would add the eqivalent character code forthat in excel , Also theoriginal issue still remained
Regards
BV
|
|
|
|
|
Hi,
I got the solution,
Adding it here so that if someone else needs it can use it.
We need to use Encoding.GetEncoding("Windows-1252")) and this sorts the issue.
Thnaks Engelberth as you gave me hint as to where I can dig more.
Regards
BV
|
|
|
|
|
Thanks guys i was struck was a long time on this issue Encoding.GetEncoding("Windows-1252"))
sloved my issue
|
|
|
|
|
Hello
I've got a comboBox and I want to make a query after a change in the selected item is done.
Inside the "comboBox1_SelectedIndexChanged" function, I wrote these:
string ogretisim;
ogretisim = comboBox1.Text;
SqlConnection conn = null;
conn = new Sqlconnection("Data Source = Veritabani.sdf");
conn.Open()
conn.Close();
I did not do the query yet, just to try.
In the runtime, conn.Open() gives an error like it cannot reach the server.
What can be the problem?
note:
I've tried all of these:
newSqlConnection("Data Source = baglanXXX");
newSqlConnection("Data Source = Veritabani.sdf");
newSqlConnection("Data Source = .\\Veritabani.sdf");
newSqlConnection("Data Source = VeritabaniDataSet.xsd");
newSqlConnection("baglanXXX");
("baglanXXX" is my connection string)
please someone help
|
|
|
|
|
try
new SqlConnection(@"Server = .\sqlexpress; database = YourDbName ; integrated security = sspi;");
|
|
|
|
|
How could you tell he was using sql express?
|
|
|
|
|
|
thank you for replies, I'll work on it a bit further,
thanks again =)
|
|
|
|
|
Hi, my friends.
I´m developing a control named TagListControl, quite similar to the control that allows you to assign tags to the posts in Blogger. But I´ve got a problem: the end of the list is hidden because it reaches the end of the GroupBox the control belongs. I´ve tried with BringToFront() method, but it just makes the control stand first in the Z-order of controls inside the GroupBox, not far beyond the GroupBox, as I want to.
Any help will be welcome.
Thanks in advance.
Best regards,
Fernando.
|
|
|
|
|
I'm populating a listbox using it's DataSource property in form's load event
what happens is that the selectedValueChanged event or selectedIndexChanged fires twice when starting the form
how can i prevent such behaviour
i want the event to fire only when user change listbox by mouse
there is an event straight for this(SelectionChangeCommitted), but it's availabe only on combbox control
i need to use listbox for htis.
how can i achive such behaviour
secondly:
when i first run the form, the selectedValueChanged event always fired once again selecting the firs index in the listbox
how to stop this also
i want to run the form without any event being fired unless the user change the value manually
thanks
modified on Tuesday, October 27, 2009 7:04 AM
|
|
|
|
|
Your ListBox is behaving as designed and as far as I am aware it is not possible to stop it.
However one of the many ways to cope with the problem is as follows:
1) Modify the Constructor for your Form
private bool stillInitializing = false;
public MyForm()
{
this.stillInitializing = true;
InitializeComponent();
this.stillInitializing = false;
}
2) Modify your event handler(s)
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.stillInitializing)
{
return;
}
}
Hope this helps!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
didn't work when applied on form construcor
so i tried this
private void Form1_Load(object sender, EventArgs e)
{
this.stillInitializing = true;
unitMeasureCollection.GetMulti(null);
vendorCollection.GetMulti(null);
shipMethodCollection.GetMulti(null);
purchaseOrderDetailCollection.GetMulti(null);
comboBoxUnitMeasure.DataSource = unitMeasureCollection;
comboBoxUnitMeasure.ValueMember = "UnitMeasureCode";
listBoxVendor.DataSource = vendorCollection;
listBoxVendor.DisplayMember = "Name";
listBoxVendor.ValueMember = "VendorID";
listBoxShipMethod.DataSource = shipMethodCollection;
listBoxShipMethod.DisplayMember = "Name";
listBoxShipMethod.ValueMember = "ShipMethodID";
dataGridView1.DataSource = purchaseOrderDetailCollection;
PopulateCategoriesAndSubCategories();
ClearTextBoxes();
DisableButtons();
this.stillInitializing = false;
}
and it worked just fine
thanks, Henry Minute
|
|
|
|
|
Good stuff!
It is nice to attempt to help someone with the intelligence to see the basis of your answer and apply it for their own circumstances.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
HI all....
i really need helping for socket programming ...............
|
|
|
|
|
there is a unmanage library Called WinPcap, search google, download it from http://www.winpcap.org/
then it adds some function to API that you can use them, if you don't know anything about PInvoke, use SharpPcap (Managed Code for winpcap) it is simply a DLL that you can add as reference for your application and use it(Search SourceForge.net to download it), for IP or Ethernet Packet Capturing and sending
|
|
|
|