Announcement

Collapse
No announcement yet.

System.Security.Principal.IdentityReference

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • System.Security.Principal.IdentityReference

    Hallo zusammen,
    wie bekomme ich meine eigene Anmeldug heraus...?

    Ich brauche in etwa so etwas:

    Code:
    Dim MyIdentity As System.Security.Principal.IdentityReference
    Wie bekomme ich einen Wert für MyIdentity

    Kann mir da jemand witerhelfen...?

  • #2
    Hallo,

    zB
    [highlight=c#]
    using System;
    using System.Security.Principal;

    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    string userName = Environment.UserName;
    WindowsIdentity identity = WindowsIdentity.GetCurrent();
    string logonName = identity.Name;

    Console.WriteLine(userName);
    Console.WriteLine(logonName);
    Console.ReadKey();
    }
    }
    }
    [/highlight]

    mfG Gü
    "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". - Martin Fowler

    Comment


    • #3
      Hallo Gü,
      da ich im VB Code wollte ich den Code von die automatisch übersetzten...

      functioniert aber nicht...

      folgende Zeile funktioniert nicht:

      static void Main(string[] args)

      Hast du evtl. VB Code

      Danke

      Comment


      • #4
        [highlight=vbnet]
        Imports System
        Imports System.Security.Principal

        Namespace ConsoleApplication1
        Public Class Program
        Public Shared Sub Main()
        Dim userName As String = Environment.UserName
        Dim identity As WindowsIdentity = WindowsIdentity.GetCurrent()
        Dim logonName As String = identity.Name

        Console.WriteLine(userName)
        Console.WriteLine(logonName)
        Console.ReadKey()
        End Sub
        End Class
        End Namespace
        [/highlight]

        Hab ich überlesen, entschuldige

        mfG Gü
        "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". - Martin Fowler

        Comment


        • #5
          OK. Danke..

          Aber irgend etwas mache ich noch falsch.

          Was ich engendlich möchte....

          Ich möchte einen Ordner erstelle, wo der User Dateien lesen darf und Dateien erstellen darf. Aber den Ordner ansich nicht...

          ich mache dies wie folgt:

          Code:
           Dim dSecurity As System.Security.AccessControl.DirectorySecurity = dInfo.GetAccessControl()
          
                Dim userName As String = Environment.UserName
                Dim identity As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
                Dim logonName As String = identity.Name
          
           System.Security.AccessControl.FileSystemAccessRule( System.Environment.UserName, Security.AccessControl.FileSystemRights.ReadData, Security.AccessControl.AccessControlType.Deny))
                dSecurity.AddAccessRule(New System.Security.AccessControl.FileSystemAccessRule(logonName, Security.AccessControl.FileSystemRights.ReadData Or Security.AccessControl.FileSystemRights.CreateFiles, Security.AccessControl.AccessControlType.Allow))
          
                dInfo.SetAccessControl(dSecurity)
          Ich bekomme aber auf dem Rechner, das dem User die Zugriffrechte fehlen...

          Was mache ich falsch...?

          Comment


          • #6
            Ich habs mal so probiert:
            [highlight=vbnet]
            Dim di As New DirectoryInfo("MyFolder")
            If Not di.Exists Then
            di.Create()
            End If

            Dim security As DirectorySecurity = di.GetAccessControl()
            Dim logonName As String = WindowsIdentity.GetCurrent().Name
            Dim allowRule As New FileSystemAccessRule(logonName, FileSystemRights.CreateDirectories Or FileSystemRights.CreateFiles Or FileSystemRights.DeleteSubdirectoriesAndFiles Or FileSystemRights.ExecuteFile Or FileSystemRights.ListDirectory Or FileSystemRights.ReadAndExecute Or FileSystemRights.WriteData, AccessControlType.Allow)
            security.AddAccessRule(allowRule)
            di.SetAccessControl(security)
            [/highlight]

            [highlight=c#]
            DirectoryInfo di = new DirectoryInfo("MyFolder");
            if (!di.Exists)
            di.Create();
            DirectorySecurity security = di.GetAccessControl();
            string logonName = WindowsIdentity.GetCurrent().Name;
            FileSystemAccessRule allowRule = new FileSystemAccessRule(
            logonName,
            FileSystemRights.CreateDirectories |
            FileSystemRights.CreateFiles |
            FileSystemRights.DeleteSubdirectoriesAndFiles |
            FileSystemRights.ExecuteFile |
            FileSystemRights.ListDirectory |
            FileSystemRights.ReadAndExecute |
            FileSystemRights.WriteData,
            AccessControlType.Allow);
            security.AddAccessRule(allowRule);
            di.SetAccessControl(security);
            [/highlight]

            mfG Gü
            "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". - Martin Fowler

            Comment


            • #7
              Schon mal besten Dank für deine Antwort...
              Ich probiers am Montag gleich aus...


              ...ich melde mich dann ob`s funktioniert hat...

              Comment


              • #8
                OK. Nochmals Danke...


                ....hat so funktioniert....

                Comment

                Working...
                X