I was thinking about just another printer installation script, installing printers depending on the network/subnet during logon. Let us presume a network with just some NT4, and mainly W2K and XP workstations. Also a Terminal server is present. I was thinking about using WTSManager.dll for the terminal sessions and IsInsubnet() to find the subnet (see UDF lib, thanks Jens). The subnet will be found via a select statement. When found, maybe I can use an ini file to install printer(s) and maybe fax and set the default printer. But I am unsure about the structure this ini file should have. I am sure this can be much better. Any reaction or comment that can help to make this script better or to simplify it is welcome. Thanks.
not sure what the fax comment there was... anyways, if you are going to use INI (which would be a good thing), your install printers might look like this: Code:
Function InstallPrinters($IP) dim $subnet, $printer, $ $subnet = moan($IP,"255.255.255.224") for each $printer in split(readprofilestring("theinifile",$subnet),chr(10)) if len($printer) if not primapstate(readprofilestring("theinifile",$subnet,$printer)) $ = addprinterconnection(readprofilestring("theinifile",$subnet,$printer)) endif endif next EndFunction
and your ini would have sections for subnets. the primapstate is not needed but if having large amount of printers and/or users, it should speed up your script a lot.
Thanks for your reply. I already noticed that checking the registry to see if a printer is installed speeds up the script. But it is good to know there is an UDF that can be used. We have multifunctionals that can be used as network fax. You know that these things just install as a network printer.
Just another thought. If it would be possible to catch the Network Address in a variable, in stead of the IP Address, the script would be more flexible and would not have to be adapted as more subnets are created. Also the subnet mask would be of less of no importance. With EnumIPInfo, you can get the IP Address and the subnet mask. In theory, the network address can be calculated. But I do not think this is possible on an NT4 or with WTSManager.dll on a terminal server.
well, my scriptlet does exactly that. you provide the ip and mask and it calculates the subnet. then you have the subnets in the ini and which that same scriptlet reads from. no need to change the script at all at any stage.
Function InstallPrinters($IP) Dim $subnet, $printer, $ $subnet = moan($IP,"255.255.255.224") For Each $printer In Split(ReadProfileString("C:\Script\PrinterScript\Printers.ini",$subnet,""),Chr(10)) ? $Printer If Len($printer) ? "You been here" If NOT primapstate(ReadProfileString("C:\Script\PrinterScript\Printers.ini",$subnet,$printer)) ;$ = AddPrinterConnection(ReadProfileString("C:\Script\PrinterScript\Printers.ini",$subnet,$printer)) ? ReadProfileString("C:\Script\PrinterScript\Printers.ini",$subnet,$printer) ? "You not been here" EndIf EndIf Next EndFunction
I think I am missing something... $Printer is the section...
I am affraid to say that in the script like I modified it as a test, $Printer returns the section. Indeed, I hardcoded the subnet mask, but better would be to get rid of that. EnumIPInfo would enable me to do so, but I do not think I can do this on a Windows NT4 (@IPADDRESS0) and certainly not in a terminal session (WTSManager.dll), as in that case, only the IP address is returned?
oh. you are providing the subnet to the udf. so it fails. MOAN does not like you to play with it's feelings. provide a real IP address as parameter and it will work fine.
Guess you are right I did something completely wrong testing this. As I read in the examples of moan(), I would have to write: moan($IP,,"255.255.255.224") To get the Network Address as return value? Code:
InstallPrinters('10.17.1.33') Function InstallPrinters($IP) Dim $subnet, $printer, $ $subnet = moan($IP,,"255.255.255.224") ? $Subnet EndFunction
ERROR : Error in expression: this type of array not supported in expressions.! Script: D:\Scripts\PrinterScript\Printers.kix Line : 7
Line 7 because there is a "Break On" and a blank line on top of the script
Network ID's and their respective subnet masks are things that are known to me. So if there would be a way I could write an INI that contains - Network ID - Subnet Mask - Printer Share Names (\\server\printer) - Reference to default printer The script itself should just return the IP Address of the computer. From the moment the IP Address of a computer is known, it should be compared to Network ID's and Subnet Masks in the ini file to find the section needed, then all keys and values in that section could be read to install the printers and set the default printer. I think I will take a good night sleep to think about this. Thanks for all your replies. I really like this BBS.
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Well if you know the subnets why don't you just do a comparison of that for the ini file. Strip off whatever is the host portion and off you go. Extremly easy if it is /24 if not I can take any given subnet mask for a given network and provide all of the subnets available.
After two nights of sleep and some testing, this will be my challenge: I am thinking about an INI file like this
To do: Create a function with as parameter the IP Address of the workstation: AddPrinterConnections($IPAddress) Check sections one by one If format section is wrong, check next Check if IP Address is part of network defined in section If error is thrown, set error and check next If IP Address not part of network defined in section, check next If success: - check keys one by one in section - Add printers if not yet installed (set error if thrown) - Install default printer if not yet installed (set error if thrown) - Possible additional reasons for not setting default printer: parallel or usb printer found - Exit function
I guess I'm missing something here with printers. I've worked in a few companies including one with thousands of workers and at none of these places did we automate installing printers for users.
Once a printer is installed (everyone that has probably been at work for more than a few days) then all that should be left is the onesey - twosey printer adds which many users can do on their own, and for those that can't the helpdesk can walk them through it typically in a minute or less, a few minutes at most for the really chatty users.
If you were changing print servers I could see doing some automation, but for stuff that is already probably 95% in place I must ask WHY?
Just seems like there must be other projects and maintenance that would benifit more from your hard work than figuring out some method to automate printer installs for people that mostly already should have their printers installed.