Re: Python script to install network printers

2005-10-05 Thread future_retro
These functions should get you started and probably finished...

def createprinterport(IPAddress,ServerName):
WBEM =
win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\"
+ ServerName + r"\root\cimv2")
WBEM.Security_.Privileges.AddAsString("SeLoadDriverPrivilege")
printerport = WBEM.Get("Win32_TCPIPPrinterPort").SpawnInstance_()
printerport.Properties_('Name').Value = 'IP_'+IPAddress
printerport.Properties_('Protocol').Value = 1
printerport.Properties_('HostAddress').Value = IPAddress
printerport.Properties_('PortNumber').Value = '9100'
printerport.Properties_('SNMPEnabled').Value = 'False'
printerport.Put_()

def
createprinter(PrinterName,DriverName,Location,ShareName,IPAddress,ServerName):
WBEM =
win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\"
+ ServerName + r"\root\cimv2")
WBEM.Security_.ImpersonationLevel = 3
WBEM.Security_.Privileges.AddAsString("SeLoadDriverPrivilege")
printer = WBEM.Get("Win32_Printer").SpawnInstance_()
printer.Properties_('DeviceID').Value = PrinterName
printer.Properties_('DriverName').Value = DriverName
printer.Properties_('Location').Value = Location
printer.Properties_('Network').Value = 'True'
printer.Properties_('Shared').Value = 'True'
printer.Properties_('ShareName').Value = ShareName
printer.Properties_('PortName').Value = 'IP_'+IPAddress
printer.Put_()

I also created one for migrating print drivers but had loads of
problems with it.  If the driver doesn't pass Microsoft logo testing
the scripts fail even if it is signed by Microsoft.  I never worked out
why there were 2 levels of protection.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python script to install network printers

2005-10-05 Thread future_retro
The target OS needs to support WMI so 2000 or XP.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python create WMI instances

2005-06-22 Thread future_retro
Create isn't a method of Win32_Printer so I couldn't get that to work.
.Create is a method of Win32_Process which (wait for it..) creates a
new process.  Unfortunatly there is no method to add a printer.  the
method .AddPrinterConnection will allow me to add a connection to an
existing print share but I want to create a printer with the option of
sharing it.

I think I'll have to do this with spawninstance.





Tim Golden wrote:
> [Marc Wyburn]
> |
> | Hi all, I am struggling with a vb - python code conversion.  I'm using
> | WMI to create printers on remote machines using (in VB);
> |
> | set oPrinter = oService.Get("Win32_Printer").SpawnInstance_
> |
> | oPrinter.DriverName = strDriver
> | oPrinter.PortName   = strPort
> | oPrinter.DeviceID   = strPrinter
> | oPrinter.Put_(kFlagCreateOnly)
> |
> | In python I have logged onto the WMI service on the remote machine and
> | I can run things like c.new.AddPrinterConnection so I know that I am
> | connected and working OK.  I don't get any errors when I create a new
> | object with SpawnInstance_ but when I try to set the value of
> | oPrinter.Drivername I get an error saying that the Drivername object
> | doesn't exist.  Does anyone know how to set the values of the object
> | using either the method above or with the WMI module?  I think the WMI
> | module only allows access to modify methods such ADDPrinterConnection
> | or Create (from Win32_Service).
>
> Not sure if I can help here or not, but just in case...
>
> As far as I understand you, the fact that you're creating
> on a remote machine is just an incidental, ie you'd have
> the same problem doing this locally.
>
> Part of the problem is that when VB does something
> like:
>
> oPrinter.DriverName = strDriver
>
> what's really happening behind the scenes is something
> like:
>
> oPrinter.Properties_ ("DriverName").Value = strDriver
>
> Now you can do that in Python. (In fact, that's what
> the wmi module does when it overrides __setattr__, followed
> by a Put_). So if you want to translate code fairly literally,
> then carry on as you were, but substitute the latter code for
> the former.
>
> Having said that, the wmi module *can* create new instances
> of classes. The problem is that I had/have little knowledge
> of how WMI works in this area, so what I've done may not
> be right. The method you're looking for is .new (aliased
> as .new_instance_of) and if you use help on that method,
> you'll get this:
>
> new(self, wmi_class) unbound wmi.WMI method
> Create a new , typically something like
> Win32_Process, eg:
>
> c = wmi.WMI ("remote_machine")
> for p in c.Win32_Process (name="notepad.exe"): print p
> c.new ("Win32_Process").Create (CommandLine="notepad.exe")
> for p in c.Win32_Process (name="notepad.exe"): print p
> p.Terminate ()
> for p in c.Win32_Process (name="notepad.exe"): print p
>
> Now this example works, but I notice from the code
> that what I did to make it work was to remove the
> SpawnInstance_ which I had, and replace it by an
> instance retrieval. ie I just do a Get on the class.
>
> I'll try to find some examples around of what you're
> doing which, up till now, I've not really needed to
> do. Meanwhile, I hope the above info is of some use.
>
> Feel free to respond with questions or comments. This
> can only get clearer!
>
> TJG
>
> 
> This e-mail has been scanned for all viruses by Star. 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
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python create WMI instances

