Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vbscript output help

Posted on 2016-08-08
4
Medium Priority
?
91 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 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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 User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

916 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