Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Here is the part of my code that fails:
private void button1_Click(object sender, EventArgs e)
        {
            string text1 = ".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}";

            Process.Start(("cmd /c" + ("ren " + (textBox1.Text + (" "+ (textBox2.Text + text1))))));
              Process.Start(("cmd /c" + ("attrib +s +h "+ (textBox1.Text + (".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}\\*.*" + " /S /D")))));
              Process.Start(("cmd /c" + ("attrib +s +h " + (textBox1.Text + (".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}" + " /S /D")))));

                
            //Shell(("cmd /c" + ("ren "+ (textBox1.Text + (" "+ (textBox2.Text + text1))))));
            //Shell(("cmd /c" + ("attrib +s +h " + (textBox1.Text + (".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}\\*.*" + " /S /D")))));
            //Shell(("cmd /c" + ("attrib +s +h " + (textBox1.Text + (".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}" + " /S /D")))));
        
}
Posted
Updated 19-Feb-15 19:10pm
v3

1 solution

Your first mistake is using CMD.EXE. It makes no sense at all. Do I even explain why? It does nothing. You simply pass some command to it which you can perform directly. Therefore, remove "CMD /C" and never do it again. Instead, use the call
C#
System.Windows.Process.Start("attrib", commandLine);

where commandLine is the rest of your string, the command line to "attrib".

Then, the brackets around concatenating string operands make no sense, totally superfluous. Then, there are not cases when hard-coded file names can be useful, but let's assume this is just preliminary experiments and you will later remove it.

What else. Ah, file names. You simply don't have these files. As simple as that. Reproduce all operation using CMD.EXE (for example), without your program and "/C", and then repeat it all programmatically. It should to the same.

Now, let me tell you that "attrib" operates on the file attributes which have become practically insignificant in the modern file systems. So, whatever you are doing to them may be just a waste of time. You are trying to make file hidden and system. Both attributes, optionally and routinely, can be ignored by any program, including file managers.
From the other hand, you still can use them. For example, you could temporarily mark files with some attributes in some multi-pass processing, but I would not do it either. If you explain the ultimate purpose of your activity, we can discuss possible solutions.

—SA
 
Share this answer
 
Comments
Brinda Lakhani 20-Feb-15 1:45am    
Thanks for the comment. Actually I'm stuck on this problem. I tried many things and many programs but still I can't find the solution.

I am developing a window application of screen capturing for my company use. I want capture the screen shoot and store those screen shots automatically in lock folder by programming. And after storing, i want to upload those screen shots on my company's server from that lock folder. so, I don't want to perform operations like delete, copy, paste on that folder. My problem is that, when I write Fullcontrol then I'm not able to store that screen shots in folder. So, Please tell me, how to do this? Which kind of access i have to give?

Before, this program i tried this code:

private void Permissionbtn_Click_1(object sender, EventArgs e)
{
DirectoryInfo myDirectoryInfo = new DirectoryInfo(textBox1.Text);

DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
string User = System.Environment.UserDomainName + "\\" +
comboBox1.SelectedItem.ToString();
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User,
FileSystemRights.Read , AccessControlType.Deny));

myDirectoryInfo.SetAccessControl(myDirectorySecurity);

MessageBox.Show("Permissions Altered Successfully");
}
Sergey Alexandrovich Kryukov 20-Feb-15 2:08am    
This is not a comment. This is answer. I expected you accept it formally (if everything is clear; if not, please ask what should be clarified), and then ask whatever you want, as a separate question. Why are you asking an unrelated question in comment to my answer? Please keep to the initial topic.
—SA
Brinda Lakhani 20-Feb-15 2:11am    
Sorry, Already I posted this question. But still didn't get answer. And i thought, may be you know the answer. That's why, I asked
Sergey Alexandrovich Kryukov 20-Feb-15 2:34am    
I mean, yes, this is related, but first question I answered.
As to this one: I might not understand all the detail, but I would just keep these files open with just one process. This is a sure way to block access by other process, more certain then permissions. It's not good to mess with permissions. Anyway, someone else can use elevated privileges and mess with files, or add privileges to some user...
Just keep the files open, this is the usual way...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900