[SOLVED] Package with absolute path requirement.

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
LMS
Messages: 5
Registration: June 3, 2020 - 11:22

June 9, 2020 - 5:22 PM

Hello,

I'm following up on my first post: viewtopic.php?f=9&t=2389 , regarding creating a printer.

The script suggested by sfonteneau works. However, there's no configuration, and my driver, by default, chooses an unbelievable format (8.5 x 11").

So I wanted to configure it, but these settings aren't readily available (or I'm just not good at searching). I did manage to find a solution by exporting and then importing a configuration using the command:
- RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry /Ss /n "Schumann copier 5th floor" /a C:\A4-format.dat
- RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry /Sr /n "Schumann copier 5th floor" /a C:\A4-format.dat
Edit: Note: Of course, I only perform the export once, on a machine that's already configured, to get the basic configuration. Then I try to reproduce the import with /Sr using a package. wapt.


However, the command only works during import when we have an absolute path. The test below leads me to this conclusion:
When I'm in my command prompt at c:> and I type the option /a 'A4-format.dat', the operation fails and stops, but with /a 'C:/A4-format.dat' it works, and when checking the printer properties, the format has indeed changed. The result is the same whether the command prompt window is launched as administrator or not.

My question is:
- Have I misunderstood something in the execution of printui.exe? Do you have any documentation on how to directly assign the printer settings, rather than relying on a configuration file?
- If I understand correctly, what solution should I recommend?
- There is a folder on the client computer, for each wapt package, which could be pointed to with an absolute path that would therefore not change for each Workstation?
- Should we use a network share to store the source files?
- Another solution? (Use a command to copy the .dat source file to the client workstations, for example to c:/source_wapt/fichier.dat, then set the new absolute path, thus avoiding a general configuration, but using a general script.)
User avatar
dcardon
WAPT Expert
Messages: 1932
Registration: June 18, 2014 - 09:58
Location: Saint Sébastien sur Loire
Contact :

June 9, 2020 - 9:44 PM

The package is unzipped into a temporary directory with a random name. You can retrieve the path to the directory where it is unzipped using the `basedir` variable.
Denis Cardon - Tranquil IT
Share your experiences on WAPT! Send us your blog and article URLs in the "Your Opinion of the forum, and we'll feature them on the WAPT
LMS
Messages: 5
Registration: June 3, 2020 - 11:22

June 11, 2020 - 11:06

Thanks, the basedir variable is great.

However, ultimately, that doesn't seem to be the main problem.

In my script, which I largely borrowed from sfonteneau for the printer creation, here are the two active lines:

- Installed the "Schumann Copier 5th floor" printer. Works without any problems.
run(ur'rundll32 printui.dll,PrintUIEntry /if /b "%s" /f %s /r "IP_%s" /m "%s" ' % (nameprinter,path_driver,portprint,name_drivers))

- Supposed to import the "printer-format.dat" printer settings into the Schumann copier/printer. Does not work from PyScripter.
run(u'printui.exe /Sr /n "Schumann copier 5th floor" /a /f %s\printer-format.dat' %(basedir))
So I tried a /f which changed nothing, and added the full path with basedir. Nothing changed.

However, as a reminder, there are no problems using CMD directly, with the same files and the same paths. Or rather, not quite:
When I build the package and push it to my local repository, then try to modify it, and run a command to the printer-format.dat file, it says "unable to complete the operation" (for the import). So I export to overwrite the file, and import it again, and then it works.

I have a feeling this might be related to a Windows security issue. I've encountered many errors like this while creating my packages. Sometimes I find workarounds that seem more like hacks (using batch files or PowerShell) than legitimate fixes.

In short, I'm going in circles and don't understand the error codes being returned. Do you have any tips for improving my understanding of them?
For your information, here is my install function:

Code: Select all

def install():

    if iswin64():
        path_driver = r"IT5DSETWin_10110FR\Drivers\PCL6\Win_x64\KOAXTJ__.INF"
        name_drivers = "KONICA MINOLTA C287SeriesPCL"
    else:
        path_driver = r"IT5DSETWin_10110FR\Drivers\PCL6\Win_x86\KOAXTJ__.inf"
        name_drivers = "KONICA MINOLTA C287SeriesPCL"



    # Delete old printer
    run_notfatal('rundll32 printui.dll,PrintUIEntry /n "%s" /dl /q ' % nameprinter)

    # Create port lpr or raw
    createprinterport_raw(portprint)

    # use create lpr if needed
    #createprinterport_lpr(portprint,'qu')

    # Install printer and drivers
    run(ur'rundll32 printui.dll,PrintUIEntry /if /b "%s" /f %s /r  "IP_%s" /m "%s" ' % (nameprinter,path_driver,portprint,name_drivers))

    run(u'printui.exe /Sr /n "Copieur schumann 5eme etage" /a /f %s\printer-format.dat' %(basedir))