2005-06-22 Thread future_retro
Win32_Printer doesn't work with the Create method and
AddPrinterConnection only lets me add a connection to a share.  I'll
try and work out how to set the printer object properties in the format
suggested;

oPrinter.Properties_ ("DriverName").Value = strDriver 

Cheers, MW.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python create WMI instances

2005-06-23 Thread future_retro
I've got as far as this.  I don't get any errors but still no
printer

>>> import win32com.client
>>> WBEM = 
>>> win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\" + 
>>> "." + r"\root\cimv2")
>>> printer = WBEM.Get("Win32_Printer").SpawnInstance_()
>>> printer.Properties_('DeviceID').Value = 'myprinter'
>>> printer.Properties_('DriverName').Value = 'HP 2000C'
>>> printer.Properties_('Location').Value = 'myoffice'
>>> printer.Properties_('Network').Value = 'True'
>>> printer.Properties_('Shared').Value = 'True'
>>> printer.Properties_('ShareName').Value = 'myprintershare'
>>> printer.Put_

Do I need to specify any flags with Put_  ?

Thanks for all your help, I can almost taste victory!

MW.

Tim Golden wrote:
> [EMAIL PROTECTED]
> | Win32_Printer doesn't work with the Create method and
> | AddPrinterConnection only lets me add a connection to a share.  I'll
> | try and work out how to set the printer object properties in
> | the format
> | suggested;
> |
> | oPrinter.Properties_ ("DriverName").Value = strDriver
> |
> | Cheers, MW.
>
> I'm sorry my module won't have been much use to you
> in this, but it would be *really* helpful if you
> could post [a fragment of] the code you come up with
> so I can see what changes I need to make to help our
> future instance-spawners. It's just that I've never
> had the need to do this, and don't have any time to
> experiment at present.
>
> Thanks
> TJG
>
> 
> This e-mail has been scanned for all viruses by Star. 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
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python create WMI instances

2005-06-23 Thread future_retro
Right I got it working.  I had to put a printer port in aswell.  I'll
now look at a script to create printer ports.  My goal is being able to
query the printers on print server x and then recreate the printers
(shares and ports) on print server y.

Thanks, for all your help Tim, much appreciated. MW

import win32com.client
WBEM =
win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\"
+ "." + r"\root\cimv2")
printer = WBEM.Get("Win32_Printer").SpawnInstance_()
printer.Properties_('DeviceID').Value = 'myprinter'
printer.Properties_('DriverName').Value = 'HP 2000C'
printer.Properties_('Location').Value = 'myoffice'
printer.Properties_('Network').Value = 'True'
printer.Properties_('Shared').Value = 'True'
printer.Properties_('ShareName').Value = 'myprintershare'
printer.Properties_('PortName').Value = 'IP_169.254.110.14'
printer.Put_()

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python create WMI instances

2005-06-23 Thread future_retro
Heres a script for creating printer ports

import win32com.client
WBEM =
win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\"
+ "." + r"\root\cimv2")
printer = WBEM.Get("Win32_Printer").SpawnInstance_()
printer.Properties_('DeviceID').Value = 'myprinter'
printer.Properties_('DriverName').Value = 'HP 2000C'
printer.Properties_('Location').Value = 'myoffice'
printer.Properties_('Network').Value = 'True'
printer.Properties_('Shared').Value = 'True'
printer.Properties_('ShareName').Value = 'myprintershare'
printer.Properties_('PortName').Value = 'IP_169.254.110.14'
printer.Put_()

