Solved

aprinters() not working in EXE

Posted on 2014-01-09
8
727 Views
Last Modified: 2014-02-07
Function aPrinters() is working when under application.  Failled when ran from EXE on some PC and works well on others.  

=APRINTERS(xPrinterList,0)
IF ASCAN(xPrinterList,"pdf995",1,0,1,1) = 0
      mbkGestionSorties = .f.
      bPDF995Present = .f.
ENDIF       

On some PC system is crashing stating that xPrinterList does not exist.  If I run into APP mode onto same PC, no problems.  If I run EXE on another PC, it run fine.  

Thanks
0
Comment
Question by:meep_meep
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 42

Expert Comment

by:pcelba
ID: 39769066
The PC system is not crashing your program just does not properly handle the APRINTERS() result... You have to test the result returned by the APRINTERS() function to avoid this "crash".

But it does not mean the APRINTERS() function works well when the array is not created but printers exist.

Unfortunately you have not so many options to fix this behavior.

1) Check the version of your run-time libraries used for EXE run on all PCs ( VERSION(4) function should return 09.00.0000.7423)
2) If the APRINTERS() returns 0 then you may attempt to issue GETPRINTER() to allow users to select printer from available printers.
3) If the GETPRINTER() does display empty printers list then you may try to obtain the list of printers by Win32 API call. See EnumPrinters API call here: http://www.news2news.com/vfp/?group=57&function=215
4) You may also check other printer related functions from the same resource (EnumPrinterDriver API call is available as the source for a free)

Another useful piece of code is e.g. here: http://www.berezniker.com/content/pages/visual-foxpro/enumerating-printer-forms

You may also obtain the list of printers by WMI:
oWMI = GetObject("winmgmts:\\.\root\cimv2")
oPlist = oWMI.ExecQuery("Select * From Win32_Printer")
FOR EACH oPrinter IN oPlist
  ? oPrinter.Name
NEXT

More info: http://blogs.technet.com/b/heyscriptingguy/archive/2006/08/14/how-can-i-list-all-the-printers-on-a-remote-computer.aspx

The only thing we are sure about is no VFP update from Microsoft...
0
 

Author Comment

by:meep_meep
ID: 39769103
Agree with you about "crashing".  I was referring to code crashing since aPrinters() did not fill up the array.  One point is bugging me: my program is working when ran from APP but fail when from EXE on same PC, even when EXE is built on that PC.  Same program is well working on other PC.  I compared files from those two and they are the same.  Do you know if there are some dll I should check version or availability on the faulty machine to make aPrinters() working ?  Reason why I need to fix that function on that machine is that FoxyPreviewer have some fatal issues when asked.  Again, on another machine, all that is working :S
0
 
LVL 42

Expert Comment

by:pcelba
ID: 39769149
How do you execute the APP? From VFP IDE by DO command?  VFP IDE uses different environment than running EXE.  Did you try to execute EXE by DO command from VFP IDE?

Did you check the VERSION(4) when the EXE/APP is running?

Printers enumeration calls functions from  WINSPOOL.DRV  so you may check this file version (in Windows\SYSTEM32 on 32 bit systems,  in Windows\SYSWoW64  on  64 bit systems).
0
Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

 

Author Comment

by:meep_meep
ID: 39769458
Not sure what happened.  The user was using Comodo anti-virus.  We disabled it for an hour, ran the EXE without any problems.  We then re-enabled anti-virus and EXE still ran without any problems.  100% confused now.  A test we missed to do is to make sure EXE was still failling before disabling anti-virus.  However, yesterday we did reboot PC and EXE was still not working.  Since I'm 100% confused, it might be possible that EXE was working before anti-virus turned off.  Does this make any sense to you ?!?
0
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 39769588
LOL,  Comodo's AI is reading this forum maybe...

I don't know Comodo antivirus software just some Comodo security certificates. And this antivirus behavior really does not make sense... except for some "printing viruses" attack blocking where this behavior could be possible... The behavior change could happen after some Comodo automatic update but it has to be confirmed by Comodo.

Antivirus compatibility is becoming a nightmare under certain circumstances... File access denied, File does not exist, applications (very) slow start, FPT file is missing or invalid, ... Missing printers are new item on this list... I am using Avast and AVG without this side effect but it can appear tomorrow...

The good point it is working now!
0
 

Author Closing Comment

by:meep_meep
ID: 39769602
Very efficient, thanks a lot for your precious collaboration
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 39841218
Just a question: How many printes are installed, and are they available for the current user, when running the EXE?

Just check if APRINTERS() returns 0, then there s no printer for that user.

Unusual, but what else should be a problem? Too many printers perhaps, specifically network printers.

Also see the note of the help topic: The behavior of this function is OS (operating system) - specific. Visual FoxPro may or may not check to see if the printers are actually connected to your computer when it prepares this list, and the list may include all printers installed as printer setups, or only those available on the current network.

So reasons for the function no working are also possible in OS configuration or behaviour.

Bye, Olaf.
0
 

Author Comment

by:meep_meep
ID: 39841548
Thanks Olaf.  The involved user is now running my exe in sandbox.  Since that time he did not face that error.  My understanding is that anti-virus was blocking aPrinters().
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question