?
Solved

Create and Share a Folder in VBScript

Posted on 2006-11-01
1
Medium Priority
?
7,194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
amiableansari earned 1000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Six Sigma Control Plans
Progress
Suggested Courses

801 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