Solved

Querying the Domain

Posted on 2013-01-22
7
242 Views
Last Modified: 2013-01-27
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

0
Comment
Question by:Bianchi928
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 38818794
Does the domain belongs to you????
0
 
LVL 38

Expert Comment

by:Rich Rumble
ID: 38818865
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
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 38819241
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
0
 
LVL 38

Accepted Solution

by:
Rich Rumble earned 500 total points
ID: 38819318
Oh I see, to run with alternate credentials, as someone with admin rights try:
On Error Resume Next
strUser = "Administrator"
strPassword = "password_here"

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", strUser, strPassword)
   objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy

   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

http://blogs.technet.com/b/heyscriptingguy/archive/2004/12/13/how-can-i-run-a-script-under-alternate-credentials.aspx
0
 

Author Closing Comment

by:Bianchi928
ID: 38824732
Thta's what I needed
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Issue: One Windows 2008 R2 64bit server on the network unable to connect to a buffalo Device (Linkstation) with firmware version 1.56. There are a total of four servers on the network this being one of them. Troubleshooting Steps: Connect via h…
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

749 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