Solved

Querying the Domain

Posted on 2013-01-22
7
241 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
  • 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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 …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

829 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