Notifications
Clear all

[Closed] create and share a folder with maxscript

I need to create a folder and share it on network with write permissions for our studio setup.
How to make it in maxscript with dotnet?

26 Replies

I would find out how to do it with a DOS / Windows Batch command and use DOScommand or HiddenDosCommand

Something like


fn make_and_share_folder folderPath =(

	make_folder_command="mkdir "+folderPath
	DOScommand make_folder_command

	share_folder_command="net share sharename=\""+folderPath+"\"/UNLIMITED"
	DOScommand share_folder_command
)

Thanks, Mambo. I just realized yesterday night that I should do it by cmd.

fn create_share folderPath =
(
	HiddenDosCommand ("mkdir "+folderPath)
	HiddenDosCommand ("net share " + (pathConfig.stripPathToLeaf folderPath) + "=" + "\"" + folderPath + "\"" + " /UNLIMITED")
)

create_share (sysInfo.tempdir + "test_folder")

The only thing is that I need to use ” /GRANT:Everyone,FULL”, but for users with Windows Multillingual User Interface, the word “Everyone” is translated, and I get an error.
Is there a way to get this “Everyone” word for any MUI?

I have found the solution here in C#:
Please read till the end, there

     [ http://stackoverflow.com/questions/5298905/add-everyone-privilege-to-folder-using-c-net ]( http://stackoverflow.com/questions/5298905/add-everyone-privilege-to-folder-using-c-net) 
	string path = @"C:\Users\you\Desktop\perms"; // path to directory whose settings you have already correctly configured
        	DirectorySecurity sec = Directory.GetAccessControl(path);
        	foreach (FileSystemAccessRule acr in sec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount))) 
        	{
        		Console.WriteLine("{0} | {1} | {2} | {3} | {4}", acr.IdentityReference.Value, acr.FileSystemRights, acr.InheritanceFlags, acr.PropagationFlags, acr.AccessControlType);
        	}

This gave me this line of output:

Everyone | Modify, Synchronize | ContainerInherit, ObjectInherit | None | Allow
     So the solution is simple (yet hard to get right if you don't know what to look for!):
	DirectorySecurity sec = Directory.GetAccessControl(path);
       	// Using this instead of the "Everyone" string means we work on non-English systems.
       	SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
       	sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
       	Directory.SetAccessControl(path, sec);
     This will make the checkboxes on the Windows security dialog match what you have already set for your test directory.
     
     Note that "Everyone" will not work on non-english versions of windows. Instead you should use 
System.Security.Principal.WellKnownSidType.WorldSid. 
     use FileSystemRights.FullControl instead of FileSystemRights.Modify if you want to allow all actions (ACL).
     Please, help me translate this to maxscript. I need it very much!
     
     
     
     I don't know if needed in addition to the code from above, but I found this for cmd:

[ol]
[li]Enable guest account: [/li]

net user guest /active:yes

[li]Share the folder: [/li]

net share cshare=c:\shared /GRANT:Everyone,FULL

[li]Sometimes sharing the folder doesn’t give the Everyone FULL permissions, so run the Icacls command as well: [/li]

Icacls C:\shared /grant Everyone:F /inheritance:e /T

[/ol]

Hello, World! Please help me realize this by maxscript:

$everyone = New-Object System.Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::WorldSid, $null); 
  $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $everyone, "Full", "ContainerInherit,ObjectInherit", "None", "Allow"
   
   
fn CreateSecurityOpsAssembly =
(
source  = ""
source += "using System;
"
source += "using System.IO;
"
source += "using System.Security.Principal;
"
source += "using System.Security.AccessControl;
"
source += " 
"
source += "namespace SystemSecurity
"
source += "{
"
source += "    public class AccessOps
"
source += "    {
"
source += "        public bool CreateSharedDirectory(String path)
"
source += "        {
"
source += "            if (!Directory.Exists(path))
"
source += "            {
"
source += "                DirectoryInfo info = Directory.CreateDirectory(path);
"
source += "                if (!info.Exists) return false;
"
source += "            }
"
source += "            DirectorySecurity sec = Directory.GetAccessControl(path);
"
source += "       
"
source += "            SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
"
source += "            sec.AddAccessRule(new FileSystemAccessRule(everyone, 
"
source += "                FileSystemRights.Modify | FileSystemRights.Synchronize, 
"
source += "                InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, 
"
source += "                PropagationFlags.None, AccessControlType.Allow));
"
source += "            Directory.SetAccessControl(path, sec);
"
source += "            return true;
"
source += "        }
"
source += "    }
"
source += "}
"


	csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
	compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"

	compilerParams.ReferencedAssemblies.AddRange #("system.dll", "mscorlib.dll")

	compilerParams.GenerateInMemory = on
	compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
	
	assembly = compilerResults.CompiledAssembly
	assembly.CreateInstance "SystemSecurity.AccessOps"
)
global SecurityOps = CreateSecurityOpsAssembly()

/*
SecurityOps.CreateSharedDirectory @"c:	emp\sec\"
*/

quick test tells me it works

Denis, thank you soo much.
It gives me “true” in the listener, but unfortunately, the folder doesn’t become shared

i used flags you showed above. probably it needs anything else… at least you have a stand to play with

Does your folder become shared in your Windows?

It may be a problem with unicode for the word “everyone”.

In cmd, if I write

net share cshare=c:\shared /GRANT:Everyone,FULL

with “Everyone” translated – to my Computer Local Language, then it works fine, from Maxscript there is a uncode error, I have to send it somehow translated.

Might be the same here.

Page 1 / 3