Access shared printer of XP guest from Windows 7 host?

Discussions about using Windows guests in VirtualBox.
Post Reply
konstantin_hu
Posts: 2
Joined: 21. Jan 2014, 16:30

Access shared printer of XP guest from Windows 7 host?

Post by konstantin_hu »

I have Windows XP SP3 guest, guest additions installed. Host system is Windows 7 64 bit. I installed a HP LaserJet 1000 Series printer on the guest XP system, because no Windows 7 64 bit drivers are available. Printing from the guest system works fine, both text and graphics. I shared the printer in the guest system on the LAN. My virtualbox system IP address is 10.2.0.15 (I think but not sure), share name of the printer is hpLaserJ. When I try to access network share \\10.0.2.15\hpLaserJ from the host system there is no success. My question: how can I access the shared printer from the Windows 7 host to enable network printing?
Rootman
Posts: 251
Joined: 1. Oct 2012, 18:29

Re: Access shared printer of XP guest from Windows 7 host?

Post by Rootman »

I've not done it from HOST to GUEST, I've one it the other way around which works just like any other share does. It SHOULD work just like any share amongst physical machines. The Win 7 WILL need some drivers written for it to access the printer, regardless if it is using it through the share or direct via IP.

BTW: have you tried the HP universal drivers on the Win 7 64 bit? I've used them around here on several Win 7 64 users for several HP models.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Access shared printer of XP guest from Windows 7 host?

Post by socratis »

konstantin_hu wrote:My virtualbox system IP address is 10.2.0.15, share name of the printer is hpLaserJ. When I try to access network share \\10.0.2.15\hpLaserJ
I think that it is the red one that is correct, in which case it means you're using "NAT" as your network interface (VM Settings, Network). If you use the VM for printing and nothing else, then change it to "HostOnly". Otherwise switch it to "Bridged" (but only if you have a DHCP server, like a home router or similar.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
konstantin_hu
Posts: 2
Joined: 21. Jan 2014, 16:30

Re: Access shared printer of XP guest from Windows 7 host?

Post by konstantin_hu »

Yes, I unfortunately mistyped the IP address. 10.0.2.15 is the right.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Access shared printer of XP guest from Windows 7 host?

Post by mpack »

That's a NAT address. If the VM is acting as a server then you can't use NAT. A NAT guest by definition ignores (in fact, never receives) unsolicited network messages. You can get around this by configuring port forwarding, but it should be much simpler to switch to host-only or bridged.

And as Socrates points out, you will in any case need a Windows 7 driver - having a shared comms path to the printer doesn't change that. The only way you can do without a Win7 print driver is to, e.g., print to PDF first, then have the guest print the PDF on the LaserJet.

I assume you've tried Googling for direct solutions to the problem of supporting LaserJet 1000 on a Win64 host.
Royspc
Posts: 3
Joined: 29. Feb 2016, 22:28

Re: Access shared printer of XP guest from Windows 7 host?

Post by Royspc »

I have aWindows XP guest on a Windows 10 host.
The purpose of the guest is to use the HP Laserjet 4 for specialty printing.
Everything work fine from the guest but would like to print from the host.
The drivers for the printer cannot be installed on Windows 10 or there would be no need for the guest.
Is it even possible to print to the guest printer using seamless or other workaround from a host program?
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

Re: Access shared printer of XP guest from Windows 7 host?

Post by scottgus1 »

I have a Brother printer which stopped driver development at Vista. I have it plugged into our house file server running XP, and print to it from 7, 8, and 10 via local 7, 8, & 10-compatible free PDF makers (Bullzip and Foxit), and dropping the PDFs into a shared folder on the server, which is monitored by a VBScript which runs the "print" command line for the PDF reader installed on the server when a PDF shows up in the shared folder, and my old printer can still print from modern OSs. (Nothing Virtualbox in the solution, but you can do something with your XP guest.)
Royspc
Posts: 3
Joined: 29. Feb 2016, 22:28

Re: Access shared printer of XP guest from Windows 7 host?

Post by Royspc »

I think I have come up a workable solution.
The windows 10 programs can save their files as pdf to a shared folder.
With Adobe reader from from the guest on the windows 10 desktop as seamless I can open files from the shared folder and print them.
By minimizing Adobe Reader in is not obtrusive until needed to print.
Would be nice if it could just launch when the computer is turned on.

The server solution would be good if we had a server.
Could you post the VBS script with instructions on how to install in the XP guest. Shared folder is already set up.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

Re: Access shared printer of XP guest from Windows 7 host?

Post by scottgus1 »

Here is my script for handling PDFs dropped in a shared folder. Save the Code text in a Notepad text file with the extension .vbs and run it with some automatic mechanism in the XP guest. The script stays alive once it is run and checks the shared folder every three seconds.

DOC files compatible with Wordpad and TXT files via Notepad are also supported. Further file types could be added by inserting more Case segments in the Select loop.

The files get printed then deleted, so don't expect to keep the files you drag to the shared folder.

PDF files with the text "(#)copies" at the end of the name will get printed # number of times:
"Test.pdf" will get printed once. "Test(4)copies.pdf" will get printed 4 times.

PDF printers typically try to open the generated PDF in a PDF reader after the "print", which may interfere with the print & delete function of the script if the PDF is saved directly into the shared folder. I make a PDF on my desktop first, testing the outcome of my print, before I drag the PDF over to the shared folder & watch it disappear & the printer start up.

In my experience the PDF reader on the XP server remembers the last settings it used to print a PDF to paper and uses those settings for a script-generated print, so I have to manually print a PDF the first time to set the print settings correctly.

At the beginning of the script are command lines for the file types supported by the script. Change the command line to change the program you want to use.

Code: Select all

'These strings are used to define the print commands on the found files, based on the file extension.
'A VB text string must begin and end with a double quote.
'Double quotes are often required in command lines to handle paths and filenames containing spaces.
'Two adjacent double-quotes in a VB text string get converted to one double-quote, to allow
'  double-quotes to appear within the string. In these examples, the variable dummy is loaded:
'    dummy = "hello"      < this line fills dummy with the word hello.
'    dummy = """hello"""  < this line fills dummy with "hello" in double quotes. There are three quotes on each end,
                          one to start the string, and two to make the double-quote in the string.
'If series of double quotes gets confusing, the command CHR(34) can be used to place a double quote in the string:
'    dummy = CHR(34) & "hello" & CHR(34)  < this will also fill dummy with "hello" in double quotes.

'Printing program command strings:
'PDFrunstring="""C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"" /t """&pdflocation&"\"&fil.name&""""
PDFrunstring="""C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe"" /t """&pdflocation&"\"&fil.name&""""
DOCrunstring="""C:\Program Files\Windows NT\Accessories\WORDPAD.EXE"" /p """&pdflocation&"\"&fil.name&""""
TXTrunstring="""C:\Program Files\Windows NT\Accessories\WORDPAD.EXE"" /p """&pdflocation&"\"&fil.name&""""

'Shared folder to monitor:
pdflocation="R:\ServerRamDisk"

Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = WScript.CreateObject ("WSCript.shell")
Set fol = fso.GetFolder(pdflocation)
wscript.sleep 60000 'wait for ram drive to appear
on error resume next
do
Set filecol = fol.Files
For Each fil in filecol
  filename = fil.name
if filename="running.test" or filename="shutdown.test" or filename="reboot.test" then
  fso.deletefile pdflocation&"\"&fil.name 'deleting running.test shows core of server still running well.
  if filename="shutdown.test" then shell.run "shutdown -s -f -t 10"
  if filename="reboot.test" then shell.run "shutdown -r -f -t 10"
else
  fileext=ucase(fso.GetExtensionName(fil.name))
  select case fileext
  case "PDF"
    numcopies = 1
    copycount = 0
    testcopies = instr(filename,")copies")
    copytally = ""
    if testcopies <> 0 then
      for x = (testcopies - 1) to 1 step -1
      if instr("0123456789",mid(filename,x,1)) = 0 then exit for
      copytally = mid(filename,x,1) & copytally
      next
    end if 
    if isnumeric(copytally) then
      numcopies = cint(copytally)
    end if
    'msgbox PDFrunstring
    do
    shell.run PDFrunstring
    copycount = copycount + 1
    loop until copycount = numcopies
    'msgbox "continue"    
    'wscript.quit
    do
      err.clear
      wscript.sleep 5000
      fso.deletefile pdflocation&"\"&fil.name
    loop until err.number=0 
  case "DOC"
    'msgbox DOCrunstring
    shell.run DOCrunstring
    do
      err.clear
      wscript.sleep 5000
      fso.deletefile pdflocation&"\"&fil.name
    loop until err.number=0 
  case "TXT"
    'msgbox TXTrunstring
    shell.run TXTrunstring
    do
      err.clear
      wscript.sleep 5000
      fso.deletefile pdflocation&"\"&fil.name
    loop until err.number=0 
  case else
  end select
end if 'filename test
Next
'wscript.quit
wscript.sleep 3000
set filecol=nothing
loop
Royspc
Posts: 3
Joined: 29. Feb 2016, 22:28

Re: Access shared printer of XP guest from Windows 7 host?

Post by Royspc »

Thank you Scott.

Will try to make heads or tails of it. You supplied a lot of options.
Post Reply