logo WinWrap®

File Access Control

WinWrap® Basic is an embedded macro language component available for .NET and COM 32/64 bit Windows applications. The WinWrap® Basic Component is an alternative to Visual Basic for Applications (VBA), ActiveX (e.g. VBScript, JScript, PerlScript, Rexx-based WSH engines and others), and VSTA for this purpose. The WinWrap® Basic Component is compatible with VBA, Sax Basic, VB.NET and Visual Basic 6.0 style scripts.

File Access Control for Scripts

  • Restrict file access.
  • Adjust file names by action.
  • Adjust file names by context.

File Access Control

WinWrap Basic Scripting File Access Control

Reading and writing files is a convenient feature, however, there are times when accessing the local file system in not desirable. In that case your application can redefine how scripts access files. Different user's running the same script can access files specific to the user without modifying the script.

Implement the IFileAccessControl

The following implementation of IFileAccessControl treats file names as simple names. Simple names are translated into full path names in the script's directory. This is a useful approach for restricting file access within the actual file system.

public class MyAccessControl : WinWrap.Basic.IAccessControl { public string Allow(string action, string baseName, ref string name) { if (name.Contains("\\") || name.Contains(":")) throw new Exception($"Access to '{name}' is not allowed."); if (name[0] == '*' || name[0] == '?') throw new Exception($"Access from '{baseName}' is not allowed."); // get the directory name containing the script var root = Path.GetDirectoryName(baseName); // adjust name so that it is in the same directory as the script name = root + "\\" + name; } }

Allowed access can be customized based on the type of access action requested by the script.

Action WWB-COM WWB.NET
Copy:From FileCopy FileCopy
Copy:To FileCopy FileCopy
CreateDirectory MkDir MkDir
Delete Kill Kill
DeleteDirectory RmDir RmDir
FileDateTime FileDateTime FileDateTime
GetAttr GetAttr GetAttr
GetDirectory Dir Dir
Open:Read Open FileOpen
Open:ReadWrite Open FileOpen
Open:Write Open FileOpen
Rename:From Name Rename
Rename:To Name Rename
SetAttr SetAttr SetAttr

Refer to IFileAccessControl.Allow for more information.