join a samba domain

Discussion in 'Python' started by Toff, Dec 22, 2008.

  1. Toff

    Toff Guest

    hi,

    I 'm trying to write a script to make my computer join a samba.

    domeone have any idea ??


    thanks regards,

    *************************************************************************
    # -*- coding: iso-8859-1 *-*

    import win32com.client
    import os,sys
    import win32api
    import impers
    import socket
    from win32com.client import GetObject
    import wmi

    def main():
    test()
    joindom()
    def test():
    import wmi
    c = wmi.WMI()
    os = c.Win32_ComputerSystem
    for method_name in os.methods:
    method = getattr(os, method_name)
    print method

    def joindom():
    #Joining a computer to a domain
    #=========================
    JOIN_DOMAIN = 1
    ACCT_CREATE = 2
    ACCT_DELETE = 4
    WIN9X_UPGRADE = 16
    DOMAIN_JOIN_IF_JOINED = 32
    JOIN_UNSECURE = 64
    MACHINE_PASSWORD_PASSED = 128
    DEFERRED_SPN_SET = 256
    INSTALL_INVOCATION = 262144
    strDomain = "mydom"
    strPassword = "mydompw"
    strUser = "admin"

    strComputer = socket.gethostname()
    print strComputer
    #objComputer = win32com.client.GetObject(r"winmgmts:
    {impersonationLevel=Impersonate}!\\mypc\root
    \cimv2:Win32_ComputerSystem.Name='mypc'")
    import wmi
    c = wmi.WMI()
    d = c.Win32_ComputerSystem
    d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")


    if __name__=='__main__':
    main()
    ***********************************************************************
    Toff, Dec 22, 2008
    #1
    1. Advertising

  2. Toff

    Tim Golden Guest

    Toff wrote:
    > hi,
    >
    > I 'm trying to write a script to make my computer join a samba.
    >
    > domeone have any idea ??


    Ummm. It's not clear if you're saying that your code doesn't
    work, or asking for general advice, or what? I'm not in a
    position to have my machine join a domain or workgroup, but
    you seem to have got most things in place already. The only
    thing I would expect to have to change is this last line:

    > import wmi
    > c = wmi.WMI()
    > d = c.Win32_ComputerSystem
    > d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")


    because the d is only a WMI *class*, not a WMI *instance*,
    so doesn't refer as it should to your computer system but
    to the class of computer systems. Try something like this (untested):

    <code>
    import wmi

    c = wmi.WMI ()
    for d in c.Win32_ComputerSystem ():
    d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")

    </code>

    TJG
    Tim Golden, Dec 22, 2008
    #2
    1. Advertising

  3. Toff

    Toff Guest

    On 22 déc, 17:02, Tim Golden <> wrote:
    > Toff wrote:
    > > hi,

    >
    > > I 'm trying to write a script to make my computer join a samba.

    >
    > > domeone have any idea ??

    >
    > Ummm. It's not clear if you're saying that your code doesn't
    > work, or asking for general advice, or what? I'm not in a
    > position to have my machine join a domain or workgroup, but
    > you seem to have got most things in place already. The only
    > thing I would expect to have to change is this last line:
    >
    > >    import wmi
    > >    c = wmi.WMI()
    > >    d = c.Win32_ComputerSystem
    > >    d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")

    >
    > because the d is only a WMI *class*, not a WMI *instance*,
    > so doesn't refer as it should to your computer system but
    > to the class of computer systems. Try something like this (untested):
    >
    > <code>
    > import wmi
    >
    > c = wmi.WMI ()
    > for d in c.Win32_ComputerSystem ():
    >   d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")
    >
    > </code>
    >
    > TJG

    thanks but it doesn't work
    I've got this errors

    Traceback (most recent call last):
    File "integrdom.py", line 51, in <module>
    main()
    File "integrdom.py", line 13, in main
    joindom()
    File "integrdom.py", line 44, in joindom
    d.JoinDomainOrWorkGroup(None, 3, "domcd", "adminLocal", r"admin
    \domcd")
    File "c:\Python25\Lib\site-packages\wmi.py", line 493, in __getattr__
    handle_com_error (error_info)
    File "c:\Python25\Lib\site-packages\wmi.py", line 189, in
    handle_com_error
    raise x_wmi, "\n".join (exception_string)
    wmi.x_wmi
    Toff, Dec 22, 2008
    #3
  4. Hi!

    If you are under Vista, you must change the LSA parameter.
    See:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
    LMCompatibilityLevel
    try with value 1 or 0


    And use a Samba not too old.


    @-salutations
    --
    Michel Claveau
    Méta-MCI \(MVP\), Dec 22, 2008
    #4
  5. Toff

    Tim Golden Guest

    Toff wrote:
    > On 22 déc, 17:02, Tim Golden <> wrote:
    >> Toff wrote:
    >>> hi,
    >>> I 'm trying to write a script to make my computer join a samba.
    >>> domeone have any idea ??

    >> Ummm. It's not clear if you're saying that your code doesn't
    >> work, or asking for general advice, or what? I'm not in a
    >> position to have my machine join a domain or workgroup, but
    >> you seem to have got most things in place already. The only
    >> thing I would expect to have to change is this last line:
    >>
    >>> import wmi
    >>> c = wmi.WMI()
    >>> d = c.Win32_ComputerSystem
    >>> d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")

    >> because the d is only a WMI *class*, not a WMI *instance*,
    >> so doesn't refer as it should to your computer system but
    >> to the class of computer systems. Try something like this (untested):
    >>
    >> <code>
    >> import wmi
    >>
    >> c = wmi.WMI ()
    >> for d in c.Win32_ComputerSystem ():
    >> d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")
    >>
    >> </code>
    >>
    >> TJG

    > thanks but it doesn't work
    > I've got this errors
    >
    > Traceback (most recent call last):
    > File "integrdom.py", line 51, in <module>
    > main()
    > File "integrdom.py", line 13, in main
    > joindom()
    > File "integrdom.py", line 44, in joindom
    > d.JoinDomainOrWorkGroup(None, 3, "domcd", "adminLocal", r"admin
    > \domcd")
    > File "c:\Python25\Lib\site-packages\wmi.py", line 493, in __getattr__
    > handle_com_error (error_info)
    > File "c:\Python25\Lib\site-packages\wmi.py", line 189, in
    > handle_com_error
    > raise x_wmi, "\n".join (exception_string)
    > wmi.x_wmi



    Do you not get *anything* after than wmi.x_wmi? Not even
    a messy exception string?

    TJG
    Tim Golden, Dec 22, 2008
    #5
  6. Toff

    Toff Guest

    On 22 déc, 17:57, Tim Golden <> wrote:
    > Toff wrote:
    > > On 22 déc, 17:02, Tim Golden <> wrote:
    > >> Toff wrote:
    > >>> hi,
    > >>> I 'm trying to write a script to make my computer join a samba.
    > >>> domeone have any idea ??
    > >> Ummm. It's not clear if you're saying that your code doesn't
    > >> work, or asking for general advice, or what? I'm not in a
    > >> position to have my machine join a domain or workgroup, but
    > >> you seem to have got most things in place already. The only
    > >> thing I would expect to have to change is this last line:

    >
    > >>>    import wmi
    > >>>    c = wmi.WMI()
    > >>>    d = c.Win32_ComputerSystem
    > >>>    d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")
    > >> because the d is only a WMI *class*, not a WMI *instance*,
    > >> so doesn't refer as it should to your computer system but
    > >> to the class of computer systems. Try something like this (untested):

    >
    > >> <code>
    > >> import wmi

    >
    > >> c = wmi.WMI ()
    > >> for d in c.Win32_ComputerSystem ():
    > >>   d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")

    >
    > >> </code>

    >
    > >> TJG

    > > thanks but it doesn't work
    > > I've got this errors

    >
    > > Traceback (most recent call last):
    > >  File "integrdom.py", line 51, in <module>
    > >    main()
    > >  File "integrdom.py", line 13, in main
    > >    joindom()
    > >  File "integrdom.py", line 44, in joindom
    > >    d.JoinDomainOrWorkGroup(None, 3, "domcd", "adminLocal", r"admin
    > > \domcd")
    > >  File "c:\Python25\Lib\site-packages\wmi.py", line 493, in __getattr__
    > >    handle_com_error (error_info)
    > >  File "c:\Python25\Lib\site-packages\wmi.py", line 189, in
    > > handle_com_error
    > >    raise x_wmi, "\n".join (exception_string)
    > > wmi.x_wmi

    >
    > Do you not get *anything* after than wmi.x_wmi? Not even
    > a messy exception string?
    >
    > TJG


    no pessy string

    something strange:

    import wmi
    c = wmi.WMI()
    os = c.Win32_ComputerSystem
    for method_name in os.methods:
    method = getattr(os, method_name)
    print method

    it doesn't give the same parameter order for JoinDomainOrWorkGroup
    than MSDN doc
    Toff, Dec 22, 2008
    #6
  7. Toff wrote:
    > d = c.Win32_ComputerSystem
    > d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")

    Shouldn't r"admin\\mydom" be "admin\\mydom" or r"admin\mydom".
    Or maybe just "admin"

    /Jens Henrik
    Jens Henrik Leonhard Jensen, Dec 22, 2008
    #7
  8. Toff

    Toff Guest

    On 22 déc, 18:59, Jens Henrik Leonhard Jensen
    <> wrote:
    > Toff wrote:
    > >    d = c.Win32_ComputerSystem
    > >    d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")

    >
    > Shouldn't r"admin\\mydom" be "admin\\mydom" or r"admin\mydom".
    > Or maybe just "admin"
    >
    > /Jens Henrik


    you are right but i've got the same error.
    Toff, Dec 22, 2008
    #8
  9. Toff

    Toff Guest

    On 22 déc, 19:37, Toff <> wrote:
    > On 22 déc, 18:59, Jens Henrik Leonhard Jensen
    >
    > <> wrote:
    > > Toff wrote:
    > > >    d = c.Win32_ComputerSystem
    > > >    d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")

    >
    > > Shouldn't r"admin\\mydom" be "admin\\mydom" or r"admin\mydom".
    > > Or maybe just "admin"

    >
    > > /Jens Henrik

    >
    > you are right but i've got the same error.


    the more i look at my script the more i think it s a BUG.

    #ALL works great
    import wmi
    c = wmi.WMI()
    for computer in c.Win32_ComputerSystem():
    if computer.PartOfDomain:
    print computer.Domain #DOMCD
    print computer.SystemStartupOptions # (u'"Microsoft Windows XP
    Professionnel" /noexecute=optin /fastdetect',)

    #error message
    computer.JoinDomainOrWorkGroup('DOMCD', 'adminLocal', 'admin\
    \DOMCD',None,3 )


    ##############
    DOMCD
    (u'"Microsoft Windows XP Professionnel" /noexecute=optin /
    fastdetect',)
    Traceback (most recent call last):
    File "integrdom.py", line 51, in <module>
    main()
    File "integrdom.py", line 13, in main
    joindom()
    File "integrdom.py", line 47, in joindom
    computer.JoinDomainOrWorkGroup('DOMCD', 'adminLocal', 'admin\
    \DOMCD',None,3
    )
    File "c:\Python25\Lib\site-packages\wmi.py", line 493, in
    __getattr__
    handle_com_error (error_info)
    File "c:\Python25\Lib\site-packages\wmi.py", line 189, in
    handle_com_error
    raise x_wmi, "\n".join (exception_string)
    wmi.x_wmi
    Toff, Dec 23, 2008
    #9
  10. Toff

    Toff Guest

    Or maybe could I try with
    LoadLibrary("netapi32.dll");
    and the netjoindomain function ?

    but it doesn't look very easy ....
    Toff, Dec 23, 2008
    #10
  11. Toff

    Tim Golden Guest

    Toff wrote:
    > On 22 déc, 19:37, Toff <> wrote:
    >> On 22 déc, 18:59, Jens Henrik Leonhard Jensen
    >>
    >> <> wrote:
    >>> Toff wrote:
    >>>> d = c.Win32_ComputerSystem
    >>>> d.JoinDomainOrWorkGroup(None, 3, "mydom", "mydompw", r"admin\\mydom")
    >>> Shouldn't r"admin\\mydom" be "admin\\mydom" or r"admin\mydom".
    >>> Or maybe just "admin"
    >>> /Jens Henrik

    >> you are right but i've got the same error.

    >
    > the more i look at my script the more i think it s a BUG.
    >
    > #ALL works great
    > import wmi
    > c = wmi.WMI()
    > for computer in c.Win32_ComputerSystem():
    > if computer.PartOfDomain:
    > print computer.Domain #DOMCD
    > print computer.SystemStartupOptions # (u'"Microsoft Windows XP
    > Professionnel" /noexecute=optin /fastdetect',)
    >
    > #error message
    > computer.JoinDomainOrWorkGroup('DOMCD', 'adminLocal', 'admin\
    > \DOMCD',None,3 )



    Try: computer.JoinDomainOrWorkgroup (...)

    note the lowercase "group"

    TJG
    Tim Golden, Dec 23, 2008
    #11
    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. jon wackley

    iis 5 virtual directory on samba share

    jon wackley, Dec 29, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,873
    jon wackley
    Dec 30, 2003
  2. Neil Zanella

    ASP.NET service providers using Samba+Unix

    Neil Zanella, Jan 5, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    372
    Brandon Potter
    Jan 6, 2005
  3. Rob@Bedford
    Replies:
    4
    Views:
    7,105
    brunasti
    Dec 6, 2007
  4. Alan Silver
    Replies:
    0
    Views:
    864
    Alan Silver
    Jun 5, 2006
  5. googleboy
    Replies:
    1
    Views:
    902
    Benji York
    Oct 1, 2005
Loading...

Share This Page