Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


BobJ
  •  BobJ
  • Paid support Topic Starter
2014-12-10T15:48:53Z
Wondering if it is possible to determine the owner of a file in VisualCron? Have a process that's watching a directory for new files. I'd like to rename the file to include the id of the individual who created the file but I haven't found a way to identify that information. Is it possible??
Sponsor
Forum information
ErikC
2014-12-11T08:41:27Z
Hi BobJ,

There is no VC way to do this, but you can do this with a .NET task:

 public static string GetCreator(string path)
 {
  return System.IO.File.GetAccessControl(path).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();     
 }

Pass a path to this method, or a variable in most cases, and the username will be returned.

Regards,
Erik
Uses Visualcron since 2006.
BobJ
  •  BobJ
  • Paid support Topic Starter
2014-12-11T13:47:32Z
Thank you! - I'll give it a try.
BobJ
  •  BobJ
  • Paid support Topic Starter
2014-12-11T20:53:58Z
Ok - I'll admit I don't do ANY VB or c# programming, but I thought I could muddle through this. I tried to paste the code in a .net code task, but it doesn't seem to recognize/format the code as the example for a .net code task shows. If I hit the compile button (or when I first try to open the task) - I get a message regarding a missing dll (the name of the dll changes each time). It wants a method, but I don't see how that can get accomplished with the error that's coming up.

"an error occurred: could not load file or assembly file 'file:///c:\documents and settings\username\local settings\temp\iwp0hknj.dll' or one of it's dependencies. The system cannot find the file specified.

Not quite sure how to proceed. Any thoughts? Thanks.
Support
2014-12-11T21:07:58Z
Only part of the code was pasted. Here is the full:

using System;

public class Test
{
 public static string GetCreator(string path)
 {
  return System.IO.File.GetAccessControl(path).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();     
 }
}

Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
BobJ
  •  BobJ
  • Paid support Topic Starter
2014-12-12T21:25:02Z
Ok thanks - yes, that works - I now can see the owner of the file in the returned string.

Now my next problem is having difficult combining functions to extract just the userid from the result. The initial result contains the domain - ie - "builtin\administrator". I just want "administrator". Since the length of the user id and the domain could vary, it seems I have to look for the position of the "\" and then either extract anything after it or remove anything through the position of "\". I just can't seem to get the syntax right when using multiple functions together. Any help for a novice??
BobJ
  •  BobJ
  • Paid support Topic Starter
2014-12-14T01:55:30Z
I was able to work out the syntax on extracting just the user id, however, now I have a new issue.

The job starts with a trigger looking for new files. A list files task to identifies new files. It then goes into a loop to run the .net task, a separate task to set up a user variable to extract just the user name and then a file rename task that attempts to create a file name that includes the identify of the individual who submitted it. It works fine when only one file is placed in the watched directory, however, if two or more files are placed in the directory, the .net task encounters an "exception in task". It appears that the .net task isn't able to execute for each item presented from the list task. Any thoughts?
BobJ
  •  BobJ
  • Paid support Topic Starter
2014-12-14T02:04:09Z
Neglected to include the information on the exception:
Exception in Task: System.Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Invalid name.
Parameter name: name
at System.Security.AccessControl.NativeObjectSecurity.CreateInternal(ResourceType resourceType, Boolean isContainer, String name, SafeHandle handle, AccessControlSections includeSections, Boolean createByName, ExceptionFromErrorCode exceptionFromErrorCode, Object exceptionContext)
at System.Security.AccessControl.FileSystemSecurity..ctor(Boolean isContainer, String name, AccessControlSections includeSections, Boolean isDirectory)
at System.Security.AccessControl.FileSecurity..ctor(String fileName, AccessControlSections includeSections)
at DynamicNS.Test.GetCreator(String path)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at OBOKIIHBDBPMCFALPGECCIFHCDJPEDKODDGK.EJNAIJCFFNMLEJKOEMCAFNHHJNOEOOPPBMNA.ANIOPLANOOOINEGKBPCHHIBGOFCEKOOLJAKP(Module[] , LangT , String , List`1 listParams, Type& ) in C:\sourcefiles\code\VisualCronService\Jobs\TaskProcesses\Reflection\clsProcessTaskDotNETExecute.vb:line 152
at OBOKIIHBDBPMCFALPGECCIFHCDJPEDKODDGK.EJNAIJCFFNMLEJKOEMCAFNHHJNOEOOPPBMNA.NGABELDFLBACDMHDDMMCGABGOJBJOHJIFAIJ(LangT , String , String , List`1 listPa
Support
2014-12-14T11:45:15Z
If you just want the username you can replace with this:

return System.IO.Path.GetFileName(System.IO.File.GetAccessControl(path).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString());

Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
BobJ
  •  BobJ
  • Paid support Topic Starter
2014-12-14T15:24:19Z
Same process - copy question. Am I correct that using the copy task will result in a change of file ownership? Is there an option to copy without changing ownership? Thank you for all your help!
Support
2014-12-15T07:20:04Z
Originally Posted by: BobJ 

Same process - copy question. Am I correct that using the copy task will result in a change of file ownership? Is there an option to copy without changing ownership? Thank you for all your help!



We do not touch ownership settings.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Scroll to Top