Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vbscript output help

Posted on 2016-08-08
4
Medium Priority
?
89 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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