IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Partage de dossier avec tous


Sujet :

C#

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    537
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 537
    Points : 369
    Points
    369
    Par défaut Partage de dossier avec tous
    Bonjour,

    Je désire actuellement donner l'accès complet à un dossier.
    J'utilise actuellement cette méthode pour donner accès à un compte utilisateur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    DirectoryInfo aDir = new DirectoryInfo(aWay);
                if (aDir.Exists)
                {
                    DirectorySecurity aSecurity = aDir.GetAccessControl();
                    aSecurity.AddAccessRule(new FileSystemAccessRule("Un compte", FileSystemRights.ReadData, AccessControlType.Allow));
                    aDir.SetAccessControl(aSecurity);
     
                }
    Mais je ne trouve pas le moyen de partager bêtement le dossier avec tous.

    Merci.

  2. #2
    Membre confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2005
    Messages
    700
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Juin 2005
    Messages : 700
    Points : 488
    Points
    488
    Par défaut
    tu as un groupe "tous les utilisateurs" tu ne peux pas leur ajouter le droit RW?
    Peut etre qu'il faut passer par ActiveDirectory sinon, il me semble qu'il y a un tuto la dessus.

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    537
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 537
    Points : 369
    Points
    369
    Par défaut
    Je retente une demande car je me prends vraiment la tête.

    J'ai essayé aussi quelque chose comme ça:
    Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
     
    private static void ShareFolder(string FolderPath, string ShareName, string Description)
            {
                try
                {
                    ManagementClass managementClass = new ManagementClass("Win32_Share");
                    ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
                    ManagementBaseObject outParams;
     
                    inParams["Description"] = Description;
                    inParams["Name"] = ShareName;
                    inParams["Path"] = FolderPath;
                    inParams["Type"] = 0x0; 
                    outParams = managementClass.InvokeMethod("Create", inParams, null);
     
                    if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
                    {
                        throw new Exception("Unable to share directory.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "error!");
                }
            }

    Mais ça ne fonctionne pas non plus.

    J'ai essayé de voir par là:
    MSDN

    Mais pour l'instant rien de bien fructifiant.

    Quelqu'un a t'il une piste?

    Merci.

  4. #4
    Max
    Max est déconnecté
    Expert éminent sénior

    Avatar de Max
    Homme Profil pro
    Artisan développeur
    Inscrit en
    Mai 2007
    Messages
    2 954
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Artisan développeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 2 954
    Points : 14 979
    Points
    14 979
    Par défaut
    Salut.

    Essaye de modifier l'instanciation de ton ManagementClass :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ManagementClass classInstance = new ManagementClass("root\\CIMV2", "Win32_Share", null);
    Tu peux utiliser WMI Code Creator pour faire joujou avec le monde merveilleux du WMI .

  5. #5
    Membre habitué Avatar de swif79
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2009
    Messages
    79
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2009
    Messages : 79
    Points : 169
    Points
    169
    Par défaut
    Bonjour,
    Tu peux utiliser net.exe aussi

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
     
     
    public string MakeShare(string shareName,
                      string path,
                      string accessRights,
                      int? numberOfUsers = null, 
                      string cacheType = null)
    {
           string returnStr = null;
     
           try
           {
                if ((string.IsNullOrEmpty(shareName) == false) & (string.IsNullOrEmpty(path) == false))
                {
                     arguments = string.Format("share {0}={1} {2}{3}{4}",
                               shareName,
                               path,
                               (accessRights != null) ? accessRights : "",
                               (numberOfUsers == 0) ? " /UNLIMITED " : " /USERS:" + numberOfUsers.ToString(),
                               (cacheType != null) ? " /CACHE:" + cacheType : "");
     
                   returnStr = this.LaunchProcess(Environment.SystemDirectory, "net.exe",arguments);
               }
               else
                        System.Windows.MessageBox.Show("shareName and path can't be null or empty", "Parameter missing", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
     
                    return returnStr;
           }
           catch (Exception)
           {
                 return null;
           }
    }
    public string LaunchProcess(string workingDirectory, string software, string arguments)
    {
          string returnStr = null;
     
          try
          {
                Process proc = new Process();
                proc.StartInfo.WorkingDirectory = workingDirectory;
                proc.StartInfo.FileName = software;
                proc.StartInfo.Arguments = arguments;
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.CreateNoWindow = true;
                proc.Start();
                proc.WaitForExit();
                returnStr = proc.StandardOutput.ReadToEnd();
                proc.Close();
           }
           catch (Exception) { return null; }
     
           return returnStr;
    }
    où AccesRight = /GRANT:Administrateur par exemple

    Attention ne fonctionne pas si le dossier cible contient des espaces

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    537
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 537
    Points : 369
    Points
    369
    Par défaut
    Merci les gars mais toujours rien.

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    537
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 537
    Points : 369
    Points
    369
    Par défaut
    Swif ça marche.

    Faut juste penser à :
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Partage de dossier avec System comme utilisateur
    Par JFmil53_2 dans le forum Windows XP
    Réponses: 1
    Dernier message: 31/01/2011, 11h47
  2. Partage de dossiers avec Windows XP
    Par jem27 dans le forum Windows XP
    Réponses: 2
    Dernier message: 27/10/2010, 09h37
  3. Réponses: 1
    Dernier message: 14/10/2009, 15h09
  4. Réponses: 2
    Dernier message: 21/04/2008, 11h23
  5. partager un dossier avec les autres users (invité)
    Par cortex024 dans le forum Windows XP
    Réponses: 3
    Dernier message: 14/09/2006, 23h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo