Creating a session in windows to auth to remote machines

E

ericwoodworth

Hi,
I'm trying to auth to remote machines so I can plunder WMI to get
logs and settings and the like. My script works for most of my
machines because they're all in the same domain and I run the script
as somebody who has enough access to get at this stuff but for
machines off the domain I'm stuck.

Now I'm primarily a sys/network admin and not a programmer. As a
sys admin if I had this problem while trying to pull eventlogs
manually with eventvwr I would simply map a drive to the remote
machine. That would allow me to enter a username/password and then
once I was authed I'd have a session and I'd be able to piggyback on
that session to pull logs.

I'm looking to do exactly that from inside my script. I could
probably import os and call the net use command to map a drive and get
a session that way but that feels really sloppy to me. I want to be
able to explicitly close this session when I'm done with it too.

So I figure there's a com object I could call to open this
session for me but I can't figure out what it is. Any help would be
appreciated!

Thanks
 
E

ericwoodworth

Hi,
     I'm trying to auth to remote machines so I can plunder WMI to get
logs and settings and the like.  My script works for most of my
machines because they're all in the same domain and I run the script
as somebody who has enough access to get at this stuff but for
machines off the domain I'm stuck.

     Now I'm primarily a sys/network admin and not a programmer.  As a
sys admin if I had this problem while trying to pull eventlogs
manually with eventvwr I would simply map a drive to the remote
machine.  That would allow me to enter a username/password and then
once I was authed I'd have a session and I'd be able to piggyback on
that session to pull logs.

     I'm looking to do exactly that from inside my script.  I could
probably import os and call the net use command to map a drive and get
a session that way but that feels really sloppy to me.  I want to be
able to explicitly close this session when I'm done with it too.

     So I figure there's a com object I could call to open this
session for me but I can't figure out what it is.  Any help would be
appreciated!

Thanks

Also I am writing this in Python. So I can use win32com if that's the
way to go or I can use anything python 2.6 has built in. I mentioned
com objects because I'm using a lot of those currently but if there's
a more pythonic way to do what I"m after then I'm all ears.

Thanks
 
T

Tim Golden

Hi,
I'm trying to auth to remote machines so I can plunder WMI to get
logs and settings and the like. My script works for most of my
machines because they're all in the same domain and I run the script
as somebody who has enough access to get at this stuff but for
machines off the domain I'm stuck.

Unless I'm missing something here, you can already specify
username etc. with WMI. Just Dispatch on "WbemScripting.SWbemLocator"
and call .ConnectServer. Just in case you haven't already, I
(naturally :) ) recommend my wmi module [1] which wraps a fair bit
of the plumbing for you, including this. Eg,

<code>
import wmi

c = wmi.WMI ("some-machine", user="tim", password="password")

for log in c.Win32_NTLogEvent (
Logfile="Application",
Type="error"
):
print log.RecordNumber, log.SourceName, log.Message


</code>


[1] http://timgolden.me.uk/python/wmi.html

TJG
 
E

ericwoodworth

Hi,
     I'm trying to auth to remote machines so I can plunder WMI to get
logs and settings and the like.  My script works for most of my
machines because they're all in the same domain and I run the script
as somebody who has enough access to get at this stuff but for
machines off the domain I'm stuck.

Unless I'm missing something here, you can already specify
username etc. with WMI. Just Dispatch on "WbemScripting.SWbemLocator"
and call .ConnectServer. Just in case you haven't already, I
(naturally :) ) recommend my wmi module [1] which wraps a fair bit
of the plumbing for you, including this. Eg,

<code>
import wmi

c = wmi.WMI ("some-machine", user="tim", password="password")

for log in c.Win32_NTLogEvent (
  Logfile="Application",
  Type="error"
):
  print log.RecordNumber, log.SourceName, log.Message

</code>

[1]http://timgolden.me.uk/python/wmi.html

TJG

That's very cool. I was using win32com.client but I'll check this
out. Thanks!
 
E

ericwoodworth

Unless I'm missing something here, you can already specify
username etc. with WMI. Just Dispatch on "WbemScripting.SWbemLocator"
and call .ConnectServer. Just in case you haven't already, I
(naturally :) ) recommend my wmi module [1] which wraps a fair bit
of the plumbing for you, including this. Eg,
<code>
import wmi
c = wmi.WMI ("some-machine", user="tim", password="password")
for log in c.Win32_NTLogEvent (
  Logfile="Application",
  Type="error"
):
  print log.RecordNumber, log.SourceName, log.Message

TJG

That's very cool.  I was using win32com.client but I'll check this
out.  Thanks!- Hide quoted text -

- Show quoted text -

Thanks Tim. I looked thru your code and you pointed me at just what I
need: SWbemLocator.ConnectServer Method which is awesome. I already
have the WMI portion of my program working so I was using SWbemLocator
already...I just didn't know about that specific method. That's a big
help. I've bookmarked that page...lot of good stuff there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top