-- 
http://mail.python.org/mailman/listinfo/python-list


accessing individual element in a list.

2005-07-01 Thread future_retro
hi all,could someone clear this up for me.  I'm sure it's probably very
simple but I can't seem to get my head round it.

doing the following

>>> import wmi
>>> c = wmi.WMI()
>>> for printdriver in c.Win32_PrinterDriver():
... pd = printdriver.Name
>>> print pd
AGFA-AccuSet v52.3,3,Windows NT x86
>>> pd[1]
u'G'
>>> pd.split(',')
[u'AGFA-AccuSet v52.3', u'3', u'Windows NT x86']
>>> pd[0]
u'A'

why does pd[1] or pd[0] not return an element from the list instead of
a character from the string?  Is split the best method to try and
seperate the individual elements?

Thanks, MW.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: accessing individual element in a list.

2005-07-01 Thread future_retro
the square brackets round the output of split got me.  Have plit into a
new list and all works as expeted. Cheers, MW.

-- 
http://mail.python.org/mailman/listinfo/python-list


exec method WMI

2005-07-13 Thread future_retro
Hi, I'm trying to use the AddPrinterDriver method of
Win32_PrinterDriver to create a new. print driver.  I can't get my
head round how I need to do this.  So far I have

import win32com.client
WBEM =
win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\"
+ "." + r"\root\cimv2")
WBEM.Security_.Privileges.AddAsString("SeLoadDriverPrivilege")
drv = WBEM.Get("Win32_PrinterDriver").SpawnInstance_()
drv.Properties_('Name').Value = "Marcs Printer 2550"
drv.Properties_('SupportedPlatform').Value = "Windows NT x86"
drv.Properties_('Version').Value = "3"
drv.Properties_('DriverPath').Value = 'C:\\test\\HPZPP034.DLL'
drv.Properties_('InfName').Value = 'C:\\test\\hpc2550d.inf'
method = drv.Methods_('AddPrinterDriver')
InParms = method.InParameters
InParms.Properties_.Item('DriverInfo').Value = drv
drv.ExecMethod_('AddPrinterDriver',InParms)

I'm using spawninstance to create a new object and then editing the
properties of it.  I'm then setting the InParameters for the method to
be the new object.  When executing the method I get SWbemObjectEx
object not found.

I think I am not setting the DriverInfo correctly, should it be an
object?  The MSDN site doesn't say what DriverInfo should be.

Any help would be grand.

Thanks, MW.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exec method WMI

2005-07-14 Thread future_retro
Got it working, removed spawninstance and the driver path should have
been "C:\\test\\"

Cheers for your help Roger.

-- 
http://mail.python.org/mailman/listinfo/python-list


RegUnloadkey access denied

2005-07-22 Thread future_retro
In the following script I can't get the reg key to unload.  Anyone got
any ideas?  I can load and save the key without any problems.  I can
unload the key from regedit and have checked security on the key.  The
docs don't mention any special privileges are needed
(SeRestorePrivilege should do it).  I'm stumped.  Cheers peeps, MW.

import ntsecuritycon
import win32security
import win32api
import _winreg
import win32con

flags = ntsecuritycon.TOKEN_ADJUST_PRIVILEGES |
ntsecuritycon.TOKEN_QUERY
htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(),
flags)
Loadid = win32security.LookupPrivilegeValue(None, 'SeRestorePrivilege')
#Saveid = win32security.LookupPrivilegeValue(None, 'SeBackupPrivilege')
LoadPrivilege = [(Loadid, ntsecuritycon.SE_PRIVILEGE_ENABLED)]
#SavePrivilege = [(Saveid, ntsecuritycon.SE_PRIVILEGE_ENABLED)]
win32security.AdjustTokenPrivileges(htoken, 0, LoadPrivilege)
#win32security.AdjustTokenPrivileges(htoken, 0, SavePrivilege)

