Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to create a network share using vbScript.

Is there a way of doing this other than executing a "net share" command?


Set shell = CreateObject("WScript.Shell")
shell.Run "net share sc1=" & sShare , 1, false
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Use WMI via vbscript.

Taken from http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/sharedfolders/#CreateNetworkShare.htm

Creating a Network Share

Creates a shared folder named FinanceShare, setting the maximum number of simultaneous connections to 25, and adding a share description.

Const FILE_SHARE = 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")
errReturn = objNewShare.Create _
    ("C:\Finance", "FinanceShare", FILE_SHARE, _
        MAXIMUM_CONNECTIONS, "Public share for the Finance group.")
Wscript.Echo errReturn
share|improve this answer
I found that the folder I was sharing needed a \ on the end to make this work. –  seanyboy Nov 3 '10 at 12:14
add comment

Try this -

Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "E:", "\\Server\Public"

Taken from this MSDN page - http://msdn.microsoft.com/en-us/library/8kst88h6(VS.85).aspx

It is how we map network shares in our login scripts.

share|improve this answer
That's mapping a network share - not creating a network share. But thanks. –  seanyboy Nov 3 '10 at 9:57
Duh, sorry about that. –  Christopher Nov 3 '10 at 15:32
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.