|
How to set security for a given folder WRITE access permissions or grant full access for all users on a computer and for NETWORK SERVICE user.
Чесноков
|
|
|
|
|
I'm no expert when it comes to this, but perhaps the technique I used in this tip[^] will help?
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
well I need to get first built-in users and NETWORK SERVICE identifiers and add some access rules for them.
how do I get them?
Чесноков
|
|
|
|
|
Chesnokov Yuriy wrote: NETWORK SERVICE identifiers
No idea I'm afraid.
Chesnokov Yuriy wrote: get built-in users
Add a reference to System.Management and add the same to your usings...
SelectQuery query = new SelectQuery("Win32_UserAccount");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject managementObject in searcher.Get())
{
Console.WriteLine("Username: {0}", managementObject["Name"]);
}
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi,
I want to remove the changes done to an image and get back the original image. the image might be modified by others and saved. If there is a single copy then how to remove the change
|
|
|
|
|
Unless you keep track of every change in some undo buffer which is somehow linked to the original then you cannot do this.
It's time for a new signature.
|
|
|
|
|
Restore from backup.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
|
i have two c# projects (ex : A and B), A is the main project and i add my B project to A, then i added a reference to A from B , now i can use the classes in B in A, but now i need to use some classes in A in side B, but i can't add reference from A to B because of circular reference , is there any way i can do this without adding that class to B project .
|
|
|
|
|
You could create a third assembly ("C") that both of the other assemblies reference but other than that, no.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
You're doing something wrong -- re-architect.
|
|
|
|
|
As John said, you would need three projects (two EXE, and one DLL referenced by both EXE).
Unless you were willing to merge all the functionality in a single EXE of course.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
|
Big mistake...
I've avoided it for decades, as Windows makes it so hard to do - at least through the eyes of a tyro. But it's time I learned it, and I sat down tonight intending to do so. I thought I'd start with drawing a simple circle on a form, and searching in Help returned a likely bit with sample code for drawing a rectangle and a circle within it, along with a button_Click handler to call the drawing function. I copied and pasted the sample code into my 800x600 form, just to try it out. Then I added a button1 object to provide the event. The code is:
public partial class FlowCalcs : Form
{
public FlowCalcs()
{
InitializeComponent();
}
private void DrawIt()
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(
100, 100, 200, 200);
graphics.DrawEllipse(System.Drawing.Pens.Black, rectangle);
graphics.DrawRectangle(System.Drawing.Pens.Red, rectangle);
}
private void button1_Click(object sender, EventArgs e)
{
DrawIt();
}
}
When I debugged it, absolutely nothing happened - no rectangle, no circle, and no errors. I would welcome an error message, since occasionally Microsoft divulges some tiny bit of information that Google can find a solution for. But no such luck this time - it executes perfectly and does nothing.
Can someone lend a clue to the clueless? I haven't any idea where to go next...
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Give this a try:
namespace WindowsFormsApplication1
{
using System;
using System.Drawing;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Width = 600;
this.Height = 700;
Graphics g = this.CreateGraphics();
Brush b = new SolidBrush(Color.Green);
g.FillEllipse(b, new Rectangle(0, 0, 500, 500));
}
}
}
Works for me. Also, I recommend WPF for graphics work. It's much nicer than Windows Forms.
|
|
|
|
|
Also, your above code worked fine for me. Make sure your form is big enough to see the drawing. And keep in mind that resizing the form causes redraws of portions of it and may cause parts of the shapes to disappear.
|
|
|
|
|
Your code is fine. However the size of the rectangle is too small. It might be possible that the circle is made below the button. My suggestion would be to increase the rectangle size.
Apart from that, there is one good habit you should start right away. Dispose the graphics object after you are done with it. This is a major source of memory leak.
|
|
|
|
|
Som Shekhar wrote: Dispose the graphics object after you are done with it. This is a major source of memory leak.
I've never heard that. Why would the Graphics object be a source for a memory leak?
|
|
|
|
|
aspdotnetdev wrote: Why would the Graphics object be a source for a memory leak?
Because it's using unmanaged resources (GDI+).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
This gets a little complex, but: The Graphics object is a limited resource, which contains unmanaged memory. What that means is that it uses memory which is not on the normal C# heap, or the stack - it is in a different area completely, and the .NET garbage collector will not process it. When your method ends, the last reference to the object is destroyed, so it becomes available to be garbage collected - which is fine. But, the GC will only try to dispose of it when it runs short of managed memory - which could be in a few weeks time, you just don't know! In the meantime, all that unused, unmanaged memory is sitting there, being wasted.
If you manually call Dispose() on your object when you are finished with it, the resources are released immediately, and all is well.
The easiest way to do this is to wrap you object in a using block:
using(Graphics g = CreateGraphics())
{
... use the Graphics object
} The system will then call Dispose at the end.
I probably haven't explained this too well, but if you look in any reasonable book on C#, it will talk about it in loads more detail!
BTW: I wouldn't do the drawing in the Button.Click event - do it in the Form.Paint event - which supplies you with a graphics context in e.Graphics - and use the Button.Click to set any parameters (such as where you want it, what color, etc.) then call Invalidate() to force a re-draw.
I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in.
Apathy Error: Don't bother striking any key.
|
|
|
|
|
Wise men have already spoken. So, no need to answer the question asked about disposing.
Your suggestion is right about doing the paint part in Form.Paint event. However, I don't see anything wrong in doing it in Button_Click for learning purposes. Doing all drawing during paint may become an herculean task.
I prefer doing my drawing on a bitmap at different occasions and draw the bitmap during Form.Paint. This imitates double buffering and saves from doing any calculations that may be required in Form.Paint every time the form is painted.
|
|
|
|
|
While Pete had explained that dispose should be used, he hadn't explained why, or how to best do it. I felt it worth a (slightly) more detailed response.
The only problem with drawing in the Click event for learning purposes is that it can confuse more than elucidate - look at the number of "I drew it and it disappeared" questions we get. Starting off with drawing into the Paint event, with an existing Graphics context just makes it a bit easier for beginners. They can them be introduced to the concept of graphics contexts for other objects.
I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in.
Apathy Error: Don't bother striking any key.
|
|
|
|
|
Hey, lemme say sorry for not writing in the correct grammar. What i said was:
Som wrote: Wise men have already spoken. So, no need to answer the question asked about disposing.
and what i meant
Wise men have already spoken. So, I do not need to answer the question asked about disposing.
he he he. I was talking about both of you.
I do not deny that writing in Paint event is incorrect. I am only saying that it is not necessary and shouldn't be considered as a norm. Thats all.
By the way, our so long discussion might be confusing the poor guy who wrote the code for the first time
|
|
|
|
|
He wasn't talking about me. He said wise. Good explanation though and you might want to consider posting it as a tip/trick so that it can be easily linked to in response to other questions.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Som Shekhar wrote: I don't see anything wrong in doing it in Button_Click for learning purposes
For the most part yes, but many beginners get the idea that that is a "best practice" and never progress -- much like all the books that show data access in click handlers.
|
|
|
|