Click here to Skip to main content
16,014,860 members
Home / Discussions / C#
   

C#

 
GeneralRe: [MOSS 2007 C# WebPart] Timer/UpdatePanel, help please... [modified] Pin
crosslink061-Aug-10 12:39
crosslink061-Aug-10 12:39 
GeneralRe: [MOSS 2007 C# WebPart] Timer/UpdatePanel, help please... Pin
Not Active1-Aug-10 16:35
mentorNot Active1-Aug-10 16:35 
GeneralRe: [MOSS 2007 C# WebPart] Timer/UpdatePanel, help please... [modified] Pin
crosslink062-Aug-10 23:45
crosslink062-Aug-10 23:45 
GeneralRe: [MOSS 2007 C# WebPart] Timer/UpdatePanel, help please... Pin
crosslink065-Aug-10 7:47
crosslink065-Aug-10 7:47 
QuestionSQL Query On DataTable Pin
cdpace30-Jul-10 4:07
cdpace30-Jul-10 4:07 
AnswerRe: SQL Query On DataTable Pin
Yusuf30-Jul-10 5:43
Yusuf30-Jul-10 5:43 
QuestionProgrammatically set the admin only permission to event viewer file in window 7 Pin
vinaykhin30-Jul-10 1:29
vinaykhin30-Jul-10 1:29 
AnswerRe: Programmatically set the admin only permission to event viewer file in window 7 Pin
vinaykhin17-Aug-10 21:59
vinaykhin17-Aug-10 21:59 
public class FilePermission
{
CreateLogFiles logfile = new CreateLogFiles();
/// <summary>
/// usernames list will store all the system user's name
/// </summary>
List<string> usernames = new List<string>();
/// <summary>
/// adminusers list will store all the admin user's name
/// </summary>
List<string> adminusers = new List<string>();
/// <summary>
/// event viewer file name with path
/// </summary>
string file_path1 = Environment.SystemDirectory + "\\eventvwr.msc";
string file_path2 = Environment.SystemDirectory + "\\en-US\\eventvwr.msc";
/// <summary>
/// FileList on which filepermission applied
/// </summary>
List<string> FileList = new List<string>();
public FilePermission()
{
try
{
if (File.Exists(file_path1))
{
FileList.Add(file_path1);
}

if (File.Exists(file_path1))
{
FileList.Add(file_path2);
}

// -- here first of all get the ownership of event viewer file.
// ownership is given to the current user
getOwnership(FileList);
// -- get the all users list and load into generic list usernames
GetALLUsersList();
// -- get the admin users list
Load_Admin_Users();
}
catch (Exception ex)
{
logfile.ErrorLog(Program.LogFile, ex.Message);
//MessageBox.Show(ex.ToString());
}

foreach (string file in FileList)
{
RemoveAccess(file);//Remove all the access one by one
}

}
/// <summary>
/// get the ownership of the specified file
/// </summary>
private void getOwnership(List<string> filenames)
{
try
{
foreach (string file in filenames)
{
ExecuteCommandSync("TAKEOWN /F " + file);
}
}
catch (Exception ex)
{
logfile.ErrorLog(Program.LogFile, ex.Message);
}
//ExecuteCommand exe = new ExecuteCommand();
//exe.ExecuteCommandSync("TAKEOWN /F " + file);
}
/// <summary>
/// get the all users list
/// </summary>
private void GetALLUsersList()
{

DirectoryEntry directoryEntry = new DirectoryEntry("WinNT://" + Environment.MachineName);
foreach (DirectoryEntry child in directoryEntry.Children)
{
if (child.SchemaClassName == "User")
{
usernames.Add(child.Name);
}

}


}
/// <summary>
/// get the admin user list
/// </summary>
private void Load_Admin_Users()
{
using (DirectoryEntry groupEntry = new DirectoryEntry("WinNT://./Administrators,group"))
{
foreach (object member in (IEnumerable)groupEntry.Invoke("Members"))
{
using (DirectoryEntry memberEntry = new DirectoryEntry(member))
{
adminusers.Add(memberEntry.Name);
//Console.WriteLine(memberEntry.Name);
}
}
}
//Console.ReadKey();
}

/// <summary>
/// set the access permission to the specified file
/// </summary>
/// <param name="FilePath"></param>
private void RemoveAccess(string FilePath)
{
try
{
FileSecurity fs = File.GetAccessControl(FilePath);


foreach (string uname in usernames)
{
// if the user have not admin rights then remove all file rights from him
if (adminusers.Contains(uname) == false)
{
try
{
fs.AddAccessRule(new FileSystemAccessRule(System.Environment.UserDomainName + "\\" + uname, FileSystemRights.FullControl, AccessControlType.Deny));
File.SetAccessControl(FilePath, fs);
}
catch (System.Security.SecurityException se)
{
logfile.ErrorLog(Program.LogFile, se.Message);
}
catch (Exception ex)
{
logfile.ErrorLog(Program.LogFile, ex.Message);
}
}
}
}
catch (Exception ex)
{
logfile.ErrorLog(Program.LogFile, ex.Message);
}
MessageBox.Show("Admininstor only permissions applied on event viewer file!", "AppliedSecurityPermission");
// @System.Environment.UserDomainName\AccountName denied from FullControl access.");

}


/// <summary>
/// Executes a shell command synchronously.
/// </summary>
/// <param name="command">string command</param>
/// <returns>string, as output of the command.</returns>
public void ExecuteCommandSync(object command)
{

try
{

// create the ProcessStartInfo using "cmd" as the program to be run, and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows, and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);

// The following commands are needed to redirect the standard output.
//This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;

procStartInfo.UseShellExecute = false;

// Do not create the black window.
procStartInfo.CreateNoWindow = true;

// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();

proc.StartInfo = procStartInfo;

proc.Start();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
// Display the command output.
Console.WriteLine(result);

}
catch (Exception objException)
{
// Log the exception
logfile.ErrorLog(Program.LogFile, objException.Message);
}
}


}
QuestionCOM server containing bulk insert impl called from Matlab Pin
devvvy29-Jul-10 23:51
devvvy29-Jul-10 23:51 
QuestionReflection to load an assembly application wide (like referencing it) Pin
hoernchenmeister29-Jul-10 23:38
hoernchenmeister29-Jul-10 23:38 
AnswerRe: Reflection to load an assembly application wide (like referencing it) Pin
PIEBALDconsult30-Jul-10 6:00
mvePIEBALDconsult30-Jul-10 6:00 
GeneralRe: Reflection to load an assembly application wide (like referencing it) Pin
hoernchenmeister1-Aug-10 20:42
hoernchenmeister1-Aug-10 20:42 
GeneralRe: Reflection to load an assembly application wide (like referencing it) Pin
PIEBALDconsult2-Aug-10 2:58
mvePIEBALDconsult2-Aug-10 2:58 
GeneralRe: Reflection to load an assembly application wide (like referencing it) Pin
hoernchenmeister2-Aug-10 3:42
hoernchenmeister2-Aug-10 3:42 
GeneralRe: Reflection to load an assembly application wide (like referencing it) Pin
PIEBALDconsult2-Aug-10 3:54
mvePIEBALDconsult2-Aug-10 3:54 
GeneralRe: Reflection to load an assembly application wide (like referencing it) Pin
hoernchenmeister2-Aug-10 4:59
hoernchenmeister2-Aug-10 4:59 
GeneralRe: Reflection to load an assembly application wide (like referencing it) Pin
PIEBALDconsult2-Aug-10 12:28
mvePIEBALDconsult2-Aug-10 12:28 
GeneralRe: Reflection to load an assembly application wide (like referencing it) Pin
hoernchenmeister2-Aug-10 20:29
hoernchenmeister2-Aug-10 20:29 
AnswerRe: Reflection to load an assembly application wide (like referencing it) Pin
Bernhard Hiller1-Aug-10 22:01
Bernhard Hiller1-Aug-10 22:01 
GeneralRe: Reflection to load an assembly application wide (like referencing it) Pin
hoernchenmeister2-Aug-10 1:20
hoernchenmeister2-Aug-10 1:20 
QuestionUpperBound of Dynamic array Pin
Enobong Adahada29-Jul-10 22:36
Enobong Adahada29-Jul-10 22:36 
AnswerRe: UpperBound of Dynamic array Pin
Sathesh Sakthivel29-Jul-10 23:35
Sathesh Sakthivel29-Jul-10 23:35 
AnswerRe: UpperBound of Dynamic array Pin
OriginalGriff29-Jul-10 23:43
mveOriginalGriff29-Jul-10 23:43 
GeneralRe: UpperBound of Dynamic array Pin
riced30-Jul-10 0:29
riced30-Jul-10 0:29 
GeneralRe: UpperBound of Dynamic array Pin
OriginalGriff30-Jul-10 0:33
mveOriginalGriff30-Jul-10 0:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.