Solved

Create and Share a Folder in VBScript

Posted on 2006-11-01
1
7,168 Views
Last Modified: 2012-06-27
I've written two functions that will create and share a folder on a File Server. For simplicity, I'd like to be able to combine them both into a single function that will create the home folder and then share it. Here's the current code:

Function CreateFolder(strComputer, strUser)
 strDir = "\\" & strComputer & "\e$\users\"
' Create the File System Object
      Set objFSO = CreateObject("Scripting.FileSystemObject")

      If objFSO.FolderExists(strDir & strUser & "\") Then
            Set objFolder = objFSO.GetFolder(strDir & strUser & "\")
      Else
            Set objFolder = objFSO.CreateFolder(strDir & strUser & "\")
      End If
End Function      

Function ShareFolder(strComputer, UserStr)
      Const FILE_SHARE = 0
      Const MAXIMUM_CONNECTIONS = 25
      Set objWMIService = GetObject _
                ("winmgmts:\\" & strComputer & "\root\cimv2")

      Set objNewShare = objWMIService.Get("Win32_Share")

      errReturn = objNewShare.Create("E:\Users\" & UserStr, UserStr & "$", FILE_SHARE, MAXIMUM_CONNECTIONS, "User Share for " & UserStr)
End Function

If I combine both, it will  not share the folder. How do I successfully combine the two?
0
Comment
Question by:fairfaxdigital
1 Comment
 
LVL 2

Accepted Solution

by:
amiableansari earned 250 total points
ID: 17857252

Hi

you are using different variable name in both functions "strUser" in first and "UserStr" in second when copying the share folder code in the first function replace

errReturn = objNewShare.Create("E:\Users\" & UserStr, UserStr & "$", FILE_SHARE, MAXIMUM_CONNECTIONS, "User Share for " & UserStr)

with

errReturn = objNewShare.Create("E:\Users\" & strUser, strUser& "$", FILE_SHARE, MAXIMUM_CONNECTIONS, "User Share for " & strUser)

and Cheers
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
wefewf 2 43
countX 22 70
word0 challenge 4 53
tidtcpserver connection lost handle 2 43
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now