Solved

Querying the Domain

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In-place Upgrading Dirsync to Azure AD Connect
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

717 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