Solved

vbscript output help

Posted on 2016-08-08
4
56 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now