svn commit: samba r16035 - in branches/SOC/bnh: .
brad at samba.org
brad at samba.org
Sun Jun 4 00:30:27 GMT 2006
Author: brad
Date: 2006-06-04 00:30:27 +0000 (Sun, 04 Jun 2006)
New Revision: 16035
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16035
Log:
Removed smb_addshare.vbs and replaced with smb_addshare.wsf.
smb_addshare.wsf checks to see if the share or directory already exist.
If they do, it removes them before trying to create them.
Added:
branches/SOC/bnh/smb_addshare.wsf
Removed:
branches/SOC/bnh/smb_addshare.vbs
Changeset:
Deleted: branches/SOC/bnh/smb_addshare.vbs
===================================================================
--- branches/SOC/bnh/smb_addshare.vbs 2006-06-03 22:42:25 UTC (rev 16034)
+++ branches/SOC/bnh/smb_addshare.vbs 2006-06-04 00:30:27 UTC (rev 16035)
@@ -1,58 +0,0 @@
-const READ_ONLY = 1
-const USAGE_STATEMENT = "Usage: cscript smb_addshare.vbs /username:<username> /sharename:<share name> /sharepath:<share path>"
-
-' This function returns the contents of a file.
-' When passed the name of a .vbs script and passed to execute, the contents
-' of the script are visible within the relevant scope of this script.
-function include(library_filename)
- dim filesystem_object, file
-
- set filesystem_object = CreateObject("Scripting.FileSystemObject")
- set file = filesystem_object.OpenTextFile(library_filename, READ_ONLY)
-
- include = file.readall
- set file = nothing
- set filesystem_object = nothing
-end function
-
-execute include("common.vbs")
-
-' Required command line options
-dim required_options, provided_options
-
-required_options = array("username", "sharename", "sharepath")
-set provided_options = wscript.arguments.named
-
-set setup_options = new setup_object
-setup_options.check_options provided_options, required_options
-
-if setup_options.error_code = RTN_ERR then
- setup_options.list_missing_options
- stdout.writeline USAGE_STATEMENT
- wscript.quit(setup_options.error_code)
-end if
-
-username = provided_options.item("username")
-sharename = provided_options.item("sharename")
-pathname = provided_options.item("sharepath")
-
-' Check if the directory exists, and exit if it does.
-Set fileSystemObject = CreateObject("Scripting.FileSystemObject")
-if fileSystemObject.FolderExists(pathname) Then
- stdout.Write "Error: Directory " & pathname & " exists. Exiting."
- WScript.Quit
-End If
-
-' Create the directory to share.
-Set fileSystemObject = CreateObject("Scripting.FileSystemObject")
-Set folder = fileSystemObject.CreateFolder(pathname)
-
-' Share the directory.
-Set shell = WScript.CreateObject("WScript.Shell")
-netsharecmd = "net share " & sharename & "=" & pathname & " /GRANT:" _
- & username & ",FULL"
-shell.Run netsharecmd, 7, True
-
-' Remove share.
-' Delete shared directory.
-'fileSystemObject.DeleteFolder(pathname)
Added: branches/SOC/bnh/smb_addshare.wsf
===================================================================
--- branches/SOC/bnh/smb_addshare.wsf 2006-06-03 22:42:25 UTC (rev 16034)
+++ branches/SOC/bnh/smb_addshare.wsf 2006-06-04 00:30:27 UTC (rev 16035)
@@ -0,0 +1,104 @@
+<package>
+<job id=smb_addshare>
+<script language="VBScript" src="common.vbs">
+
+' A windows script (.wsf) to add a shared directory, written in VBScript.
+' Copyright Brad Henry <brad at samba.org> 2006
+' Released under the GNU GPL v2 or later.
+
+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."
+ 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."
+
+ local_machine = "."
+ set shares_list = getObject("WinNT://" & local_machine _
+ & "/LanmanServer,FileService")
+ for each share in shares_list
+ if share.name = sharename then
+ stdout.writeline "Share " & sharename _
+ & " exists."
+ ' Remove the share.
+ set shell = wscript.createObject("wscript.shell")
+ netsharecmd = "net share " & sharename & " /DELETE"
+ error_code = shell.run(netsharecmd, _
+ NEW_WINDOW_MINIMIZED, True)
+ if error_code = 0 then
+ stdout.writeline "Share " & sharename _
+ & " removed."
+ else
+ stdout.writeline "Error: " & netsharecmd _
+ & " returned " & error_code & "."
+ end if
+ break
+ end if
+ next
+
+ ' Share the directory.
+ set shell = wscript.createObject("wscript.shell")
+ netsharecmd = "net share " & sharename & "=" & sharepath & " /GRANT:" _
+ & username & ",FULL"
+ error_code = shell.run(netsharecmd, NEW_WINDOW_MINIMIZED, True)
+ if error_code = 0 then
+ stdout.writeline "Share " & sharename & " created."
+ else
+ stdout.writeline "Error: " & netsharecmd & " returned " _
+ & error_code & "."
+ end if
+
+end function
+
+' Command line options.
+dim required_options, provided_options
+
+required_options = array("username", "sharename", "sharepath")
+set provided_options = wscript.arguments.named
+
+set setup_options = new setup_object
+setup_options.check_options provided_options, required_options
+
+if setup_options.error_code = RTN_ERR then
+ setup_options.list_missing_options
+ stdout.writeline USAGE_STATEMENT
+ wscript.quit(setup_options.error_code)
+end if
+
+username = provided_options.item("username")
+sharename = provided_options.item("sharename")
+sharepath = provided_options.item("sharepath")
+
+' Check to see if the directory exists.
+' If it does, delete and recreate it.
+' If it does not, create it. Do the same for the share.
+setup_dir username, sharename, sharepath
+
+</script>
+</job>
+</package>
More information about the samba-cvs
mailing list