Solved

Create and Share a Folder in VBScript

Posted on 2006-11-01
1
7,182 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

733 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