Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do I rename a printer programmatically?
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00151536
Message ID:
00151593
Views:
20
>>Hi all,
>>
>>I need to rename a printer programmatically (any printer from the printers Window in Windows NT). I have tried using the OpenPrinter() and SetPrinter() api functions, but I get errors in VFP. I am now trying to write a C++ program, but I do not know how to convert the 'pPrinter' pointer to a data structure of type PRINTER_INFO_2 in the SetPrinter function.
>>
>>Does anyone know how to do this? Am I on the right track?
>>
>>Thanks in advance,
>>
>
>Hi Maria,
>
>I'm not a C++ programmer, but I do know a little about the API. First, add the winspool.h include file. Second, rather than a PRINTER_INFO_2 structure, which also requires a pointer to a DEVMODE structure, I'd use a PRINTER_INFO_5 structure, which doesn't require this. I'd then use a call to GetPrinter to initialize the structure, then change the name of the printer and send it to SetPrinter.
>
>The only problem that I can see with this is NT. PRINTER_INFO_2 also requires a SECURITY_DESCRIPTOR structure. You can initialize this structure using PRINTER_INFO_2, and a call to GetPrinter, which should give you both this and the DEVMODE structure.

A null pointer for the security descriptor should use the Default SACL for the user for a console app. The user needs to have Server Operator or Admin privileges (either as a Local Administrator or DOmain Admin) to alter the printer name.

>
>Hopefully, someone a bit more fluent in C++ can fill in any holes I've left open.
>
>hth,
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform