RE: Windows Remote Log in

Discussion in 'Python' started by Tim Golden, Aug 28, 2003.

  1. Tim Golden

    Tim Golden Guest

    [TJG: I've slightly rearranged the posts so they read top-to-bottom]

    > From: Jesse [mailto:]
    >
    >I guess it is how can I have a user enter their NT Domain Authentication
    >and the script use it to log into NT Domains the computer it is running
    >on it not a member of.


    > From Tim:
    >
    > I suggest you have a look at WMI.
    > Try using it without any particular security qualifiers
    > first; if you really need an explicit log on (you probably
    > won't if you're a Domain Admin and using your own or a
    > trusted domain) then you can specify an explicit wmi
    > moniker in the constructor.
    > TJG


    > From Jesse:
    > This is a mixture of NT 4 and Win2K Servers.
    > WMI may not be installed on all the remote systems.


    Does that mean it could not be? It's available for both (and
    is, I think, there by default on Win2K). Maybe there are
    political reasons or fears for stability of long-running
    NT4 servers? We have that problem here.

    > We have quite a few NT domains that our servers are spread out over and
    > sometimes the machine I would execute the script from would not be in
    > the same Domain and need different Logon Credentials to access the
    > remote machine.


    Understood.

    > Often certian services for the applications we maintain will need to be
    > restarted on these remote machines. I've found a way to this this with
    > a Python Module called WService.


    I've not come across this module; is it one you've written yourself?
    Or could you give a URL where it could be found? Assuming, in any case,
    that it's based on Mark Hammond's win32service, a quick browse of the docs
    for that suggest that, although you can control services on other machines,
    there's no way of authenticating yourself in the process.

    Here, I think, WMI would probably serve you best, because it does
    allow explicit domain-credential logons (in a slightly roundabout way),
    and once you're in, stopping and starting services is a snap. Having
    said that, getting the combination of local security and remote
    credentials right is a bit of a pain. Judging by past threads, I
    think other people on this list have more experience of that than I.

    Maybe something like this would suit:

    <code>

    import win32com.client
    import wmi

    def list_services (machine, username, password):
    locator = win32com.client.Dispatch ("WbemScripting.SWbemLocator")
    remote_wmi = locator.ConnectServer (machine, "", username, password)
    remote_machine = wmi.WMI (wmi=remote_wmi)
    #
    # This just lists all services; obviously it
    # could stop, or start, or delete or whatever.
    #
    for s in remote_machine.Win32_Service ():
    print s.Caption, s.State

    </code>

    TJG

    ________________________________________________________________________
    This e-mail has been scanned for all viruses by Star Internet. The
    service is powered by MessageLabs. For more information on a proactive
    anti-virus service working around the clock, around the globe, visit:
    http://www.star.net.uk
    ________________________________________________________________________
    Tim Golden, Aug 28, 2003
    #1
    1. Advertising

  2. Tim Golden

    Jesse Guest

    Tim Golden wrote:

    > [TJG: I've slightly rearranged the posts so they read top-to-bottom]
    >
    >
    >>From: Jesse [mailto:]
    >>
    >>I guess it is how can I have a user enter their NT Domain Authentication
    >>and the script use it to log into NT Domains the computer it is running
    >>on it not a member of.

    >
    >
    >>From Tim:
    >>
    >>I suggest you have a look at WMI.
    >>Try using it without any particular security qualifiers
    >>first; if you really need an explicit log on (you probably
    >>won't if you're a Domain Admin and using your own or a
    >>trusted domain) then you can specify an explicit wmi
    >>moniker in the constructor.
    >>TJG

    >
    >
    >>From Jesse:
    >>This is a mixture of NT 4 and Win2K Servers.
    >>WMI may not be installed on all the remote systems.

    >
    >
    > Does that mean it could not be? It's available for both (and
    > is, I think, there by default on Win2K). Maybe there are
    > political reasons or fears for stability of long-running
    > NT4 servers? We have that problem here.
    >
    >
    >>We have quite a few NT domains that our servers are spread out over and
    >>sometimes the machine I would execute the script from would not be in
    >>the same Domain and need different Logon Credentials to access the
    >>remote machine.

    >
    >
    > Understood.
    >
    >
    >>Often certian services for the applications we maintain will need to be
    >>restarted on these remote machines. I've found a way to this this with
    >>a Python Module called WService.

    >
    >
    > I've not come across this module; is it one you've written yourself?
    > Or could you give a URL where it could be found? Assuming, in any case,
    > that it's based on Mark Hammond's win32service, a quick browse of the docs
    > for that suggest that, although you can control services on other machines,
    > there's no way of authenticating yourself in the process.
    >
    > Here, I think, WMI would probably serve you best, because it does
    > allow explicit domain-credential logons (in a slightly roundabout way),
    > and once you're in, stopping and starting services is a snap. Having
    > said that, getting the combination of local security and remote
    > credentials right is a bit of a pain. Judging by past threads, I
    > think other people on this list have more experience of that than I.
    >
    > Maybe something like this would suit:
    >
    > <code>
    >
    > import win32com.client
    > import wmi
    >
    > def list_services (machine, username, password):
    > locator = win32com.client.Dispatch ("WbemScripting.SWbemLocator")
    > remote_wmi = locator.ConnectServer (machine, "", username, password)
    > remote_machine = wmi.WMI (wmi=remote_wmi)
    > #
    > # This just lists all services; obviously it
    > # could stop, or start, or delete or whatever.
    > #
    > for s in remote_machine.Win32_Service ():
    > print s.Caption, s.State
    >
    > </code>
    >
    > TJG
    >
    > ________________________________________________________________________
    > This e-mail has been scanned for all viruses by Star Internet. The
    > service is powered by MessageLabs. For more information on a proactive
    > anti-virus service working around the clock, around the globe, visit:
    > http://www.star.net.uk
    > ________________________________________________________________________
    >

    The WService is here
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/115875

    I don't believe that all of the NT 4 servers have WMI but I can check
    that. The previous version of the application we had would crap out if
    WMI was running (I don't know why but we saw it happen) But we've since
    then upgraded. I'll continue messing around.

    I really appreciate all the help I'm kinda diving in head first here and
    learning as I go. I try to find an answer online if I can but for this
    I coudn't. Most of my prior programming experience was Batch Files LOL :)
    Jesse, Aug 28, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henrik_the_boss
    Replies:
    0
    Views:
    2,628
    Henrik_the_boss
    Nov 5, 2003
  2. Amratash
    Replies:
    0
    Views:
    499
    Amratash
    Apr 13, 2004
  3. =?Utf-8?B?VG9tIFdpbmdlcnQ=?=

    My.Log.Writeexception not writing to Application Event Log.

    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=, Jan 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,353
    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=
    Jan 20, 2006
  4. Jesse

    Windows Remote Log in

    Jesse, Aug 28, 2003, in forum: Python
    Replies:
    3
    Views:
    289
    Peter Hansen
    Aug 28, 2003
  5. Jesse

    Re: Windows Remote Log in

    Jesse, Aug 28, 2003, in forum: Python
    Replies:
    3
    Views:
    732
    David Bolen
    Sep 1, 2003
Loading...

Share This Page