Solved

Querying the Domain

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

Join & Write a Comment

Suggested Solutions

Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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 to another domain controller. Log onto the new domain controller with a user account t…
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 …

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now