Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > Change NTFS Permissions or run shell script

Reply
Thread Tools

Change NTFS Permissions or run shell script

 
 
Shawn H. Mesiatowsky
Guest
Posts: n/a
 
      02-03-2005
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


 
Reply With Quote
 
 
 
 
Daniel Fisher\(lennybacon\)
Guest
Posts: n/a
 
      02-04-2005
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: http://www.lennybacon.com/


"Shawn H. Mesiatowsky" <smesiatowsky@spam_no_perfectfit-ind.com> wrote in
message news:%(E-Mail Removed)...
>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
>



 
Reply With Quote
 
 
 
 
Vladimir
Guest
Posts: n/a
 
      04-18-2005
' 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"

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
execute a shell script in a shell script moongeegee Perl Misc 2 12-04-2007 12:18 AM
Need better run/edit method. I have to restart the shell after every script change. Mark Python 3 01-12-2007 04:19 PM
How to change NTFS Permissions programmitcally Firas Assaad ASP General 6 04-17-2006 02:06 AM
can I run unix shell command in the ModelSim shell? clinton__bill@hotmail.com VHDL 2 02-18-2005 10:04 PM
Change NTFS Permissions or run shell script Shawn H. Mesiatowsky ASP .Net 0 02-03-2005 10:23 PM



Advertisments