key = _winreg.HKEY_USERS
hkey = win32api.RegLoadKey(key,'Marc','c:\\ntuser.dat')
okey =
win32api.RegOpenKeyEx(key,'Marc\\test',0,win32con.KEY_ALL_ACCESS)
win32api.RegSetValueEx(okey,'test',0,_winreg.REG_DWORD,0)
#win32api.RegSaveKey(okey,'c:\\ntuser2.dat',None)
#win32api.RegFlushKey(_winreg.HKEY_USERS)
win32api.RegUnLoadKey(key,'Marc')

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RegUnloadkey access denied

2005-07-22 Thread future_retro
I've worked out that I can open and close the key fine if I don't open
a subkey.  I've tried adding flush and close statements after opening
the key and still get access denied when trying to unload.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RegUnloadkey access denied

2005-07-22 Thread future_retro
solved it!

I need to close the key first

import ntsecuritycon
import win32security
import win32api
import _winreg
import win32con

flags = ntsecuritycon.TOKEN_ADJUST_PRIVILEGES |
ntsecuritycon.TOKEN_QUERY
htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(),
flags)
Loadid = win32security.LookupPrivilegeValue(None, 'SeRestorePrivilege')
Saveid = win32security.LookupPrivilegeValue(None, 'SeBackupPrivilege')
LoadPrivilege = [(Loadid, ntsecuritycon.SE_PRIVILEGE_ENABLED)]
SavePrivilege = [(Saveid, ntsecuritycon.SE_PRIVILEGE_ENABLED)]
win32security.AdjustTokenPrivileges(htoken, 0, LoadPrivilege)
win32security.AdjustTokenPrivileges(htoken, 0, SavePrivilege)

key = _winreg.HKEY_USERS
hkey = win32api.RegLoadKey(key,'Marc','c:\\ntuser.dat')
okey = win32api.RegOpenKeyEx(key,'Marc\\test',0,win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(okey,'test',0,_winreg.REG_DWORD,0)
win32api.RegCloseKey(okey)
win32api.RegUnLoadKey(key,'Marc')

-- 
http://mail.python.org/mailman/listinfo/python-list


wmi addprinterdriver for remote PC

2005-08-03 Thread future_retro
Hi all, cannot work this one out at all...

import win32com.client
WBEM =
win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\"
+ servername + r"\root\cimv2")
WBEM.Security_.Privileges.AddAsString("SeLoadDriverPrivilege")
drv = WBEM.Get("Win32_PrinterDriver")
drv.Properties_('Name').Value = "HP Color LaserJet 8550 PCL 5C"
drv.Properties_('SupportedPlatform').Value = "Windows NT x86"
drv.Properties_('Version').Value = "3"
drv.Properties_('DriverPath').Value =
"C:\\Printdrivers\\clj8550pcl5cwin2kxp"
drv.Properties_('InfName').Value =
"C:\\Printdrivers\\clj8550pcl5cwin2kxp\\hpbf401i.inf"
method = drv.Methods_('AddPrinterDriver')
InParms = method.InParameters
InParms.Properties_.Item('DriverInfo').Value = drv
drv.ExecMethod_('AddPrinterDriver',InParms)

If servername is "." the driver loads.  If it is a remote machine the
script runs without any errors but no printerdriver is created.  As far
as can tell its not a privilege issue and when running through
pythonwin it looks like the object is created but it doesn't show up in
server properties.  It also runs too quickly so I'm pretty sure its not
doing anything.  I've tried different drivers but no joy.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wmi addprinterdriver for remote PC

2005-08-03 Thread future_retro
soz I missed the glaring error.  The file paths need to be to a UNC
location of have to exist on the remote PC.

-- 
http://mail.python.org/mailman/listinfo/python-list


RasAdminUserGetInfo

2005-12-19 Thread future_retro
Anyone got any idea how to use this?  It looks like it isn't available
directly from the win32 extensions.

Thanks, MW.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RasAdminUserGetInfo

2005-12-19 Thread future_retro
I got that far but the RasAdminUserGetInfo function isn't defined in
win32net (or anywhere else as far as I can work out).  Is there a way
to use it without the win32 module?  This is the first thing I haven't
been able to do with win32net so I'm a little stumped on where the road
goes from here..MW.

-- 
http://mail.python.org/mailman/listinfo/python-list