Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Access to the Path is denied

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Freiza
Grandmaster Cheater
Reputation: 22

Joined: 28 Jun 2010
Posts: 662

PostPosted: Sat Mar 26, 2011 4:52 pm    Post subject: Access to the Path is denied Reply with quote

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string startPath = @"c:\";
            string[] oDirectories = Directory.GetDirectories(startPath, "*", SearchOption.AllDirectories);
            Console.WriteLine(oDirectories.Length.ToString());
            foreach (string oCurrent in oDirectories)
                Console.WriteLine(oCurrent);
            Console.ReadLine();

        }
    }
}


In windows 7.. it causes
Code:
Access to the path 'c:\$Recycle.Bin\S-1-5-21-327271160-3615910704-1843085597-500\' is denied.


how to solve it programmatically...
Back to top
View user's profile Send private message Send e-mail
Krähne
Expert Cheater
Reputation: 0

Joined: 06 Jun 2010
Posts: 108
Location: Inside of my Kernel

PostPosted: Sun Mar 27, 2011 3:39 am    Post subject: Reply with quote

Change the access to the $Recycle.Bin folder (or another you want/need).

I made an example:


Code:
using System;
using System.IO;
using System.Security.Principal;
using System.Security.AccessControl;

class ChangeAccess
{
    public static void Main()
    {
        string __StartPath = "C:\\$Recycle.Bin";
        string[] __Directories;
        string __UserName = string.Empty;
        FileSystemAccessRule __AllowRule, __DenyRule;
        bool __Modified = false;
        FileSecurity __FileSec;

        Console.WriteLine("Getting the current user name");

        try
        {
            __UserName = WindowsIdentity.GetCurrent().Name.ToString();
        }
        catch (System.Security.SecurityException e)
        {
            Console.WriteLine("Failed getting the current user name: {0}\nPress any key for exit", e);
            Console.Read();
        }
        finally
        {
            __DenyRule = new FileSystemAccessRule(__UserName, FileSystemRights.FullControl, AccessControlType.Deny);
            __AllowRule = new FileSystemAccessRule(__UserName, FileSystemRights.FullControl, AccessControlType.Allow);
        }

        Console.WriteLine("The current user name is: {0}\nGetting the current access control of path: {1}", __UserName, __StartPath);
        __FileSec = File.GetAccessControl(__StartPath);

        Console.WriteLine("Removing the current access rules");
        __FileSec.RemoveAccessRule(__AllowRule);
        __FileSec.RemoveAccessRule(__DenyRule);

        Console.WriteLine("Changing the current access rules");
        __FileSec.ModifyAccessRule(AccessControlModification.Set, __AllowRule, out __Modified);

        Console.WriteLine("Applying the new entries of control access to current directory");
        File.SetAccessControl(__StartPath, __FileSec);

        Console.WriteLine("Getting the current list of subdirectories in: {0}", __StartPath);
        __Directories = Directory.GetDirectories(__StartPath, "*", SearchOption.AllDirectories);

        Console.WriteLine("{0} current directories in: {1} :", __Directories.Length.ToString(), __StartPath);

        foreach (string __Current in __Directories)
            Console.WriteLine(__Current);

        Console.WriteLine("Finished!");
        Console.ReadLine();
    }
}


Modify to your needs, hope this help.

_________________
Excuse me if you don't understand what I just said, but "english" isn't my native language.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites