Link to home
Start Free TrialLog in
Avatar of fancyfanta
fancyfantaFlag for Türkiye

asked on

Change file attribute with c# cmd command

I want to change file attribute with cmd.exe via c#.
But when I Executed the program. It don't any changes.

Please help, where's my mistake?

string arguments = @"attrib -r -h -s C:\WINDOWS\system32\drivers\etc\hosts";
System.Diagnostics.Process.Start("cmd.exe", arguments);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jasonduan
jasonduan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fancyfanta

ASKER

Thank you @jasonduan,
and then how can I lock down the file? I mean I want to get back the ex attributes.
Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It gives error:
The name 'orgAttributes' does not exist in the current context
Sorry my mistake.
But I want to change attributes to readonly, system file and hidden
How can i?
I dont want to orginals
This is one of the best examples on the net that I
You can refer too. http://www.csharp-examples.net/file-attributes/
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial