DBWServer: Protected Script

<< Click to Display Table of Contents >>

Navigation:  Advanced Features > DBWServer (obsolete) >

DBWServer: Protected Script

MechWorks DBWServer

Protected Script

Starting from R13 sp2.0 it is possible to run VBS scripts impersonating the DBWServer login personality.

This feature may be useful when a management of File Server features may be required (for example, querying the File Server for who is locking particular files)

This new feature is based on an API available starting from DBWServer ver.13.2:

ExecuteScript(UNC_file_path_name, User_ID, Group_ID, UNC_script_path_name)

The input parameters:

UNC_file_path_name

User_ID

Group_ID

will be passed as 'const' parameters to the UNC_script_path_name script that will be executed.

The UNC_script_path_name can not show any User Interface, so all the VBS function that expose a UI can't be used (for example the MsgBox can't be used, since it would HANG the Service execution)

Example

This example supposes that a protected script will be invoked by a user script, and that the protected script will create a file output in a fixed folder ( C:\TEMP ) - this output will be read by the user script and displayed to the end user

User side script (testScript.vbs)

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Set fs = CreateObject("Scripting.FileSystemObject")
fs.DeleteFile( "C:\TEMP\myProtectedScript.out" )
Set api = CreateObject("DBWServer.DBWServerApi")
version = api.GetVersion()
If version >= 13.2 Then
 ok = api.ExecuteScript("\\myserver\myshare\test.sldprt","CIRO","DBWorks
 Trainee","\\CIRO_DELL3\c\Program Files (x86)\DBWorks\LST\testProtectedScript.vbs")
 If ok then
  Dim msg
  Set a = fs.OpenTextFile( "C:\TEMP\myProtectedScript.out" , ForReading, True )
  Do While a.AtEndOfStream <> True
   line = a.ReadLine
   if line <> "" Then
    msg = msg & line
   end if
  Loop
  a.Close
  MsgBox msg 'Here it is use any UI function
 End if
End If

DBWServer Protected Script (testProtectedScript.vbs)

'' DBWorks R13 sp2.0

' DBWServer Protected Script example
' the script can access the following constants:
' const UNCFilePathName
' const UserID
' const GroupID
'
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Call main
Sub main()
 inputParameters = _
 "UNCFilePathName = " & UNCFilePathName & vbcrlf &_
 "UserID = " & UserID & vbcrlf &_
 "GroupID = " & GroupID
 '
 'You can't use any UI functionality from within a DBWServer Protected Script !!
 ' MsgBox inputParameters <= NO !
 ' Any output must be directed on a file, so that a User Script can read it
 '
 Set fs = CreateObject("Scripting.FileSystemObject")
 Set a = fs.OpenTextFile( "C:\TEMP\myProtectedScript.out", ForWriting, True )
 a.WriteLine( "script output = " & inputParameters )
 a.Close
End Sub