Windows Remote Log in
Tim Golden
tim.golden at viacom-outdoor.co.uk
Thu Aug 28 11:50:51 EDT 2003
[TJG: I've slightly rearranged the posts so they read top-to-bottom]
> From: Jesse [mailto:redrumjack at hotmail.com]
>
>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
________________________________________________________________________
More information about the Python-list
mailing list