Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

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
Avatar of vikas_madhusudana
vikas_madhusudana
Flag of India image

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
Avatar of AmazingTech
AmazingTech

Are you going to setup a GPO Machine Startup script for this?
Avatar of bsharath

ASKER

Hi AT yes via GPO
Hi AT any Views...
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

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
ASKER CERTIFIED SOLUTION
Avatar of AmazingTech
AmazingTech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial