473,789 Members | 2,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting EFS using FileInfo.Attrib utes

I'm trying to unset the Encrypted attribute on all the files in a path.

The attribute is not getting set. What am I doing wrong?

Perhaps there's another newsgroup I can send this to?

Here's the code:
=============== =============== ===============
using System;

using System.Diagnost ics;

using System.IO;

namespace efsfind

{

/// <summary>

/// Searches a path, looking for EFS attribute.

/// Does not handle trailing spaces in names.

/// </summary>

class ConsoleMain

{

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main(string[] args)

{

ConsoleMain cm = new ConsoleMain();

Arguments commandLine = new Arguments(args) ;

string path = commandLine["path"];

if (null != path) {

cm.ProcessDirec tory (path);

}

}

private void ProcessDirector y(string path)

{

//Console.WriteLi ne ("{0}", path);

if (null != path && 0 < path.Length)

{

try

{

DirectoryInfo dir = new DirectoryInfo(p ath);

foreach (FileSystemInfo fileSystemInfo in
dir.GetFileSyst emInfos ())

{

if (fileSystemInfo is FileInfo)

{

FileInfo file = (FileInfo) fileSystemInfo;

FileAttributes fileAttrib = file.Attributes ;

if (FileAttributes .Encrypted ==
(FileAttributes .Encrypted & fileAttrib))

{

Console.Write ("{0}::[{1}", file.FullName,
fileAttrib);

fileAttrib = fileAttrib &
(~FileAttribute s.Encrypted);

file.Attributes = fileAttrib;

file.Refresh ();

Console.WriteLi ne (" ==> {0}]", fileAttrib);

Console.WriteLi ne ("After update: {0}",
file.Attributes );

}

}

else

{

ProcessDirector y (fileSystemInfo .FullName);

}

}

}

catch (Exception e)

{

Console.WriteLi ne (e);

}

}

}

}

}

=============== =============== ===============
Jul 21 '05 #1
4 6012
Sorry, there's a library I use that I didn't include. Therefore, these
lines:

Arguments commandLine = new Arguments(args) ;

string path = commandLine["path"];

Should be
string path = args[0];
Jul 21 '05 #2
Hi Richard,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to set encryption attributes
to the file. However, it doens't work by simply reverse the Attribute
property. If there is any misunderstandin g, please feel free to let me know.

Setting attribute in using .NET framework class libraries is really just a
thin wrapper around Win32's SetFileAttribut es API.

As far as I know, the some of the attributes cannot be set by simply
setting the property. And in fact, I don't think there's any way to set
this attribute using the .NET Framework class libraries today. I believe
you would have to go directly to the Win32 APIs in order to accomplish
this. (You can call Win32 APIs from C# code by using PInvoke).

You can find the help topic for Win32's SetFileAttribut es here:

http://msdn.microsoft.com/library/de...us/fileio/base
/setfileattribut es.asp

As mentioned in this help topic, the SetFileAttribut es API cannot be used
to set any of the following file attributes:

FILE_ATTRIBUTE_ COMPRESSED
FILE_ATTRIBUTE_ DEVICE
FILE_ATTRIBUTE_ DIRECTORY
FILE_ATTRIBUTE_ ENCRYPTED
FILE_ATTRIBUTE_ REPARSE_POINT
FILE_ATTRIBUTE_ SPARSE_FILE

These are special attributes that must be set through other means. The
document has given us a complete list of ways to set these attributes. For
example, to unset the Encrypted attribute on the file, you have to call
Decrypt API funtion.

http://msdn.microsoft.com/library/de...us/fileio/base
/decryptfile.asp

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #3
Excellent, that puts me on the right track.
Jul 21 '05 #4
You're welcome, Richard.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1878
by: Alexander Kervero | last post by:
Hi ,today i was reading diveinto python book,in chapter 5 it has a very generic module to get file information,html,mp3s ,etc. The code of the example is here : http://diveintopython.org/object_oriented_framework/index.html One thing that i have some doubs is this part : class FileInfo(UserDict): "store file metadata"
7
12262
by: John R. | last post by:
How do you set the following file attributes: Compressed Encrypted Normal ReparsePoint SparsePoint You CAN'T set these using FileInfo.Attributes or File.SetAttributes. It doesn't work for these file attributes.
2
1350
by: Samuel Shum | last post by:
Hello, I'm just wondering if there are any .Net objects that I can use in the framework that set folders/files permission, assign quotas to users. Any suggestions/comments are welcome. Thanks in advance. Samuel
5
6545
by: Lance | last post by:
I want to expose properties of a class to a user via a PropertyGrid class. Some of the properties are of type System.IO.FileInfo. Ideally, an OpenFileDialog window would appear when the user attempted to edit the value of the System.IO.FileInfo properties. Is there an existing UITypeEditor that will do this type of thing, or will I need to create my own Thanks Lance
1
1801
by: Benjamin | last post by:
I am trying to make a file I created a hidden file. I think I need to use the setfileattribute() but I cannot find it anywhere. I found this on msdn: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcedata5/html/wce50lrfsetfileattributes.asp can anyone direct me in the right direction?
4
409
by: G. Richard Bellamy | last post by:
I'm trying to unset the Encrypted attribute on all the files in a path. The attribute is not getting set. What am I doing wrong? Perhaps there's another newsgroup I can send this to? Here's the code: ============================================= using System;
2
2029
by: Greg Larsen | last post by:
I'm trying write a SQLCLR that returns FileInfo.Attributes property to SQL Server in a record set and I am getting the following error. cannot convert from 'System.IO.FileAttributes' to 'System.Data.SqlTypes.SqlInt32' How can I convert the Attributes to display an integer value. Clearly the code below doesn't work. What do I need to do to make it work? FileInfo f = new FileInfo(FileInfo);
2
8618
by: rn5a | last post by:
Using the FileSystemInfo class, I am retrieving all the directories & files existing in a particular directory on the server & listing them in a ListBox. If an item in the ListBox happens to be a directory, then the ListItem should display the directory name which will be appended with the text <DIR>. If an item in the ListBox happens to be a file, then the ListItem should display the file name which will be appended with the size of the...
5
6147
by: Tom P. | last post by:
I am having the following problem: I create a FileSystemWatcher and wait for events. When the event does happen I refresh a FileSystemInfo list and set properties accordingly (IsFile, IsDir, ReadOnly, etc.). The problem I'm having is in identifying when a FileSystemInfo entry is a FileInfo or a DirectoryInfo type. I get the rare, and yet oddly common, "setup.inf" file that for some inexplicable reason passes the standard...
0
9506
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4089
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.