Here is the error code when I run an "install" command in PyScripter:

Code: Select all

2020-06-11 10:51:51,466 CRITICAL Fatal error in install script: CalledProcessErrorOutput: Command 'printui.exe /Sr /n "Copieur schumann 5eme etage" /a /f c:\\waptdev\\wapt_av-5thFloor-printer-wapt\\printer-format.dat' returned non-zero exit status 1.
Output::
Traceback (most recent call last):
  File "C:\Program Files (x86)\wapt\common.py", line 3800, in install_wapt
    exitstatus = setup.install()
  File "c:\waptdev\wapt_av-5thFloor-printer-wapt\setup.py", line 36, in install
    run(u'printui.exe /Sr /n "Copieur schumann 5eme etage" /a /f %s\printer-format.dat' %(basedir))
  File "C:\Program Files (x86)\wapt\common.py", line 3570, in run
    return ensure_unicode(setuphelpers.run(*arg,**args))
  File "C:\Program Files (x86)\wapt\setuphelpers_windows.py", line 3863, in run
    raise CalledProcessErrorOutput(proc.returncode,cmd,''.join(output))
CalledProcessErrorOutput: Command 'printui.exe /Sr /n "Copieur schumann 5eme etage" /a /f c:\\waptdev\\wapt_av-5thFloor-printer-wapt\\printer-format.dat' returned non-zero exit status 1.
Output:

FATAL ERROR : CalledProcessErrorOutput: Command 'printui.exe /Sr /n "Copieur schumann 5eme etage" /a /f c:\\waptdev\\wapt_av-5thFloor-printer-wapt\\printer-format.dat' returned non-zero exit status 1.
Output:
Exit code:  3
Not knowing which information might be truly important to you, feel free to ask me questions if needed. I already post a lot, and I wouldn't want to discourage people who might have wanted to read my posts.
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

June 11, 2020 - 1:43 PM

for the order

Code: Select all

run(ur'printui.exe /Sr /n "Copieur schumann 5eme etage" /a /f %s\printer-format.dat' %(basedir))
Perhaps it needs to be run in user context? with session-setup
LMS
Messages: 5
Registration: June 3, 2020 - 11:22

June 11, 2020 - 3:59 PM

The session-setup is useful! It just goes to show I'll need to check out a bit more of everything wapt can do for me.

In this case, it was related, but not directly. It's the printui executable that directly sets the context; we can modify it with flags at the end of the imported configuration file. So here's the new line that works in user context and executes correctly from "def install:"

Code: Select all

run(ur'printui.exe /Sr /n "Copieur schumann 5eme etage" /a %s\printer-format.dat u' %(basedir))
And actually, to go further, I was going to run into a problem: my import wouldn't contain any formatted data, because you need flags to specify what you want to export. So you have to export with:

Code: Select all

Rundll32.exe printui.dll,PrintUIEntry /Ss /n "Copieur Schumann 5eme etage" /a printer-format.dat c m u
And import with:

Code: Select all

run(ur'Rundll32.exe printui.dll,PrintUIEntry /Sr /n "Copieur Schumann 5eme etage" /a %s\printer-format.dat c m p r u' %(basedir))
What is important is to export and import with the "u" to use the same context.

Here is the topic that helped me:
https://stackoverflow.com/questions/173 ... ompleted-e
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

June 11, 2020 - 4:16 PM

Thank you so much! Very helpful!
rmaurisso
Messages: 4
Registration: January 12, 2021 - 5:12 PM

January 12, 2021 - 5:29 PM

Good morning,
Thank you for the code for deploying and configuring the printers.
The deployment works fine, but in Pyscripter when I launch the installation to test, the printer settings only work for my domain admin account (ads samba domain).
However, if I manually run the following command line in the user's session using cmd

Code: Select all

RUNDLL32 PRINTUI.DLL,PrintUIEntry /Sr /n "Copieur Administratif Etage" /a C:\waptdev\tis-install-printer-Administratif_Etage-wapt\disk1\config-CAE.dat u
The configuration applies correctly for my user.
Could I have missed a setting that causes the printer deployment to work but not the configuration for users?
Thank you for your feedback
rmaurisso
Messages: 4
Registration: January 12, 2021 - 5:12 PM

January 13, 2021 - 11:25

Works with the session_setup user context :D
. Awesome! :mrgreen:
Locked