コード例 #1
0
ファイル: FileExtension.cs プロジェクト: imgd/C-PushRemind
 /// <summary>
 /// 创建文件夹
 /// </summary>
 /// <param name="path">必须是物理路径</param>
 public static void CreateFile(this string path)
 {
     if (!Directory.Exists(path))//如果不存在文件夹,则创建
     {
         try
         {
             Directory.CreateDirectory(path);
             DirectorySecurity security = new DirectorySecurity(path, AccessControlSections.Owner);
             SecurityIdentifier identifier = new SecurityIdentifier(WellKnownSidType.CreatorOwnerSid, null);
             security.SetAccessRule(new FileSystemAccessRule(identifier, FileSystemRights.FullControl, AccessControlType.Allow));
         }
         catch (FileNotFoundException e) { throw e; }
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: digitalhuman/SVNDelete
        public void parseDir(String path)
        {
            foreach (String f in Directory.GetDirectories(path))
            {
                if (f.EndsWith(".svn"))
                {
                    DirectoryInfo dinfo;
                    try
                    {
                        DirectorySecurity ds = new DirectorySecurity(f, AccessControlSections.Access);
                        FileSystemAccessRule fsRule = new FileSystemAccessRule(self.Name,
                            FileSystemRights.FullControl,
                            AccessControlType.Allow);
                        ds.SetAccessRule(fsRule);

                        dinfo = new DirectoryInfo(f);
                        dinfo.Attributes = FileAttributes.Normal;
                        dinfo.SetAccessControl(ds);
                    }
                    catch (Exception err)
                    {
                    }

                    dinfo = new DirectoryInfo(f);
                    DirectorySecurity sec = dinfo.GetAccessControl();
                    sec.SetOwner(self.Owner);

                    setFileSecurity(f);

                    addListItem(f);
                    Application.DoEvents();

                    try
                    {
                        Directory.Delete(f, true);
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.Message);
                    }
                }
                else
                {
                    //addListItem(f);
                    Application.DoEvents();
                    parseDir(f);
                }
            }
        }
コード例 #3
0
ファイル: DirSecurity.cs プロジェクト: jesszgc/VideoConvert
        public static DirectorySecurity CreateDirSecurity(SecurityClass securityClass)
        {
            DirectorySecurity security = new DirectorySecurity();

            WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
            if (windowsIdentity != null)
            {
                SecurityIdentifier identity = windowsIdentity.User;
                if (identity != null)
                {
                    security.SetOwner(identity);
                    FileSystemAccessRule accessRule = new FileSystemAccessRule(identity,
                                                              FileSystemRights.FullControl,
                                                              InheritanceFlags.ObjectInherit |
                                                              InheritanceFlags.ContainerInherit,
                                                              PropagationFlags.None,
                                                              AccessControlType.Allow);
                    security.SetAccessRule(accessRule);
                }
            }

            if (securityClass == SecurityClass.Everybody)
            {
                SecurityIdentifier everybodyIdentity = new SecurityIdentifier(WellKnownSidType.WorldSid, null);

                FileSystemAccessRule accessRule = new FileSystemAccessRule(everybodyIdentity,
                                                          FileSystemRights.FullControl,
                                                          InheritanceFlags.ObjectInherit |
                                                          InheritanceFlags.ContainerInherit,
                                                          PropagationFlags.None,
                                                          AccessControlType.Allow);
                security.AddAccessRule(accessRule);
            }

            return security;
        }
コード例 #4
0
 private void WriteParametersFile(IEnumerable<string> keys)
 {
     if (!Directory.Exists(Destination()))
     {
         Directory.CreateDirectory(Destination());
     }
     var directorySecurity = new DirectorySecurity();
     directorySecurity.SetAccessRuleProtection(true, false);
     directorySecurity.SetAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null), FileSystemRights.FullControl, AccessControlType.Allow));
     Directory.SetAccessControl(Destination(), directorySecurity);
     var parameters = new Dictionary<string, string>();
     foreach (string key in keys)
     {
         var value = Context.Parameters[key];
         parameters.Add(key, value);
     }
     var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
     string jsonString = javaScriptSerializer.Serialize(parameters);
     var configFile = DestinationFilename("parameters.json");
     File.WriteAllText(configFile, jsonString);
 }
