tags:

views:

3148

answers:

6

Hello.

I'd like to know how to convert this vb script to C#

Dim strFolder As String
Dim objShell As Object

strFolder = "C:\zz"

Set objShell = CreateObject("Wscript.Shell")

objShell.Run "%COMSPEC% /c Echo Y| cacls " & _
                 strFolder & _
                 " /t /c /g everyone:F ", 2, True

What I'm trying to do is set permissions to "Everyone" on a newly created folder on the users C:\ drive.

I'm using Visual Studio, .Net 1.1

Thanks. Iain

+1  A: 

This article (and link to GotDotNet source) should help you.

Pete OHanlon
A: 

Hello Pete. Thanks for this. I had already found this page, but when I try to type:

using Microsoft.Win32.Security;

I don't see Security. I thought maybe it was added in later versions of .Net?

Any other suggestions?

A: 

There's always this one on CodeProject.

Pete OHanlon
A: 

Is upgrading to a newer version not possible? .NET 2.0 introduced classes in the System.Security.AccessControl namespace to handle this. If it's really not possible and you only have this one command to execute, you may want to create a Process and just execute the cacls command in it.

tvanfosson
A: 

This is also using the "Microsoft.Win32.Security" library...

I've no SecuredObject

SecuredObject sec = new SecuredObject("C:\\", SecuredObjectType.FileObject);
+1  A: 

Hello tvanfosson. It's not possible to upgrade unfortunately - I work for a big company, so would mean updating loads of people - which would be a mission...

But - creating a process worked!

System.Diagnostics.Process meProc = System.Diagnostics.Process.Start ("cmd.exe", " /c echo y| cacls C:\\zzz /t /c /g everyone:F");

Thanks both of you for your help.