locked
Adding "Wscript.echo" in place of Report.txt in VBS? RRS feed

  • Question

  • Hi, This script gets remote user's membership info and saves a report.txt as a result.

    Can this code be changed with wscript.echo in place of Report.txt

    I tried to change it but i couldnt :( Thank you in advance

    Note: I am afraid Jrv responds or answers to me :(

    strUsers = InputBox("Enter Username: ")
    arrUsers = Split(strUsers, ",")
    
    If strUsers <> "" Then
    On Error Resume Next
    Err.Clear
    
    '("WScript.Network")
    Set fs = CreateObject ("Scripting.FileSystemObject")
    Set outFile = fs.CreateTextFile (".\Report.txt")
    
    outFile.WriteLine "Active User's Membership"
    For x = 0 to UBound(arrUsers)
    	arrUsers(x) = Trim(arrUsers(x))
    	If x = 0 Then
    		'outFile.WriteLine "USER: " & arrUsers(x)
    	Else
    		outFile.WriteLine "        " & arrUsers(x)
    	End If
    Next 
    outFile.WriteLine "==========="
    For x = 0 to UBound(arrUsers)
    	Call getGroups(arrUsers(x))
    Next
    
    Wscript.echo "Check the Report (report.txt) File!"
    
    
    Sub getGroups(strUser)
    	Set oNetwork = CreateObject("WScript.Network")
    	strDomain = oNetwork.UserDomain
    	On Error Resume Next
    	Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
    	If Err.Number <> 0 Then
    		outFile.WriteLine strUser & " not found..."
    		Exit Sub
    	End If
    	Err.Clear
    	On Error Goto 0
    	
    	outFile.WriteLine strUser & " - " & oUser.FullName
    
    	For Each strGroup In oUser.Groups
    		outFile.WriteLine "" & strGroup.Name
    	Next
    End Sub
    
    ElseIf strUsers = "" Then
    	WScript.Echo "Cancelled."
    End If


    \_(ツ)_/ twitter.com/serdaruzun



    • Edited by serdaruzun Thursday, September 18, 2014 10:36 AM understand
    Thursday, September 18, 2014 10:24 AM

Answers

  • strUsers = InputBox("Enter Username: ")
    arrUsers = Split(strUsers, ",")
    
    If strUsers <> "" Then
    On Error Resume Next
    Err.Clear
    
    WScript.Echo "Active User's Membership"
    For x = 0 to UBound(arrUsers)
    	arrUsers(x) = Trim(arrUsers(x))
    	If x = 0 Then
    		'outFile.WriteLine "USER: " & arrUsers(x)
    	Else
    		WScript.Echo "        " & arrUsers(x)
    	End If
    Next 
    WScript.Echo "==========="
    For x = 0 to UBound(arrUsers)
    	Call getGroups(arrUsers(x))
    Next
    
    WScript.Echo "Check the Report (report.txt) File!"
    
    
    Sub getGroups(strUser)
    	Set oNetwork = CreateObject("WScript.Network")
    	strDomain = oNetwork.UserDomain
    	On Error Resume Next
    	Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
    	If Err.Number <> 0 Then
    		WScript.Echo strUser & " not found..."
    		Exit Sub
    	End If
    	Err.Clear
    	On Error Goto 0
    	
    	WScript.Echo strUser & " - " & oUser.FullName
    
    	For Each strGroup In oUser.Groups
    		WScript.Echo "" & strGroup.Name
    	Next
    End Sub
    
    ElseIf strUsers = "" Then
    	WScript.Echo "Cancelled."
    End If
    This is :)

    \_(ツ)_/ twitter.com/serdaruzun

    • Marked as answer by serdaruzun Friday, September 19, 2014 1:27 PM
    Friday, September 19, 2014 1:27 PM

All replies

  • Just add it.

    Open script in notepad and type in the commands where needed.


    ¯\_(ツ)_/¯


    • Edited by jrv Thursday, September 18, 2014 10:27 AM
    Thursday, September 18, 2014 10:27 AM
  • Just add it.

    Open script in notepad and type in the commands where needed.


    ¯\_(ツ)_/¯


    Oooh thank you! You helped me so so much! Please Jrv, You, dont answer!

    \_(ツ)_/ twitter.com/serdaruzun

    Thursday, September 18, 2014 10:31 AM
  • Just replace the lines that write to the file. Why is that so hard?

    After three+ months of asking question you should know how to edit a script file by now so why can't you do that.

    Change these lines:

    outFile.WriteLine strUser & " - " & oUser.FullName

    That is all there is to do.


    ¯\_(ツ)_/¯

    Thursday, September 18, 2014 10:39 AM
  • Here is a detailed explanation of how to use WScript.Echo

    http://blogs.technet.com/b/heyscriptingguy/archive/2009/05/29/scripting-your-first-steps.aspx


    ¯\_(ツ)_/¯

    Thursday, September 18, 2014 10:40 AM
  • Why do you insist of offending yourself by answering!

    \_(ツ)_/ twitter.com/serdaruzun

    Thursday, September 18, 2014 10:52 AM
  • Why do you insist of offending yourself by answering!

    \_(ツ)_/ twitter.com/serdaruzun

    Why>  Do you think the answer is wrong?

    It is the exact answer you asked for.  Did you even look at the link?


    ¯\_(ツ)_/¯

    Thursday, September 18, 2014 11:01 AM
  • One day, I hope you will help and give the right answer instead of criticising

    \_(ツ)_/ twitter.com/serdaruzun

    Friday, September 19, 2014 12:13 PM
  • And Jrv;

    If you'd like to visit to Turkiye (Ankara), I wanna host you and show my hospitality lovely :)

    So maybe, I find an opportunity to explain my problems to you :) face to face

    • Edited by serdaruzun Friday, September 19, 2014 12:19 PM
    Friday, September 19, 2014 12:18 PM
  • strUsers = InputBox("Enter Username: ")
    arrUsers = Split(strUsers, ",")
    
    If strUsers <> "" Then
    On Error Resume Next
    Err.Clear
    
    WScript.Echo "Active User's Membership"
    For x = 0 to UBound(arrUsers)
    	arrUsers(x) = Trim(arrUsers(x))
    	If x = 0 Then
    		'outFile.WriteLine "USER: " & arrUsers(x)
    	Else
    		WScript.Echo "        " & arrUsers(x)
    	End If
    Next 
    WScript.Echo "==========="
    For x = 0 to UBound(arrUsers)
    	Call getGroups(arrUsers(x))
    Next
    
    WScript.Echo "Check the Report (report.txt) File!"
    
    
    Sub getGroups(strUser)
    	Set oNetwork = CreateObject("WScript.Network")
    	strDomain = oNetwork.UserDomain
    	On Error Resume Next
    	Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
    	If Err.Number <> 0 Then
    		WScript.Echo strUser & " not found..."
    		Exit Sub
    	End If
    	Err.Clear
    	On Error Goto 0
    	
    	WScript.Echo strUser & " - " & oUser.FullName
    
    	For Each strGroup In oUser.Groups
    		WScript.Echo "" & strGroup.Name
    	Next
    End Sub
    
    ElseIf strUsers = "" Then
    	WScript.Echo "Cancelled."
    End If
    This is :)

    \_(ツ)_/ twitter.com/serdaruzun

    • Marked as answer by serdaruzun Friday, September 19, 2014 1:27 PM
    Friday, September 19, 2014 1:27 PM