Solved

Create and Share a Folder in VBScript

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countHi challenge 25 101
Currency Conversion? 1 73
program a usb light to turn on when needed 6 49
Apps blocked by Java 9 64
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
A short article about problems I had with the new location API and permissions in Marshmallow
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 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

24 Experts available now in Live!

Get 1:1 Help Now