Link to home
Start Free TrialLog in
Avatar of davidlars99
davidlars99Flag for United States of America

asked on

Modify File Permissions in VB.NET

I'm trying to modify folder's security options and it doesn't work, it works only thru the command prompt with this parameters

cacls.exe c:\dave /t /P ASPNET:f

does anybody have any idea what I am doing wrong...?



Imports System
Imports System.Collections

Public Class FileSecurity

    Public Shared Function SetSecurity() As String
        Dim _cmdLine As String = "c:\dave /t /P ASPNET:F"
        Try
            Dim p As System.Diagnostics.Process = New System.Diagnostics.Process
            p.StartInfo.FileName = "cacls.exe"
            p.StartInfo.Arguments = _cmdLine
            p.StartInfo.RedirectStandardOutput = True
            p.StartInfo.UseShellExecute = False
            p.StartInfo.WindowStyle = Diagnostics.ProcessWindowStyle.Minimized
            p.StartInfo.CreateNoWindow = True
            p.Start()
            'Return p.StandardOutput.ReadToEnd.ToString
        Catch ex As Exception
            Return ex.Message
        End Try
    End Function

End Class
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of davidlars99

ASKER

no it doesn't make any difference because it's not working either way...  :)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
no, I'm not getting any error, the page just won't finish loading... if I comment out this line "psi.Arguments = _cmdLine" then I just get same output as you would get from the orginal command prompt window, I have no idea what I'm doing wrong, I am logged in as Admin and ASPNET account belongs to Admin group...  frantik...  :)
I forgot to mention that I doing this from web app
I'm going to delete this question unless nobody minds...   :)
Please remember to delete this question.

Bob "Cleanup Volunteer"
if anyone is interested I just found the way...  :)


    Public Shared Function Extractor(ByVal path As String) As String
        Dim p As System.Diagnostics.Process = New System.Diagnostics.Process
        Try
            p.StartInfo.FileName = "CACLS"
            p.StartInfo.Arguments = "C:\Inetpub\wwwroot\asp.net\mcad\statemanagement /E /P DAVE\IUSR_DAVE:F"
            p.StartInfo.RedirectStandardInput = True
            p.StartInfo.RedirectStandardOutput = True
            p.StartInfo.UseShellExecute = False
            p.StartInfo.WindowStyle = Diagnostics.ProcessWindowStyle.Hidden

            p.Start()
            p.WaitForExit(1000)

            Return p.StandardOutput.ReadToEnd.ToString
        Catch ex As Exception
            Return ex.Message
        Finally
            If Not p Is Nothing Then
                p.Dispose()
                p = Nothing
            End If
        End Try
    End Function