Home » » Need Help : Windows Security

Need Help : Windows Security

Written By M.L on புதன், 10 ஆகஸ்ட், 2011 | ஆகஸ்ட் 10, 2011

I am working on Windows based application and we have requirement to create folders/files in the local drive. I am using the below code to provide permission to the specified folder.  The code is working fine in Windows XP and the same thing is not working in Windows 7 OS.

It is throwing exception  Attempted to perform an unauthorized operation for the below code.

1)

// retrieving the directory information              
DirectoryInfo directoryInfo = new DirectoryInfo(folderName);
                                
DirectorySecurity directorySecurity = directoryInfo.GetAccessControl();
                                                
// myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.ReadAndExecute, AccessControlType.Allow));

directorySecurity.AddAccessRule(new FileSystemAccessRule("Everyone",
FileSystemRights.FullControl,
InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit,
PropagationFlags.InheritOnly, AccessControlType.Allow));
                
// Set the new access settings. 
directoryInfo.SetAccessControl(directorySecurity);


If I use below code getting exception Some or all identity references could not be translated.

string User = System.Environment.MachineName + @"\Users";          
directorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.ReadAndExecute, AccessControlType.Allow));

2) Second requirement is , I need to Start/Stop the some windows services programmatically, I am getting exception Cannot open Tomcat6 service on computer '.'
    This also using the OS Windows 7.

ServiceController service = new ServiceController(serviceName);
service.Start ();

Kindly reply to me if anyone can resolve this issue

0 comments:

கருத்துரையிடுக

Popular Posts

General Category