Solved

Create and Share a Folder in VBScript

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is about my first experience with programming Arduino.
Six Sigma Control Plans
Starting up a Project

705 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