Solved

vbscript output help

Posted on 2016-08-08
4
69 Views
Last Modified: 2016-08-09
I had this question after viewing vbscript, email results.


I needed some assistance with the output this is generating through email.  strResult only send information on one line of text or echo's like the below.

AllowMaximum:       True
Caption:       Apps$
MaximumAllowed:       
Name:       Apps$
Path:       C:\Apps
Type:       0

How can I get the output to read:
Computer Name:
Name:
Path:

in the email this sends?
0
Comment
Question by:Rob Shorts
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 41748606
            strResult = strResult + "Computer Name: " & vbTab & strComputer  & vbcrlf &_
                  "Name: " & vbTab & objShare.Name & vbcrlf &_
                  "Path: " & vbTab & objShare.Path & vbcrlf & vbcrlf

Open in new window

1
 

Author Comment

by:Rob Shorts
ID: 41748666
Thank you Robberbaron (robr) - this is what I needed.

If I can get your advice on one more thing please, I want to list the permissions of each share as well, how could I got about doing this with a readable output?
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 41749615
I got lots of code from https://wmiscripting.wordpress.com/2007/12/07/view-share-permission/   (and Kimputer)

the Excel workbook reference seems redundant now also

Dim strComputer, strResult
Dim exclusions

If Trim(strComputer) = "" Then strComputer = "."
exclusions = Array("Apps$", "sys$")

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery("SELECT * FROM Win32_Share WHERE NOT Type=2147483648 AND NOT Type=2147483649 AND NOT Type=2147483650 AND NOT Type=2147483651")


For each objShare in colShares
      If UBound(Filter(exclusions, objShare.Name, True, 1)) < 0 Then
            strResult = strResult + "Computer Name: " & vbTab & strComputer  & vbcrlf &_
                  "Name: " & vbTab & objShare.Name & vbcrlf &_
                  "Path: " & vbTab & objShare.Path & vbcrlf 
			strResult = strResult & "Permissions::"	& vbcrlf 
			strResult = strResult &  GetSharePermissions(objShare.Name) & vbcrlf & vbcrlf			
      End If
Next
wscript.echo "Shares on computer: " & strComputer & vbcrlf & vbcrlf & strResult
'wscript.echo "Done"

Dim objMessage, Rcpt 
'Set objExcel = CreateObject("Excel.Application")
'objExcel.Workbooks.Add

wscript.quit

''' https://wmiscripting.wordpress.com/2007/12/07/view-share-permission/

Function GetSharePermissions(vShareName )
    Set objFolderSecSetting = objWMIService.Get("Win32_LogicalShareSecuritySetting.Name='" & vShareName & "'")
    intRetVal = objFolderSecSetting.GetSecurityDescriptor(objSecDescriptor)
    dim shareList
    If IsNull(objSecDescriptor.DACL) Then
        ''// Note: A NULL DACL gives full access to everyone, which is a serious security risk
        shareList = vbTab & "Everyone: Full Control"
    Else
        arrDACL = objSecDescriptor.DACL '// Get DACL (an array of Win32_ACE objects)
        For Each objACE In arrDACL
			Set objTrustee = objACE.Trustee
            shareList = shareList & vbTab & objTrustee.Name & ": " & GetShareAccessMaskStr(objACE.AccessMask)& vbcrlf
        Next 
    End If

	GetSharePermissions = shareList
    Set objFolderSecSetting = Nothing

End Function

Function GetShareAccessMaskStr(vAccessMaskVal)
    Dim strTemp

    Select Case vAccessMaskVal
        Case 2032127:  strTemp = "Full Control"
        Case 1245631:  strTemp = "Change"
        Case 1179817:  strTemp = "Read"   
        Case Else: strTemp = "Access Mask " & vAccessMaskVal
    End Select 
    GetShareAccessMaskStr = strTemp
End Function

Open in new window

1
 

Author Closing Comment

by:Rob Shorts
ID: 41749622
Awesome, thank you!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question