text file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yqyq22@hotmail.com

    text file

    HI all,
    i have some problem with the code belove, i have a list of servers in
    a textfile (elencopc.txt). ... i would to retrieve informations via WMI
    ( cicle for ), but i don't understand if the code is correct:

    import win32com.client
    import string
    import sys
    listserver = open('c:\\elenc opc.txt','r')
    objWMIService = win32com.client .Dispatch("Wbem Scripting.SWbem Locator")
    objSWbemService s = objWMIService.C onnectServer(li stserver,"root
    \cimv2")
    colItems = objSWbemService s.ExecQuery("Se lect * from
    Win32_QuickFixE ngineering")
    for objItem in colItems:
    print "Caption: ", objItem.Caption
    print "Descriptio n: ", objItem.Descrip tion
    print "Fix Comments: ", objItem.FixComm ents
    print "HotFix ID: ", objItem.HotFixI D
    print "Install Date: ", objItem.Install Date
    print "Installed By: ", objItem.Install edBy
    print "Installed On: ", objItem.Install edOn
    print "Name: ", objItem.Name
    print "Service Pack In Effect: ", objItem.Service PackInEffect
    print "Status: ", objItem.Status

    I receive the error :
    ile "C:\Python25\Li b\site-packages\win32c om\client\dynam ic.py", line
    258, in _ApplyTypes_
    result = self._oleobj_.I nvokeTypes(*(di spid, LCID, wFlags,
    retType, argTypes) + args)
    com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemLocator',
    'The RPC server is unavailable. ', None, 0, -2147023174), None)

    MY big dubt is if the code is correct... because if i use vbscript all
    works fine..
    thanks a lot in advance
  • yqyq22@hotmail.com

    #2
    Re: text file

    On Oct 1, 4:03 pm, yqy...@hotmail. com wrote:
    HI all,
    i have some problem with the code belove, i have a list of servers in
    a textfile (elencopc.txt). ... i would to retrieve informations via WMI
    ( cicle for ), but i don't understand if the code is correct:
    >
    import win32com.client
    import string
    import sys
    listserver = open('c:\\elenc opc.txt','r')
    objWMIService = win32com.client .Dispatch("Wbem Scripting.SWbem Locator")
    objSWbemService s = objWMIService.C onnectServer(li stserver,"root
    \cimv2")
    colItems = objSWbemService s.ExecQuery("Se lect * from
    Win32_QuickFixE ngineering")
    for objItem in colItems:
        print "Caption: ", objItem.Caption
        print "Descriptio n: ", objItem.Descrip tion
        print "Fix Comments: ", objItem.FixComm ents
        print "HotFix ID: ", objItem.HotFixI D
        print "Install Date: ", objItem.Install Date
        print "Installed By: ", objItem.Install edBy
        print "Installed On: ", objItem.Install edOn
        print "Name: ", objItem.Name
        print "Service Pack In Effect: ", objItem.Service PackInEffect
        print "Status: ", objItem.Status
    >
    I receive the error :
    ile "C:\Python25\Li b\site-packages\win32c om\client\dynam ic.py", line
    258, in _ApplyTypes_
        result = self._oleobj_.I nvokeTypes(*(di spid, LCID, wFlags,
    retType, argTypes) + args)
    com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemLocator',
    'The RPC server is unavailable. ', None, 0, -2147023174), None)
    >
    MY big dubt is if the code is correct... because if i use vbscript all
    works fine..
    thanks a lot in advance
    My problem is how to translate this vbs in python:

    Dim fso
    Dim strComputer
    Set fso = CreateObject("S cripting.FileSy stemObject")
    Set ElencoPC = fso.OpenTextFil e("elencoPC.txt " , 1, False)
    Do Until ElencoPC.AtEndO fStream
    strComputer = ElencoPC.ReadLi ne

    thanks

    Comment

    • Lie Ryan

      #3
      Re: text file

      On Wed, 01 Oct 2008 07:19:44 -0700, yqyq22 wrote:
      My problem is how to translate this vbs in python:
      >
      Dim fso
      Dim strComputer
      Set fso = CreateObject("S cripting.FileSy stemObject") Set ElencoPC =
      fso.OpenTextFil e("elencoPC.txt " , 1, False) Do Until
      ElencoPC.AtEndO fStream
      strComputer = ElencoPC.ReadLi ne
      >
      thanks
      try this:

      fso = open('elencoPC. txt', 'r')
      for line in f:
      strComputer = line


      Comment

      • Tim Golden

        #4
        Re: text file

        yqyq22@hotmail. com wrote:
        HI all,
        i have some problem with the code belove, i have a list of servers in
        a textfile (elencopc.txt). ... i would to retrieve informations via WMI
        ( cicle for ), but i don't understand if the code is correct:

        Try this, using http://timgolden.me.uk/python/wmi.html :

        <code>
        import wmi

        #
        # For the test to work
        #
        open ("elencopc.txt" , "w").write ("localhost" )

        for server in open ("elencopc.txt" ).read ().splitlines ():
        c = wmi.WMI (server)
        print "SERVER:", server
        for item in c.Win32_QuickFi xEngineering ():
        print item # or print item.Caption, etc.
        print
        print

        </code>

        If you get RPC Server unavailable, it usually means that
        the WMI service isn't running on that machine. Usually.

        TJG

        Comment

        Working...