Guest User

Untitled

a guest
Feb 11th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. try
  2. {
  3. string MyConString =
  4. "SERVER=localhost;" +
  5. "DATABASE=permdata;" +
  6. "UID=user;" +
  7. "PASSWORD=pass;";
  8.  
  9. string sql = "SELECT expDate, user, sfolder FROM permuser";
  10.  
  11. MySqlConnection connection = new MySqlConnection(MyConString);
  12. MySqlCommand cmdSel = new MySqlCommand(sql, connection);
  13. MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);
  14. MySqlDataReader dr = cmdSel.ExecuteReader();
  15.  
  16. while (dr.Read())
  17. {
  18. foreach ( *row that exp. date = today)
  19. {
  20. *get user and share path
  21. *myDirectorySecurity.RemoveAccessRule (user/share path)
  22. }
  23. }
  24.  
  25. connection.Close();
  26. connection.Dispose();
  27. }
  28.  
  29. catch (MySqlException ex)
  30. {
  31. MessageBox.Show(ex.Message);
  32. Close();
  33. }
  34.  
  35. try
  36. {
  37. string MyConString =
  38. "SERVER=localhost;" +
  39. "DATABASE=permdata;" +
  40. "UID=user;" +
  41. "PASSWORD=pass;";
  42.  
  43. DataSet dataSet = new DataSet();
  44. string sql = "SELECT key, fdate, user, perm, sfolder FROM permuser WHERE fdate=CURDATE()";
  45.  
  46. MySqlConnection connection = new MySqlConnection(MyConString);
  47. MySqlCommand cmdSel = new MySqlCommand(sql, connection);
  48. new MySqlDataAdapter(cmdSel).Fill(dataSet, "permuser");
  49.  
  50.  
  51. foreach (DataRow row in dataSet.Tables["permuser"].Rows)
  52. {
  53. string fuser = row["user"].ToString();
  54. string pathtxt = row["sfolder"].ToString();
  55.  
  56. DirectoryInfo myDirectoryInfo = new DirectoryInfo(pathtxt);
  57. DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
  58. string User = System.Environment.UserDomainName + "\" + fuser;
  59.  
  60.  
  61. myDirectorySecurity.RemoveAccessRule(new FileSystemAccessRule(User, FileSystemRights.Write | FileSystemRights.Read, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
  62. PropagationFlags.None, AccessControlType.Allow));
  63.  
  64. myDirectoryInfo.SetAccessControl(myDirectorySecurity);
  65. }
  66.  
  67. connection.Close();
  68. connection.Dispose();
  69. }
  70.  
  71.  
  72. catch (MySqlException ex)
  73. {
  74. Console.WriteLine(ex.Message);
  75. Environment.Exit(0);
  76. }
  77.  
  78. "SELECT expDate, user, sfolder FROM permuser WHERE expDate=GetDate()";
  79.  
  80. try
  81. {
  82. string MyConString =
  83. "SERVER=localhost;" +
  84. "DATABASE=permdata;" +
  85. "UID=user;" +
  86. "PASSWORD=pass;";
  87.  
  88. DataSet dataSet = new DataSet(); // Set a new DataSet instance
  89. string sql = "SELECT expDate, user, sfolder FROM permuser WHERE expDate=GetDate()"
  90.  
  91. MySqlConnection connection = new MySqlConnection(MyConString);
  92. MySqlCommand cmdSel = new MySqlCommand(sql, connection);
  93. new SqlDataAdapter(cmdSel).Fill(dataSet, "permuser"); // passing the command into the DataAdapter
  94.  
  95.  
  96. foreach (DataRow row in dataSet.Tables["permuser"].Rows)
  97. {
  98. //*get user and share path
  99. row["user"]; //User rows
  100. row["sfolder"]; //sfolder rows
  101. *myDirectorySecurity.RemoveAccessRule (user/share path)
  102. }
  103.  
  104. connection.Close();
  105. connection.Dispose();
  106. }
  107.  
  108. catch (MySqlException ex)
  109. {
  110. MessageBox.Show(ex.Message);
  111. Close();
  112. }
Add Comment
Please, Sign In to add comment