Solved

vbscript output help

Posted on 2016-08-08
4
77 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 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