コード例 #5
0
 private static void SetDirectoryOwner(DirectorySecurity deploymentDirSecurity, Prison prison)
 {
     deploymentDirSecurity.SetOwner(new NTAccount(prison.User.Username));
     deploymentDirSecurity.SetAccessRule(
         new FileSystemAccessRule(
             prison.User.Username, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
             PropagationFlags.None, AccessControlType.Allow));
 }
コード例 #6
0
ファイル: Installer.cs プロジェクト: AlexandrM/VSExpert
        void MyInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            StringBuilder path = new StringBuilder(260);
            SHGetSpecialFolderPath(IntPtr.Zero, path, 5, false);

            string p_addinOrg = this.Context.Parameters["path"] + @"ASEExpertVS2005.AddIn";
            string p_addin2005 = path.ToString() + @"\Visual Studio 2005\Addins\ASEExpertVS2005.AddIn";
            string p_addin2008 = path.ToString() + @"\Visual Studio 2008\Addins\ASEExpertVS2005.AddIn";
            string p_addin2010 = path.ToString() + @"\Visual Studio 2010\Addins\ASEExpertVS2005.AddIn";
            string p_dll = this.Context.Parameters["path"] + "ASEExpertVS2005.dll";
            XmlDocument xd;
            XmlNode node;

            try
            {
                if (this.Context.Parameters["cboxval1"].ToString() == "1")
                {
                    if (!Directory.Exists(path.ToString() + @"\Visual Studio 2005\Addins\"))
                        Directory.CreateDirectory(path.ToString() + @"\Visual Studio 2005\Addins");

                    if (File.Exists(p_addin2005))
                        File.Delete(p_addin2005);

                    System.IO.File.Copy(p_addinOrg, p_addin2005);
                    xd = new XmlDocument();
                    xd.Load(p_addin2005);
                    node = xd["Extensibility"]["Addin"]["Assembly"];
                    node.InnerText = p_dll;
                    xd.Save(p_addin2005);
                }
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #1: " + exc.Message);
            }

            try
            {
                if (this.Context.Parameters["cboxval2"].ToString() == "1")
                {
                    if (!Directory.Exists(path.ToString() + @"\Visual Studio 2008\Addins\"))
                        Directory.CreateDirectory(path.ToString() + @"\Visual Studio 2008\Addins");

                    if (File.Exists(p_addin2008))
                        File.Delete(p_addin2008);

                    System.IO.File.Copy(p_addinOrg, p_addin2008);
                    xd = new XmlDocument();
                    xd.Load(p_addin2008);
                    node = xd["Extensibility"]["Addin"]["Assembly"];
                    node.InnerText = p_dll;
                    foreach (XmlNode item in xd["Extensibility"].ChildNodes)
                        if (item.Name == "HostApplication")
                            item["Version"].InnerText = "9.0";
                    xd.Save(p_addin2008);
                }
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #2: " + exc.Message);
            }

            try
            {
                if (this.Context.Parameters["cboxval3"].ToString() == "1")
                {
                    if (!Directory.Exists(path.ToString() + @"\Visual Studio 2010\Addins\"))
                        Directory.CreateDirectory(path.ToString() + @"\Visual Studio 2010\Addins");

                    if (File.Exists(p_addin2010))
                        File.Delete(p_addin2010);

                    System.IO.File.Copy(p_addinOrg, p_addin2010);
                    xd = new XmlDocument();
                    xd.Load(p_addin2010);
                    node = xd["Extensibility"]["Addin"]["Assembly"];
                    node.InnerText = p_dll;
                    foreach (XmlNode item in xd["Extensibility"].ChildNodes)
                        if (item.Name == "HostApplication")
                            item["Version"].InnerText = "10.0";
                    xd.Save(p_addin2010);
                }
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #3: " + exc.Message);
            }

            try
            {
                Assembly asm = Assembly.LoadFile(p_dll);

                string csp = File.ReadAllText(this.Context.Parameters["path"] + @"ASEExpertVS2005.Sample\ASEExpertVS2005.Sample.csproj", Encoding.UTF8);
                csp = csp.Replace("ASEExpertVS2005, Version=1.0.2904.23426", "ASEExpertVS2005, Version=" + asm.GetName().Version.ToString());
                csp = csp.Replace(@"<HintPath>..\ASEExpertVS2005\bin\ASEExpertVS2005.dll</HintPath>",
                    "<HintPath>" + p_dll + "</HintPath>");

                File.WriteAllText(this.Context.Parameters["path"] + @"ASEExpertVS2005.Sample\ASEExpertVS2005.Sample.csproj", csp, Encoding.UTF8);
                //<Reference Include="ASEExpertVS2005, Version=1.0.2904.23426, Culture=neutral, processorArchitecture=MSIL">
                //  <SpecificVersion>False</SpecificVersion>
                //  <HintPath>..\..\..\Program Files\ASE\ASE Expert VS2005\ASEExpertVS2005.dll</HintPath>
                //</Reference>

                DirectorySecurity ds = new DirectorySecurity();
                FileSystemAccessRule ar = new FileSystemAccessRule(
                    Environment.UserName,
                    FileSystemRights.FullControl,
                    AccessControlType.Allow);

                ds.SetAccessRule(ar);
                System.IO.Directory.CreateDirectory(this.Context.Parameters["path"] + "en-US", ds);

                FileSecurity fs = new FileSecurity();
                fs.SetAccessRule(ar);
                FileStream fsm = File.Create(this.Context.Parameters["path"] + "user.config", 1, FileOptions.None, fs);
                fsm.Close();
                StreamWriter tw = new StreamWriter(this.Context.Parameters["path"] + "user.config");
                tw.WriteLine("<ASE.Tools.XmlIni>");
                tw.WriteLine("  <Plugins>");
                tw.WriteLine("  </Plugins>");
                tw.WriteLine("</ASE.Tools.XmlIni>");
                tw.Close();
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Exception #4: " + exc.Message);
            }
        }
コード例 #7
0
 private void CreateDestination()
 {
     Directory.CreateDirectory(Destination());
     var directorySecurity = new DirectorySecurity();
     directorySecurity.SetAccessRule(fileSystemAccessRule);
     Directory.SetAccessControl(Destination(), directorySecurity);
 }
コード例 #8
0
		/// <summary>
		/// Setzt volle Zugriffsrechte für einen bestimmten Ordner für den angemeldeten Benutzer.
		/// </summary>
		/// <param name="path">Der Ordner für welchen die Zugriffsrechte geändert werden sollen.</param>
		/// <returns>Gibt 'True' zurück wenn die Zugriffsrechte erfolgreich gesetzt wurden, andernfalls 'False'</returns>
		protected bool SetDirectoryAccessControl(string path) {
			try {
				var ds = new DirectorySecurity();
				var fs_rule = new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name, FileSystemRights.FullControl,
				                                       AccessControlType.Allow);

				ds.SetAccessRule(fs_rule);

				Directory.SetAccessControl(path, ds);

				return true;
			}
			catch {
				return false;
			}
		}
コード例 #9
0
        /// <summary>
        /// Creates a directory that is fully exposed to read, write and execute by everyone
        /// </summary>
        /// <param name="dirPath">Path to directory</param>
        private void CreateExposedDirectory(string dirPath)
        {
            if (!Directory.Exists(dirPath))
            {
                try
                {
                    Directory.CreateDirectory(dirPath);
                }
                catch (Exception e)
                {
                    Log.WriteSystemEventLog("Unable to create directory during installation. Error:" + e.ToString(), EventLogEntryType.Error);
                }
            }

            DirectoryInfo dirInfo = new DirectoryInfo(dirPath);

            SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
            NTAccount acct = sid.Translate(typeof(System.Security.Principal.NTAccount)) as System.Security.Principal.NTAccount;

            FileSystemAccessRule rule = new FileSystemAccessRule(acct.ToString(), FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);
            if (!dirInfo.Exists)
            {
                DirectorySecurity security = new DirectorySecurity();
                security.SetAccessRule(rule);
                dirInfo.Create(security);
            }
            else
            {
                DirectorySecurity security = dirInfo.GetAccessControl();
                security.AddAccessRule(rule);
                dirInfo.SetAccessControl(security);
            }
        }