[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 765
  • Last Modified:

aprinters() not working in EXE

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
meep_meep
Asked:
meep_meep
  • 4
  • 3
1 Solution
 
pcelbaCommented:
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
 
meep_meepAuthor Commented:
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
 
pcelbaCommented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
meep_meepAuthor Commented:
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
 
pcelbaCommented:
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
 
meep_meepAuthor Commented:
Very efficient, thanks a lot for your precious collaboration
0
 
Olaf DoschkeSoftware DeveloperCommented:
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
 
meep_meepAuthor Commented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now