Link to home
Start Free TrialLog in
Avatar of Bianchi928
Bianchi928

asked on

Querying the Domain

I need to extract infos from a  domain about users who are connected.
I found this little script which can be a starting point. Apart from computer name,
username, what else can I extract.

When I run it , I get an error message on LIne 3
Permission Denied : " Get Object"
Code 800A0046

N.B How can I run the script as admin.

Thanks
Cheers


strServer = "?????.?????.co.nz" 
Set objWMI = GetObject("winmgmts://" & strServer & "/rootcimv2")  
Set objInstances = objWMI.InstancesOf("Win32_ServerSession",48)  
For Each objInstance in objInstances  
    With objInstance  
         WScript.Echo .UserName & " ; " & .ComputerName & " ; " & .ClientType &_  
         .Name & " ; " & Round(.ActiveTime/60,0) & " minutes connected" 
     End With 
Next 
Set objInstances = Nothing 
Set objWMI = Nothing

Open in new window

Avatar of Amandeep Singh Bhullar
Amandeep Singh Bhullar
Flag of India image

Does the domain belongs to you????
On Error Resume Next

arrComputers = Array("?????.?????.co.nz")
For Each strComputer In arrComputers
   WScript.Echo
   WScript.Echo "=========================================="
   WScript.Echo "Computer: " & strComputer
   WScript.Echo "=========================================="

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ServerSession",,48)

   For Each objItem In colItems
      WScript.Echo "ActiveTime: " & objItem.ActiveTime
      WScript.Echo "Caption: " & objItem.Caption
      WScript.Echo "ClientType: " & objItem.ClientType
      WScript.Echo "ComputerName: " & objItem.ComputerName
      WScript.Echo "Description: " & objItem.Description
      WScript.Echo "IdleTime: " & objItem.IdleTime
      WScript.Echo "InstallDate: " & WMIDateStringToDate(objItem.InstallDate)
      WScript.Echo "Name: " & objItem.Name
      WScript.Echo "ResourcesOpened: " & objItem.ResourcesOpened
      WScript.Echo "SessionType: " & objItem.SessionType
      WScript.Echo "Status: " & objItem.Status
      WScript.Echo "TransportName: " & objItem.TransportName
      WScript.Echo "UserName: " & objItem.UserName
      WScript.Echo
   Next
Next

Open in new window

Run the script from a administrative CMD prompt...
right-click CMD, run as administrator
cscript /nologo script.vbs
Where script.vbs is the script above.
The script isn't about who is connected to the domain, it's about network/server sessions
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394417%28v=vs.85%29.aspx
-rich
Hi

You need to change the settings in registry, i don't know which version of Windows you are using

Check the links
http://social.technet.microsoft.com/Forums/en/ITCG/thread/f2955711-4dc5-4150-9f65-60f46f11213c
http://www.vistax64.com/vb-script/245848-permissions-execute-script.html

Some information on RPC
http://technet.microsoft.com/en-us/library/cc781010.aspx



Hope this will help you
ASKER CERTIFIED SOLUTION
Avatar of Rich Rumble
Rich Rumble
Flag of United States of America image

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

ASKER

Thta's what I needed