EFS: File.Encrypt Exception when a folder is in use

  • Thread starter Thread starter tomtown.net
  • Start date Start date
T

tomtown.net

Hello

I'm using the File.Encrypt method (.net 2.0) to encrypt files and
folders (mark for encryption) on a local disk (XP SP2, 3DES, .net 2.0).
Unfortunatelly I get an exception when trying to mark the %desktop%
folder for encryption: "The process cannot access the file because it
is being used by another process).
Is there any possibility I can close handles that use the folder?

Thanks a lot in advance

Tom

Here's what I'm trying to do (snipped from msdn to keep focus on the
actual issue)
http://msdn2.microsoft.com/en-us/library/system.io.file.encrypt.aspx

using System;
using System.IO;
using System.Security.AccessControl;

namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
try
{
string FileName = @"C:\Documents and
Settings\USER1\Desktop";
AddEncryption(FileName);
}
catch (Exception e)
{ Console.WriteLine(e); }
}

public static void AddEncryption(string FileName)
{
File.Encrypt(FileName);
}
}
}
 
The desktop folder of the current logged on user is owned by the
explorer.exe process, you can't close file handles you don't own.
What stops you from encrypting each file in %desktop% individually?

Willy.


| Hello
|
| I'm using the File.Encrypt method (.net 2.0) to encrypt files and
| folders (mark for encryption) on a local disk (XP SP2, 3DES, .net 2.0).
| Unfortunatelly I get an exception when trying to mark the %desktop%
| folder for encryption: "The process cannot access the file because it
| is being used by another process).
| Is there any possibility I can close handles that use the folder?
|
| Thanks a lot in advance
|
| Tom
|
| Here's what I'm trying to do (snipped from msdn to keep focus on the
| actual issue)
| http://msdn2.microsoft.com/en-us/library/system.io.file.encrypt.aspx
|
| using System;
| using System.IO;
| using System.Security.AccessControl;
|
| namespace FileSystemExample
| {
| class FileExample
| {
| public static void Main()
| {
| try
| {
| string FileName = @"C:\Documents and
| Settings\USER1\Desktop";
| AddEncryption(FileName);
| }
| catch (Exception e)
| { Console.WriteLine(e); }
| }
|
| public static void AddEncryption(string FileName)
| {
| File.Encrypt(FileName);
| }
| }
| }
|
 
Hello Willy

Thanks for your post. The problem by doing so is, that every new file a
user creeates on the desktop won't be encrypted. :(
Maybe I can try executing the program a little earlier in the login
process :S

Thanks again

Tom
 
| Hello Willy
|
| Thanks for your post. The problem by doing so is, that every new file a
| user creeates on the desktop won't be encrypted. :(
| Maybe I can try executing the program a little earlier in the login
| process :S
|
| Thanks again
|
| Tom
|

That's right, question is why do users create user files on the desktop in
the first place?. Anyway, you have to encrypt the folder before Explorer
starts.

Willy.
 
Hello Willy / everyone

I am now launching th eprogram using the
HKLM\SW\MS\\WNT\Winlogon\userinit Registry key, it works fine. I would
have prefered laucnhing it using the RunOnce, but the key permissions
have been restricted in my company. I can surely impersonate to write
the key, but it seems a user who has not full permissions on that key
will not be able to launch it's contents on startup.

Thanks for the inspiration

Tom
 
Back
Top