No announcement yet.

Pushing the values back into the share

  • Filter
  • Time
  • Show
Clear All
new posts

  • Pushing the values back into the share

    Hi All,
    I wrote a small script to get some properties of a share like Name, Description and many more.

    On Error Resume Next
     Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
       Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Share")
    For Each objItem In colItems
    WScript.Echo "Name: " & objItem.Name
     WScript.Echo "Description: " & objItem.Description
    Now I have a new description for each share. How do I push that back into that share? I have all the descriptions in an excel file. I can do the Excel initiation but I just wanted to know the way we push it back.

    I am assuming we can use PUT method. But I am not sure. Any help appreciated.


  • #2
    Re: Pushing the values back into the share


    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
       & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colShares = objWMIService.ExecQuery _
       ("SELECT * FROM Win32_Share")
    For Each objShare in colShares
        If objShare.Name = "sharename" Then
           'wscript.echo objShare.Description
           errReturn = objShare.SetShareInfo(50, _
           If errReturn <> 0 Then
             Wscript.Echo "FAILED", errReturn
           End If
        End If

    This posting is provided "AS IS" with no warranties, and confers no rights.


    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts


    • #3
      Re: Pushing the values back into the share

      Thanks rems. It worked like a charm.

      Although, I have a new doubt now. When we use that SetShareInfo, how are we sure that it changes only the Description field of the share? There are many other fields like Caption, Path, Type etc. How can we change their info?

      Does the number 50 have to do some thing with it ?


      • #4
        Re: Pushing the values back into the share

        Ohh.. 50 is the maximum no. of users it can allow. I got that. So, my question still remains. How can we change the other aspects like name, type, path etc