[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

On startup of a machine record the Users & groups of the Machine.Just accounts that are manually created.

Hi,

On startup of a machine record the Users & groups of the Machine.Just accounts that are manually created.
Any user or groups that are created manually needs to be logged into a txt file in the UNC path.

Regards
Sharath
0
bsharath
Asked:
bsharath
  • 4
  • 3
1 Solution
 
vikas_madhusudanaCommented:
to get the users you can go to c:\documents and settings and do

dir /b


to get the localgroups you can use net command

net localgroup
0
 
AmazingTechCommented:
Are you going to setup a GPO Machine Startup script for this?
0
 
bsharathAuthor Commented:
Hi AT yes via GPO
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bsharathAuthor Commented:
Hi AT any Views...
0
 
AmazingTechCommented:
OK. Try out this .vbs script.

Modify these 3 string variables for your environment.


UNCFile = "C:\AT\ComputerUserGrouplist.txt"
ApprovedUsers = "Administrator,Guest,HelpAssistant,ASPNET,SUPPORT_388945a0"
ApprovedGroups = "Administrators,Users,Power Users,Backup Operators,Guests,Remote Desktop Users"

On Error Resume Next
UNCFile = "C:\AT\ComputerUserGrouplist.txt"
ApprovedUsers = "Administrator,Guest,HelpAssistant,ASPNET,SUPPORT_388945a0"
ApprovedGroups = "Administrators,Users,Power Users,Backup Operators,Guests,Remote Desktop Users"


strComputer = "."
ApprovedUsers = "," & ApprovedUsers & ","
ApprovedGroups = "," & ApprovedGroups & ","

Set objComputer = GetObject("WinNT://" & strComputer & "")


objComputer.Filter = Array("User")

For Each objUser In objComputer
    If InStr(1, ApprovedUsers, "," & objUser.Name & ",", vbTextCompare) = 0 Then WriteToUNC ("LocalUser=" & objUser.Name)
Next

objComputer.Filter = Array("group")
For Each objGroup In objComputer
    If InStr(1, ApprovedGroups, "," & objGroup.Name & ",", vbTextCompare) = 0 Then WriteToUNC ("LocalGroup=" & objGroup.Name)
Next


Sub WriteToUNC(Message)
    Const ForWriting = 2
    Const ForAppending = 8
    Set WSHSHELL = CreateObject("Wscript.Shell")


    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(UNCFile) Then
        Set objTextFile = objFSO.OpenTextFile(UNCFile, ForAppending)
    Else
        Set objTextFile = objFSO.CreateTextFile(UNCFile, ForWriting)
    End If
    objTextFile.Writeline WSHSHELL.ExpandEnvironmentStrings("%ComputerName%") & "," & Message
    objTextFile.Close
    Set objFSO = Nothing
    Set WSHSHELL = Nothing
End Sub

Open in new window

0
 
bsharathAuthor Commented:
Thanks  AT it works fine

Will all machines data get into 1 file?
If yes then can i get them seperate files with Machine name as the txt file name in the UNC folder
0
 
AmazingTechCommented:
The above code logs:

MachineName,Group or user=Name of manually added

If you want per machine log. Is duplicating the entries OK? Maybe we can log Date and Time?

Sorry it took so long. I really wanted to do it as a batch file but couldn't find an easy way to get proper user names and group names.
On Error Resume Next
UNCPath = "C:\AT"
ApprovedUsers = "Administrator,Guest,HelpAssistant,ASPNET,SUPPORT_388945a0"
ApprovedGroups = "Administrators,Users,Power Users,Backup Operators,Guests,Remote Desktop Users"
 
 
strComputer = "."
ApprovedUsers = "," & ApprovedUsers & ","
ApprovedGroups = "," & ApprovedGroups & ","
 
Set objComputer = GetObject("WinNT://" & strComputer & "")
 
 
objComputer.Filter = Array("User")
 
For Each objUser In objComputer
    If InStr(1, ApprovedUsers, "," & objUser.Name & ",", vbTextCompare) = 0 Then WriteToUNC ("LocalUser=" & objUser.Name)
Next

objComputer.Filter = Array("group")
For Each objGroup In objComputer
    If InStr(1, ApprovedGroups, "," & objGroup.Name & ",", vbTextCompare) = 0 Then WriteToUNC ("LocalGroup=" & objGroup.Name)
Next


Sub WriteToUNC(Message)
    Const ForWriting = 2
    Const ForAppending = 8
    UNCFile = UNCPath & "\" & WSHSHELL.ExpandEnvironmentStrings("%ComputerName%") & ".txt"
    Set WSHSHELL = CreateObject("Wscript.Shell")
 
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(UNCFile) Then
        Set objTextFile = objFSO.OpenTextFile(UNCFile, ForAppending)
    Else
        Set objTextFile = objFSO.CreateTextFile(UNCFile, ForWriting)
    End If
    objTextFile.Writeline  Date & "," & Time & "," & Message
    objTextFile.Close
    Set objFSO = Nothing
    Set WSHSHELL = Nothing
End Sub

Open in new window

0
 
bsharathAuthor Commented:
Thank U AT....Works perfect

Can you help on this...
http://www.experts-exchange.com/Programming/Languages/Q_25081166.html
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now