FAQ
I've created Python COM servers in the past with a fair amount of
success but I can't seem to figure out what I am doing wrong in this
instance.

The only difference that I have found is that in this particular COM
server, I am importing win32net. And after doing some debugging I
have found that the COM server works fine if I remove this import.
This, however I can't do because I need NetUseGetInfo, NetUseAdd,
NetUseDel & NetUseEnum for my Server to function correctly. I've
attached the meat of my code below. If anyone can offer any insight,
I would be extremely grateful. The error that I'm getting is that the
Specified procedure could not be found. When I use Python debugging I
get the error number 2147221231. I've looked in previous posts but
haven't had much luck...

##The splitstring is just here so that I could test the COM server
##without the win32net import. Without the import, it works fine.
##The code itself also works fine before making it a COM server.

import os
from win32net import NetUseGetInfo, NetUseAdd, NetUseDel, NetUseEnum

class ShareControll:
_public_methods_=['QueryDrive','MapDrive','DeleteDrive','SplitString']
_reg_progid_ = "PythonDemos.MW_COM"
_reg_clsid_ = "{1CBECF27-89E4-4E5A-928B-92E11B11B0A9}"
def MapDrive(self, letter, share):
try:
share = u'%s'%share
letter = u'%s'%letter
NetUseAdd(None,1,{'remote': share, 'local': letter})
status = "sucess"
except:
status = "fail"
return status

def DeleteDrive(self, letter):
try:
NetUseDel(None,letter)
status = "sucess"
except:
status = "fail"
return status

def QueryDrive(self, letter):
try:
query = NetUseGetInfo(None,letter)
except:
query = "Drive not in use"
return query

def SplitString(self, val, item=None):
import string
if item != None: item = str(item)
return string.split(str(val), item)

if __name__ == "__main__":
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(ShareControll)

Search Discussions

  • Mark Hammond at Jul 30, 2002 at 11:52 pm

    Emanuel Borges wrote:


    The only difference that I have found is that in this particular COM
    server, I am importing win32net. And after doing some debugging I
    have found that the COM server works fine if I remove this import.
    This, however I can't do because I need NetUseGetInfo, NetUseAdd,
    NetUseDel & NetUseEnum for my Server to function correctly. I've
    win32net uses functions only available on Win NT/2k/XP - you should use
    win32wnet for Win9x.

    Mark.
  • Emanuel Borges at Jul 31, 2002 at 1:38 pm

    win32net uses functions only available on Win NT/2k/XP - you should use
    win32wnet for Win9x.
    Thanks Mark but I am using these functions on a Windows 2000 system.
    The functions themselves work fine. It's when I include them into my
    COM server that gives me errors. If you register this code in your
    registry, do you have the same problems? I'm using VBA in Excel to
    access these methods, if that helps...

    Thanks,
    Emanuel


    Mark Hammond <mhammond at skippinet.com.au> wrote in message news:<3D4726D5.7050001 at skippinet.com.au>...
    Emanuel Borges wrote:

    The only difference that I have found is that in this particular COM
    server, I am importing win32net. And after doing some debugging I
    have found that the COM server works fine if I remove this import.
    This, however I can't do because I need NetUseGetInfo, NetUseAdd,
    NetUseDel & NetUseEnum for my Server to function correctly. I've
    win32net uses functions only available on Win NT/2k/XP - you should use
    win32wnet for Win9x.

    Mark.
  • Mark Hammond at Jul 31, 2002 at 10:58 pm

    Emanuel Borges wrote:
    win32net uses functions only available on Win NT/2k/XP - you should use
    win32wnet for Win9x.

    Thanks Mark but I am using these functions on a Windows 2000 system.
    The functions themselves work fine. It's when I include them into my
    COM server that gives me errors. If you register this code in your
    registry, do you have the same problems? I'm using VBA in Excel to
    access these methods, if that helps...
    That is strange. Can you send me a trivial COM object that demonstrates
    the problem?

    Thanks,

    Mark.
  • Emanuel Borges at Aug 1, 2002 at 3:34 pm
    Thank you for your help.

    I actually learned how to create COM servers from your book. So when
    I couldn't get this one to work, I inserted the "SplitString" method
    from your book because I know that I have once gotten that to work.
    So the code calling the object is the one you had in your book in VBA.
    I've attached it below for reference. As I had said, it works great
    as long as I remove the line importing win32net.
  • Steve Holden at Aug 1, 2002 at 5:40 pm
    "Mark Hammond" <mhammond at skippinet.com.au> wrote in message
    news:3D486BC3.9010607 at skippinet.com.au...
    Emanuel Borges wrote:
    win32net uses functions only available on Win NT/2k/XP - you should use
    win32wnet for Win9x.

    Thanks Mark but I am using these functions on a Windows 2000 system.
    The functions themselves work fine. It's when I include them into my
    COM server that gives me errors. If you register this code in your
    registry, do you have the same problems? I'm using VBA in Excel to
    access these methods, if that helps...
    That is strange. Can you send me a trivial COM object that demonstrates
    the problem?

    If only there *were* such a thing as a "trivial COM object" ...

    irrevernt-ly y'rs - steve
    -----------------------------------------------------------------------
    Steve Holden http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/pwp/
    -----------------------------------------------------------------------
  • Mark Hammond at Aug 1, 2002 at 11:03 pm

    Steve Holden wrote:

    If only there *were* such a thing as a "trivial COM object" ...
    If we weren't talking about Python I would agree with you.
    irrevernt-ly y'rs - steve
    modestly y'rs <wink> - Mark

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 30, '02 at 9:12p
activeAug 1, '02 at 11:03p
posts7
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase