Answered by:
How to impersonate in Win 7 64 bits or Win2008 64 bits

Question
-
I want to impersonate on a Win 7 64 bits or Win2008 64 bits. For this I use DECLARE integer LogonUser IN AdvApi32.DLL and DECLARE integer ImpersonateLoggedOnUser IN AdvApi32.DLL integer hToken.
After doing the impersonation successfully, the "super" user has network access the normal user does not have. But for the "supersuer" there are no printers available (not even the local ones) even if I configure them separately interactively on the desktop on "superuser" profile. The normal user does see the printers.
Maybe the impersonation must be done differently. I know there are 2 AdvApi32.dll on 64 bits, one is in system32, the other in syswow64. Which one must I use? Shall I force the library name to have the complete path?
WPThursday, September 1, 2011 1:00 PM
Answers
-
In that case, I can only repeat Pavel answer to your first attempt of this in July: Check if the impersonated user has permission to access the printers.So, try to log in as this user and check if there are any printers availlable.
Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011Friday, September 2, 2011 2:53 PMAnswerer -
Hi Again Everyone,
Here is a solution that worked for me.
BEFORE you impersonate the super-user, just print a report. I use a null-report that contains it's own data set of one empty table and nothing on the report. I issue:-
REPORT FORM null-report.frx FOR .F. noconsole TO FILE c:\foxwork\null.txt.
This seems (and I admit that I'm guessing here!) to initialise the printer driver in memory prior to the impersonation and so it's available after the impersonation kicks in. In fact, I get a list of printers using APRINTERS(), set the printer to each name and use the same command for each printer but that may be over the top for some applications.
HAPPY DAYS!
Cheers everyone and I hope that this solves the problem for someone else.
Derek
- Proposed as answer by Derek.Jackson Friday, August 3, 2012 1:01 PM
- Marked as answer by Pavel Celba Friday, August 3, 2012 11:04 PM
Friday, August 3, 2012 12:58 PM
All replies
-
Hi,
syswow64 contains the 32bit dll versions.
However, to be able to use printers you will have to install 32bit printerdrivers. To me it seems as so there are 64bit drivers installed, only.
Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011Thursday, September 1, 2011 1:23 PMAnswerer -
And how can I check if the network printers installed have the 64 bit drivers or the 32 bit drivers?
WPFriday, September 2, 2011 1:46 AM -
Usually, when installing printer drivers on a 64bit machine, there is a small x86 checkbox that has to be selected.
However, there is an article on technet where they describe how to manage this:
http://technet.microsoft.com/en-us/library/cc732946.aspx
Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011Friday, September 2, 2011 5:57 AMAnswerer -
Yes, I have the 32 bit printer drivers installed. When I do "REPORT FORM xxxx" with the normal user, I can print without problems, the issue is with the impersonated user, there I am not able to see any printers. When the printer dialog appears to select a printer I get an empty list, there is the possibility to "Add Printer" but it is greyed out. However, the normal user can choose any of the installed printers.
WPFriday, September 2, 2011 2:05 PM -
In that case, I can only repeat Pavel answer to your first attempt of this in July: Check if the impersonated user has permission to access the printers.So, try to log in as this user and check if there are any printers availlable.
Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011Friday, September 2, 2011 2:53 PMAnswerer -
I would suggest to wait with closing of this thread. We should know whether this is Windows bug or just access rights issue.
Monday, September 5, 2011 10:47 AM -
So, what's the status of this problem?
Wednesday, September 14, 2011 8:34 AM -
Hi All, I have exactly the same problem as WPaul59. When using XP32bit the impersonate user function worked without problem. Now I have upgraded my workstations to Win7 64bit with all 46bit printer drivers and I can no longer print when I impersonate user. I am a local admin on the workstation and can print without problem from the desktop. Within my VFP application I Impersonate User to myself so I know that I have exactly the same rights over printers and network drives but printing fails. If I print from "Report Form .... Preview" there is no error message generated and the program does not crash. The list of printers is displayed and I can select the correct printer but nothing is printed and I can't see anything entering the print queue. Calling to Getprinter() produces an ErrorBox with "Printr is not ready" Oh, and just to be pedantic, printing works fine from the same application if I do not use impersonate user. Has anyone seen any solution to this problem? Cheers DerekWednesday, March 7, 2012 1:23 PM
-
Hi Again Everyone,
Here is a solution that worked for me.
BEFORE you impersonate the super-user, just print a report. I use a null-report that contains it's own data set of one empty table and nothing on the report. I issue:-
REPORT FORM null-report.frx FOR .F. noconsole TO FILE c:\foxwork\null.txt.
This seems (and I admit that I'm guessing here!) to initialise the printer driver in memory prior to the impersonation and so it's available after the impersonation kicks in. In fact, I get a list of printers using APRINTERS(), set the printer to each name and use the same command for each printer but that may be over the top for some applications.
HAPPY DAYS!
Cheers everyone and I hope that this solves the problem for someone else.
Derek
- Proposed as answer by Derek.Jackson Friday, August 3, 2012 1:01 PM
- Marked as answer by Pavel Celba Friday, August 3, 2012 11:04 PM
Friday, August 3, 2012 12:58 PM -
Many thanks for your solution Derek!Friday, August 3, 2012 11:04 PM