以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]文件夹共享问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=77721)

--  作者:pcxjxjhkw
--  发布时间:2015/11/24 11:10:00
--  [求助]文件夹共享问题
如何用代码将指定文件夹共享并设置为隐藏?
--  作者:大红袍
--  发布时间:2015/11/24 11:20:00
--  

mark 创建共享文件夹

 

Try
    Dim managementClass As New System.Management.ManagementClass("Win32_Share")
   
    Dim inParams As object = managementClass.GetMethodParameters("Create")
    Dim outParams As object
   
    inParams("Description") = "注释"
    inParams("Name") = "test共享"
    inParams("Path") = "d:\\test"
    inParams("Type") = &H0
   
    outParams = managementClass.InvokeMethod("Create", inParams, Nothing)
   
    If CUInt(outParams.Properties("ReturnValue").Value) <> 0 Then
        msgbox("设置失败")
    Else
        msgbox("OK")
    End If
Catch ex As exception
    msgbox(ex.message)
End Try

 


--  作者:大红袍
--  发布时间:2015/11/24 11:24:00
--  

取消共享

 

try
    Dim selectQuery As New System.Management.SelectQuery("Select * fr-om Win32_Share Where Name = \'" & "test共享" & "\'")
    Dim searcher As New System.Management.ManagementObjectSearcher(selectQuery)
    For Each mo As object In searcher.[Get]()
        mo.InvokeMethod("Delete", Nothing, Nothing)
    Next
    msgbox("OK")
catch ex As exception
    msgbox(ex.message)
End try


--  作者:大红袍
--  发布时间:2015/11/24 11:24:00
--  
记得添加引用 System.Management.dll