Invoke Code - Passing Parameters

I have the following bit of code I am using inside an Invoke Code activity:-

Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(“\path1\path2\path3”)
Dim FolderAcl As System.Security.AccessControl.DirectorySecurity = FolderInfo.GetAccessControl()
FolderAcl.AddAccessRule(New System.Security.AccessControl.FileSystemAccessRule(“UserName”, System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.InheritanceFlags.ContainerInherit Or System.Security.AccessControl.InheritanceFlags.ObjectInherit, System.Security.AccessControl.PropagationFlags.None, System.Security.AccessControl.AccessControlType.Allow))
FolderInfo.SetAccessControl(FolderAcl)

This works with the paramaters passed directly - and in quotes - to the code.

If I try and pass the information into the code as arguments:-
Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(varDir)
Dim FolderAcl As System.Security.AccessControl.DirectorySecurity = FolderInfo.GetAccessControl()
FolderAcl.AddAccessRule(New System.Security.AccessControl.FileSystemAccessRule(varUser, System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.InheritanceFlags.ContainerInherit Or System.Security.AccessControl.InheritanceFlags.ObjectInherit, System.Security.AccessControl.PropagationFlags.None, System.Security.AccessControl.AccessControlType.Allow))
FolderInfo.SetAccessControl(FolderAcl)

it fails even if I assign the arguments in an assign statement as
varDir - “”“\path1\path2\path3"”"
varUser - “”“UserName”“”

Can anybody assist please

You don’t include quotes in the value you’re passing.

Don’t do…

varDir - “”“\path1\path2\path3"”"

Just do…

varDir = “\path1\path2\path3”

1 Like

hi @gary.cobden

Could you pls try this - use In arguments of type String in Invoke Code, assign the path using double backslashes (e.g., \path1\path2), avoid using triple or extra quotes in the Assign activity, and use the variables directly without quotes inside Invoke Code.

Happy Automation

None of that is necessary. The variable just needs to be assigned with the correct normal path and used in the code. The OP is trying to assign the value including double quotes in the value and that’s incorrect.

Yes indeed @postwick

Whenever people mention Invoke Code these days Gary, I like to make sure they know about coded workflows and coded source files.

You can now easily make a static class that has a function in it to do this and avoid the nasty, hard to debug, invoke code.

I think they are standard from version 23.10 so if you are on that or higher, I’d strongly recommend switching.


Please see screenshot. I have the Invoke Code in a Try Catch and it is not liking what is being passed as it is always jumping to the catch. Using the same account I have been able to add the permissions manually so have ruled that out.
It just seems to be not liking how the Arguments are passed