Author: brad
Date: 2006-06-04 21:19:22 +0000 (Sun, 04 Jun 2006)
New Revision: 16041

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16041

Log:
Added a constant for ERROR_PATH_NOT_FOUND to include\common.vbs, and moved 
NEW_WINDOW_MINIMIZED from smb_addshare.wsh and smb_delshare.wsh.
Created include\fs_common.vbs with functions for creating and removing 
directories.
smb_addshare.wsh and smb_delshare.wsh have been updated to find common.vbs and 
fs_common.vbs in include\, and use the new fs_common.vbs create_directory and 
delete_directory functions.


Added:
   branches/SOC/bnh/include/fs_common.vbs
Modified:
   branches/SOC/bnh/include/common.vbs
   branches/SOC/bnh/smb_addshare.wsf
   branches/SOC/bnh/smb_delshare.wsf


Changeset:
Modified: branches/SOC/bnh/include/common.vbs
===================================================================
--- branches/SOC/bnh/include/common.vbs 2006-06-04 20:42:12 UTC (rev 16040)
+++ branches/SOC/bnh/include/common.vbs 2006-06-04 21:19:22 UTC (rev 16041)
@@ -11,6 +11,8 @@
 
 const READ_ONLY = 1
 
+const ERROR_PATH_NOT_FOUND = 76
+
 ' We don't have WMI or ADSI extended errors in VBScript.
 ' To figure them out, take the last 4 digits of the hex error code,
 ' and convert them to an integer. Then search for that integer
@@ -19,6 +21,8 @@
 const ADSI_ERROR_DS_NO_SUCH_OBJECT     = "80072030" ' PlatformSDK WinError.h
 const LM_NERR_PasswordTooShort         = "800708C5" ' PlatformSDK LMErr.h
 
+const NEW_WINDOW_MINIMIZED = 7
+
 set stdout = wscript.stdout
 set stdin = wscript.stdin
 
@@ -82,4 +86,3 @@
         set file = nothing
         set fileSystemObject = nothing
 end function
-

Added: branches/SOC/bnh/include/fs_common.vbs
===================================================================
--- branches/SOC/bnh/include/fs_common.vbs      2006-06-04 20:42:12 UTC (rev 
16040)
+++ branches/SOC/bnh/include/fs_common.vbs      2006-06-04 21:19:22 UTC (rev 
16041)
@@ -0,0 +1,47 @@
+' A VBScript providing some common library functions for performing
+' filesystem activities.
+' Copyright Brad Henry <[EMAIL PROTECTED]> 2006
+' Released under the GNU GPL v2 or later.
+
+' Don't halt on runtime errors, we will catch them.
+on error resume next
+
+public function create_directory(pathname)
+       on error resume next
+       
+       set fileSystemObject = createObject("scripting.fileSystemObject")
+       set folder = fileSystemObject.createFolder(pathname)
+
+       if err.number <> 0 then
+               stdout.writeline "Unhandled error occurred while " _
+                       & "creating directory " & pathname & "."
+               report_error
+               wscript.quit(err.number)
+       end if
+       stdout.writeline "Directory " & pathname & " created."
+       create_directory = err.number
+end function
+
+public function delete_directory(pathname)
+       on error resume next
+
+       set fileSystemObject = createObject("scripting.fileSystemObject")
+
+       fileSystemObject.deleteFolder(pathname)
+       if err.number <> 0 then
+               if err.number = ERROR_PATH_NOT_FOUND then
+                       stdout.writeline "Directory " & pathname  _
+                               & " does not exist."
+                       report_error
+               else
+                       stdout.writeline "An unhandled error occurred " _
+                               & "while removing the directory " & pathname _
+                               & "."
+                       report_error
+                       wscript.quit(err.number)
+               end if
+       else
+               stdout.writeline "Directory " & pathname & " removed."
+       end if
+       delete_directory = err.number
+end function

Modified: branches/SOC/bnh/smb_addshare.wsf
===================================================================
--- branches/SOC/bnh/smb_addshare.wsf   2006-06-04 20:42:12 UTC (rev 16040)
+++ branches/SOC/bnh/smb_addshare.wsf   2006-06-04 21:19:22 UTC (rev 16041)
@@ -1,43 +1,30 @@
 <package>
 <job id=smb_addshare>
-<script language="VBScript" src="common.vbs">
+<script language="VBScript" src="include\common.vbs">
 
 ' A windows script (.wsf) to add a shared directory, written in VBScript.
 ' Copyright Brad Henry <[EMAIL PROTECTED]> 2006
 ' Released under the GNU GPL v2 or later.
 
+execute include("include\fs_common.vbs")
+
 const USAGE_STATEMENT = "Usage: cscript smb_addshare.vbs /username:<username> 
/sharename:<share name> /sharepath:<share path>"
 
 function setup_dir(username, sharename, sharepath)
 
        on error resume next
 
-       stdout.writeline(sharepath)
-
        ' Check to see if the directory exists. If it does, delete it.
        set fileSystemObject = createObject("scripting.fileSystemObject")
        if fileSystemObject.folderExists(sharepath) then
                stdout.writeline "Directory " & sharepath & " exists."
-               fileSystemObject.deleteFolder(sharepath)
-               if err.number <> 0 then
-                       stdout.writeline "Unhandled error occurred while " _
-                               & "removing directory " & sharepath & "."
-                       report_error
-                       wscript.quit(err.number)
-               end if
-               stdout.writeline "Directory " & sharepath & " removed."
+               delete_directory sharepath
        end if
 
        ' Create the directory to share.
-       set folder = fileSystemObject.createFolder(sharepath)
-       if err.number <> 0 then
-               stdout.writeline "Unhandled error occurred while " _
-                       & "creating directory " & sharepath & "."
-               report_error
-               wscript.quit(err.number)
-       end if
-       stdout.writeline "Directory " & sharepath & " created."
+       create_directory sharepath
        
+       ' If the share exists, remove it.       
        local_machine = "."
        set shares_list = getObject("WinNT://" & local_machine _
                & "/LanmanServer,FileService")

Modified: branches/SOC/bnh/smb_delshare.wsf
===================================================================
--- branches/SOC/bnh/smb_delshare.wsf   2006-06-04 20:42:12 UTC (rev 16040)
+++ branches/SOC/bnh/smb_delshare.wsf   2006-06-04 21:19:22 UTC (rev 16041)
@@ -1,13 +1,14 @@
 <package>
 <job id=smb_delshare>
-<script language="VBScript" src="common.vbs">
+<script language="VBScript" src="include\common.vbs">
 
 ' A windows script (.wsf) to remove a shared directory, written in VBScript.
 ' Copyright Brad Henry <[EMAIL PROTECTED]> 2006
 ' Released under the GNU GPL v2 or later.
 
+execute include("include\fs_common.vbs")
+
 const USAGE_STATEMENT =  "Usage: cscript smb_delshare.vbs /sharename:<share 
name> /sharepath:<share path>"
-const NEW_WINDOW_MINIMIZED = 7
 
 on error resume next
 
@@ -41,15 +42,7 @@
 end if
 
 ' Delete the directory.
-set fileSystemObject = createObject("scripting.fileSystemObject")
-fileSystemObject.deleteFolder(pathname)
-if err.number <> 0 then
-       stdout.writeline "An unhandled error occurred while removing " _
-               & "the directory " & pathname  & "."
-       report_error
-       wscript.quit(err.number)
-end if
-stdout.writeline "Directory " & pathname & " removed."
+delete_directory pathname
 
 </script>
 </job>

Reply via email to