File access denied when printing from a Delphi application

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
marcos_antonio_ps
Level 2
Level 2
Posts: 17
Joined: Mon Apr 20, 2009 8:05 am

File access denied when printing from a Delphi application

Post by marcos_antonio_ps »

Hello, everybody!

I'm getting the following error when I'm trying to print from a Delphi application:

File access denied.

This printer routine in my application is a routine to print text. So it prints to a file
in LPT1 . The source code is more or less like this:

Code: Select all

procedure Print;
var
  File: TextFile;
begin
  AssignFile(File, 'LPT1');
  Rewrite(File);
  try
    Writeln(File, '...');
    // ...
  finally
    CloseFile(File);
  end;
end;
I think the error occur in the AssignFile or Rewrite procedures, when the application tries to generate the file that will hold the printing on the system. I'm almost sure that if I execute my application on Wine under root or superuser the printing will work, but we all know that we should not execute applications on Wine like that. So what's the solution to have file access in this case?

Thank you.

Marcos
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: File access denied when printing from a Delphi applicati

Post by vitamin »

marcos_antonio_ps wrote:I'm getting the following error when I'm trying to print from a Delphi application:

File access denied.

Code: Select all

AssignFile(File, 'LPT1');
Make sure you can write to /dev/lp0
marcos_antonio_ps
Level 2
Level 2
Posts: 17
Joined: Mon Apr 20, 2009 8:05 am

Re: File access denied when printing from a Delphi applicati

Post by marcos_antonio_ps »

vitamin wrote:Make sure you can write to /dev/lp0
How can I test this (I'm sorry for the question but I'm new to Linux)?

Marcos
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: File access denied when printing from a Delphi applicati

Post by vitamin »

marcos_antonio_ps wrote:How can I test this (I'm sorry for the question but I'm new to Linux)?

Code: Select all

ls -la /dev/lp0
echo "hello world" > /dev/lp0
marcos_antonio_ps
Level 2
Level 2
Posts: 17
Joined: Mon Apr 20, 2009 8:05 am

Re: File access denied when printing from a Delphi applicati

Post by marcos_antonio_ps »

vitamin wrote:
marcos_antonio_ps wrote:How can I test this (I'm sorry for the question but I'm new to Linux)?

Code: Select all

ls -la /dev/lp0
echo "hello world" > /dev/lp0
I have just tested. No, I can't. It says that I don't have permission.

Marcos
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: File access denied when printing from a Delphi applicati

Post by vitamin »

marcos_antonio_ps wrote:
vitamin wrote:
marcos_antonio_ps wrote:How can I test this (I'm sorry for the question but I'm new to Linux)?

Code: Select all

ls -la /dev/lp0
echo "hello world" > /dev/lp0
I have just tested. No, I can't. It says that I don't have permission.
What did 'ls -la /dev/lp0' say?
marcos_antonio_ps
Level 2
Level 2
Posts: 17
Joined: Mon Apr 20, 2009 8:05 am

Re: File access denied when printing from a Delphi applicati

Post by marcos_antonio_ps »

vitamin wrote:What did 'ls -la /dev/lp0' say?
It says:

Code: Select all

crw- rw---- 1 root lp 6, 0 2009-04-27 15:32 /dev/lp0
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: File access denied when printing from a Delphi applicati

Post by vitamin »

marcos_antonio_ps wrote:
vitamin wrote:What did 'ls -la /dev/lp0' say?
It says:

Code: Select all

crw- rw---- 1 root lp 6, 0 2009-04-27 15:32 /dev/lp0
Then add yourself to "lp" group and log-off, log-in.
marcos_antonio_ps
Level 2
Level 2
Posts: 17
Joined: Mon Apr 20, 2009 8:05 am

Re: File access denied when printing from a Delphi applicati

Post by marcos_antonio_ps »

vitamin wrote:Then add yourself to "lp" group and log-off, log-in.
Another dumb question: can you tell me how to do this please?
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: File access denied when printing from a Delphi applicati

Post by vitamin »

marcos_antonio_ps wrote:
vitamin wrote:Then add yourself to "lp" group and log-off, log-in.
Another dumb question: can you tell me how to do this please?

Code: Select all

man usermod
marcos_antonio_ps
Level 2
Level 2
Posts: 17
Joined: Mon Apr 20, 2009 8:05 am

Re: File access denied when printing from a Delphi applicati

Post by marcos_antonio_ps »

vitamin wrote:

Code: Select all

man usermod
Like this, for example:

Code: Select all

usermod -a -G lp marcos
marcos_antonio_ps
Level 2
Level 2
Posts: 17
Joined: Mon Apr 20, 2009 8:05 am

Re: File access denied when printing from a Delphi applicati

Post by marcos_antonio_ps »

vitamin wrote:Then add yourself to "lp" group and log-off, log-in.
When I execute the command:

Code: Select all

usermod -a -G lp marcos
I get the message:

Code: Select all

usermod : unable to lock password file
How can I solve this?

Marcos
jay
Level 2
Level 2
Posts: 22
Joined: Fri Apr 24, 2009 3:57 pm

Re: File access denied when printing from a Delphi applicati

Post by jay »

marcos_antonio_ps wrote:

Code: Select all

usermod : unable to lock password file
How can I solve this?

Marcos
-> You need root privileges for adding users to group.
-> You can use the sudo command for executing a command with root privileges:

Code: Select all

sudo usermod -a -G lp marcos
I hope this helps,
Jay
marcos_antonio_ps
Level 2
Level 2
Posts: 17
Joined: Mon Apr 20, 2009 8:05 am

Re: File access denied when printing from a Delphi applicati

Post by marcos_antonio_ps »

jay wrote: -> You need root privileges for adding users to group.
-> You can use the sudo command for executing a command with root privileges:

Code: Select all

sudo usermod -a -G lp marcos
I hope this helps,
Jay
Hello, Jay! Thanks a lot. It helped.

Marcos
Locked