我想使用 vbScript 创建网络共享。
除了执行“net share”命令之外,还有其他方法可以做到这一点吗?
例如
Set shell = CreateObject("WScript.Shell")
shell.Run "net share sc1=" & sShare , 1, false
答案1
通过 vbscript 使用 WMI。
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
答案2
尝试这个 -
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "E:", "\\Server\Public"
摘自此 MSDN 页面 -http://msdn.microsoft.com/en-us/library/8kst88h6(VS.85).aspx
这就是我们在登录脚本中映射网络共享的方式。