自动文件共享 [英] Automate file sharing

查看:19
本文介绍了自动文件共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一些关于如何启用文件共享和共享文件夹的 vbscript 示例,但是它们关闭了公共文件夹共享",因此您必须登录,而不仅仅是允许任何具有网络访问权限的人阅读/写入公共文件夹.

I've found some vbscript examples on how to enable file sharing and share a folder, however they leave the "Public folder sharing" off so that you have to be logged in rather than just allowing anyone with network access to read/write to public folders.

对于我所有的谷歌搜索,我似乎无法找到如何自动化最后一部分.Vbscript 或任何可以通过命令行运行的东西将是我执行此操作的首选方法,但我真的很乐意听到任何可以自动执行此操作的解决方案.

For all my googling, I can't seem to find out how to automate that last piece. Vbscript or anything that can be run via command line would be my preferred method of doing this, but really I'm open to hearing about any solution that would automate this.

如果相关,我应该指出我将在非域计算机上以管理员权限在本地运行它.

In case it's relevant, I should point out that I'm going to be running this locally with admin privileges on non-domain computers.

编辑 2:

我已经尝试了下面列出的解决方案,但是我需要更改的选项会影响连接到计算机以查看共享列表的能力;它不特定于特定份额.

I've tried the solutions listed below, however the option I need to change affects the ability to connect to a computer to see the list of shares; it's not specific to a particular share.

推荐答案

最简单的方法是炮轰:

Set sh = CreateObject("WScript.Shell")
sh.Run "net share sharename=C:\some\folder /grant:Everyone,FULL", 0, True

完全在 VBScript 中完成它是可能的,但需要更多的代码.已在此处发布了一个示例脚本,可以针对您的特定情况进行简化要求如下:

Doing it entirely in VBScript is possible, but requires significantly more code. A sample script for this has been published here, which could be simplified for your particular requirements like this:

path      = "C:\some\folder"
sharename = "name"
comment   = "foo"

Set wmi = GetObject("winmgmts://./root/cimv2")

Set trustee = wmi.Get("Win32_Trustee").SpawnInstance_()
trustee.Domain = Null
trustee.Name   = "Everyone"
trustee.SID    = Array(1,1,0,0,0,0,0,1,0,0,0,0) 'SID S-1-1-0 (binary)

Set ace = wmi.Get("Win32_Ace").SpawnInstance_()
ace.AccessMask = 2032127  'full access
ace.AceFlags   = 3        'object inheritance + container inheritance
ace.AceType    = 0        'allow access
ace.Trustee    = trustee

Set sd = wmi.Get("Win32_SecurityDescriptor").SpawnInstance_()
sd.DACL = Array(ace)

Set share = wmi.Get("Win32_Share")
rc = share.Create(path, sharename, 0, 10, comment, "", sd)

If rc = 0 Then
  WScript.Echo "Folder " & path & " has been shared as " & sharename & "."
Else
  WScript.Echo "Error sharing folder " & path & ": " & rc
End If

这篇关于自动文件共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