Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Redirect parallel port to LPT2

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,39972
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Redirect parallel port to LPT2
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Redirect parallel port to LPT2 - 11/21/2006 9:14:54 PM   
  suriname

 

Posts: 2
Score: 0
Joined: 11/21/2006
Status: offline
Hello everybody,

I just joined this forum and I have a challange for you, I hope you can help me out.

Description:
I am trying to find a way to automate the changing of the LPT port number of the parallel port to LPT2.  By default the parallel port is set to LPT1 on Windows PCs.  The manual way of redirecting the parallel port is as follows:  Open Device Manager, scroll down to 'Ports (COM & LPT)', double-click 'ECP Printer Port (LPT1)' and go to the second tab called 'Port Settings'. There at the bottom you have a drop down list of LPT port numbers which you can select.  I need to change the port number to LPT2.

I have written a script which opens up Device Manager and sends keystrokes (SENDKEYS) to the active window to navigate to the properties window of ECP Printer Port and change the port number, however this type of script is very unstable and easily interupted - this script needs to be run on remote PCs and as such this type of script is not suitable.

I have google-d high and low for a solution but did not find it.  I have experimented with the WMI class Win32_ParallelPort but that is only able to display the config settings - it does not include a function to make changes.

Maybe VBScript is not the method of performing this task, but I am quite a newbie VBS so I would like to hear from the experts whether what I am asking for is not possible with VBScript - and possibly suggest other ways of going about it.

Many thanks in advance,
Stanley.

PS. The reason I need to redirect the parallel port to LPT2 is because of a legacy application which has LPT2 hardcoded as the printer output port.  The parallel port is used to connect a label printer.  I have already tried to network the label printer (using a HP jetdirect box) and use the NET USE command to redirect LPT2 to that label printer but unfortunatly print performance/stablility suffers too much for the user to make this an acceptable configuration.
 
 
Post #: 1
 
 RE: Redirect parallel port to LPT2 - 11/22/2006 12:06:45 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
You may be able to do it throughthe registry
It makes changes to the following registry key


[HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\PARALLEL PORTS]
"\\Device\\Parallel0"="\\DosDevices\\LPT1"
[HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\PARALLEL PORTS]
"\\Device\\Parallel1"="\\DosDevices\\LPT2"
[HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\PARALLEL PORTS]
"\\Device\\Parallel2"="\\DosDevices\\LPT3"

(in reply to suriname)
 
 
Post #: 2
 
 RE: Redirect parallel port to LPT2 - 11/22/2006 12:14:04 AM   
  SAPIENScripter


Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
While I was pondering this I see someone else came to the same conclusion.  Modify the registry. I first thought you might be able to use the command line MODE command, but that only works if there is a LPT2 device detected, which it sounds like it isn't.  You can use the WshShell object to modify the local registry or WMI to modify remote registries. Because the key is in HKLM, you'll most likely need admin rights to modify it.

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to gdewrance)
 
 
Post #: 3
 
 RE: Redirect parallel port to LPT2 - 11/22/2006 12:20:42 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
The only problem is how do you create a key strating with \ e.g. "\Device\Parallel0" (it creates a new folder device)

Dim Wshshell, path
Set WshShell = CreateObject("Wscript.Shell")

path = "HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\PARALLEL PORTS"

WSHShell.RegWrite path & "\Device\Parallel0", "\\DosDevices\\LPT1", "REG_SZ"

(in reply to SAPIENScripter)
 
 
Post #: 4
 
 RE: Redirect parallel port to LPT2 - 11/22/2006 12:41:00 AM   
  SAPIENScripter


Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
Crap. This is going to bug me until I figure this out.

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to gdewrance)
 
 
Post #: 5
 
 RE: Redirect parallel port to LPT2 - 11/22/2006 12:48:10 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
got it. But I think he will need to delete previous value first

Const HKEY_LOCAL_MACHINE = &H80000002

const REG_SZ = 1

strComputer = "."
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

'Add paths as you see fit and remember to change the path below each statement to your disiried path
strKeyPath = "HARDWARE\DEVICEMAP\PARALLEL PORTS\"

'StringValue
strValueName = "\Device\Parallel0"
strValue = "\\DosDevices\\LPT1"
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue

(in reply to SAPIENScripter)
 
 
Post #: 6
 
 RE: Redirect parallel port to LPT2 - 11/22/2006 12:50:39 AM   
  SAPIENScripter


Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
I think this is a limitation with the Shell object.  The better way, or at least one that works, is to just run REG.EXE from the command line like this:

reg ADD "HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\PARALLEL PORTS" /v "\DEVICE\PARALLEL1" /t REG_SZ /d "\DOSDEVICES\LPT2"

REG has the added advantage is that it can remotely modify registries. 

Obviously, set what ever values you want.  I just was testing the technique.

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to SAPIENScripter)
 
 
Post #: 7
 
 RE: Redirect parallel port to LPT2 - 11/22/2006 1:25:21 AM   
  suriname

 

Posts: 2
Score: 0
Joined: 11/21/2006
Status: offline
Thanks for your suggestion about the registry change.  I played around with that but I wasn't sure whether a reg change would have been sufficient to really change the LPT assignment.  I'll try it locally first and see whether it works.

If it does then infact no scripting is required - i'll just create a REG file and import it  (with regedit /s <filename>.reg), we have a distribution/software deployment infrastructure to upload the file to the PCs.


(in reply to suriname)
 
 
Post #: 8
 
 RE: Redirect parallel port to LPT2 - 11/22/2006 2:09:39 AM   
  SAPIENScripter


Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
What I don't know, and what you'll have to test, is if the change requires a reboot before it is recognized.

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to suriname)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Redirect parallel port to LPT2 Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts