1

I want to create a network share using vbScript.

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

e.g.

Set shell = CreateObject("WScript.Shell")
shell.Run "net share sc1=" & sShare , 1, false
seanyboy
  • 308
  • 4
  • 17

2 Answers2

2

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
Const MAXIMUM_CONNECTIONS = 25
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
Matt
  • 1,903
  • 13
  • 12
0

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.

Christopher
  • 1,673
  • 12
  • 17