Change NTFS Permissions or run shell script

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Change NTFS Permissions or run shell script

    I am trying to Create a web app that creates a directory, and assigns
    permissions to the directory. Is there a way to do this, or even run a shell
    comand (like cacls.exe) to alter the NTFS permissions on the directory?
    Thanks for your help

    Shawn H. Mesiatowsky


    Shawn H. Mesiatowsky Guest

  2. Similar Questions and Discussions

    1. user permissions on NTFS
      I have flash working for local and domain admins but not to anyone else.The only way I've got round to this is to make users admintrators of the...
    2. Changing NTFS permissions in ASP.NET
      Hi. Some related questions were discussed here, but my question is some different. I'm writing the project, the metter of it can be expressed...
    3. NTFS permissions
      I need to reset the NTFS permissions of a windows 2003 web server to the default installation permissions. What's the easiest way of doing this?...
    4. NTFS permissions for ASP.NET user
      I've read the following article regarding NTFS permissions and ASP.NET http://msdn.microsoft.com/library/default.asp?...
    5. PHP & NTFS Permissions
      Hello group! I'm having a problem and I hope some of you may be able to point me in the right direction. I inherited a web site using php,...
  3. #2

    Default Re: Change NTFS Permissions or run shell script

    Look at the System.IO namespace and the Directory class.

    It's not easy to set the permissions if you do not use .NET 2.0 yet. There
    is a Win32 wrapper class around gotDotNet.com you can try.

    The namespace System.Diagnostics holds a class called ProcessInfo witch can
    be used to run "calcs.exe" for example.

    --
    Daniel Fisher(lennybacon)
    MCP ASP.NET C#
    Blog: [url]http://www.lennybacon.com/[/url]


    "Shawn H. Mesiatowsky" <smesiatowsky@spam_no_perfectfit-ind.com> wrote in
    message news:%23l0tj7jCFHA.2232@TK2MSFTNGP14.phx.gbl...
    >I am trying to Create a web app that creates a directory, and assigns
    >permissions to the directory. Is there a way to do this, or even run a
    >shell comand (like cacls.exe) to alter the NTFS permissions on the
    >directory? Thanks for your help
    >
    > Shawn H. Mesiatowsky
    >

    Daniel Fisher\(lennybacon\) Guest

  4. #3

    Default RE: Change NTFS Permissions

    ' Setting NTFS permissions

    ' Creating Access Control Entry (ACE) object
    Function SetACE(AccessMask, AceFlags, AceType, objTrustee)
    Set objACE = getObject("Winmgmts:Win32_Ace").Spawninstance_
    objACE.AccessMask = AccessMask
    objACE.AceFlags = AceFlags
    objACE.AceType = AceType
    objACE.Trustee = objTrustee
    Set SetACE = objACE
    End Function

    Wscript.Echo "Script running ..."

    Set objs = GetObject("Winmgmts:").InstancesOf("Win32_AccountS ID")

    For Each obj In objs
    strValue = obj.Properties_("Element") ' object refrence
    Set objElement = GetObject("Winmgmts:"+strValue) ' getting object
    strName = objElement.Properties_("Name")
    If strName = "TinaTurner" Then ' that's it
    Exit For
    End If
    Next

    ' Getting SID
    strValue = obj.Properties_("Setting")
    Set objSid = GetObject("Winmgmts:"+strValue)
    BinaryRepresentationOfSid = objSid.Properties_("BinaryRepresentation")

    ' Group "All"
    Set objTrusteeAll = getObject("Winmgmts:Win32_Trustee").SpawnInstance_
    objTrusteeAll.SID = Array(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)

    ' User GeorgeSmith
    Set objTrusteeTT = GetObject("Winmgmts:Win32_Trustee").SpawnInstance_
    objTrusteeTT.SID = BinaryRepresentationOfSid

    ' Setting NTFS permissions ...
    Set Ace = SetACE(2032127, 3, 0, objTrusteeAll) ' full access

    Set objSecDescriptor =
    GetObject("Winmgmts:Win32_SecurityDescriptor").Spa wnInstance_
    objSecDescriptor.DACL = Array(Ace)

    ' One folder
    folderName = "C:\Data\"
    Set obj = GetObject("Winmgmts:Win32_Directory='" & folderName & "'")
    Set objClass = GetObject("Winmgmts:Win32_Directory")
    Set objInParam =
    obj.Methods_("ChangeSecurityPermissions").inParame ters.SpawnInstance_
    objInParam.Option = 4 'DACL
    objInParam.SecurityDescriptor = objSecDescriptor
    Set objOutParams = obj.ExecMethod_("ChangeSecurityPermissions", objInParam)

    Wscript.Echo folderName & " ..."
    If objOutParams.ReturnValue = 0 Then
    str = "... changed"
    Else
    str = "Error!" & vbCrLf & " ReturnValue = " & objOutParams.ReturnValue
    End if
    Wscript.Echo str

    ' Another folder
    Set Ace1 = SetACE(1179817, 3, 0, objTrusteeAll) ' read
    Set Ace2 = SetACE(2032127, 3, 0, objTrusteeTT) ' full

    Set objSecDescriptor =
    GetObject("Winmgmts:Win32_SecurityDescriptor").Spa wnInstance_
    objSecDescriptor.DACL = Array(Ace1, Ace2)

    folderName = "C:\Data\Accounting"
    Set obj = GetObject("Winmgmts:Win32_Directory='" & folderName & "'")
    Set objClass = GetObject("Winmgmts:Win32_Directory")
    Set objInParam =
    obj.Methods_("ChangeSecurityPermissions").inParame ters.SpawnInstance_
    objInParam.Option = 4 'DACL
    objInParam.SecurityDescriptor = objSecDescriptor
    Set objOutParams = obj.ExecMethod_("ChangeSecurityPermissions", objInParam)

    Wscript.Echo folderName & " ..."
    If objOutParams.ReturnValue = 0 Then
    str = "... changed"
    Else
    str = "Error!" & vbCrLf & " ReturnValue = " & objOutParams.ReturnValue
    End if
    Wscript.Echo str

    Wscript.Echo "Finish"

    Vladimir Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139