Announcement

Collapse
No announcement yet.

NET USE LPT redirection issue

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • NET USE LPT redirection issue

    I did no see a WTH category to put this in.
    Just an FYI that belongs here by importance compared to the system category.
    After installing Windows 7 Utlimate 32 bit and doing updates using WSUS offline updates with service pack updates rather than individual updates.
    Failed was using making commands NET USE LPT1, and LPT2 and LPT3 work.
    I never saw this act this way.
    I had added LPT4 to LPT9 using a reg file and it is standard that I add these to all machines.
    The ports could be seen in printer properties under the ports tab.
    What finally made it work was removing the Ports by way of the registry.
    I did a practice on other Windows 7 pro machines, non Ultimate and I was able to make redirected attachments.
    Before under Windows xp. You could only do this for ports listed and if the actual port did not exist on the computer or you renowned the port or disabled the port in device manager.
    I have seen others have issues with redirect of ports in this forum and wonder if this problem is what was causing their problem.
    Without further testing to this point. It looks like I will be removing all LPT and COM ports from printer ports.

    I have other machines with Ultimate 7 on them but not an current uodate as turn updates off after a machine is running.
    Also I found my other problem with Trusted Zones. Yep, windows update broke that.
    p purvis

  • #2
    here is my standard add more lpt ports reg file
    i do this in the case i want to print from a 16 bit console program or a 16 BIT powerbasic TSR program.
    no i have not tried to print higher than lpt3 or lpt4 on those program but i believe Powerbasic PBCC works just fine for ports higher than lpt3 meaning lpt4 to lpt9.

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports]
    "LPT4:"=""
    "LPT5:"=""
    "LPT6:"=""
    "LPT7:"=""
    "LPT8:"=""
    "LPT9:"=""
    the problem may not of been what i thought it was originally.
    on the xp systems, i could have the protocol for File and Printer sharing for Microsoft Networks in the lan area properties for my network card but not have to check place a check on the item.
    by doing so, i could just make a share locally and have redirection all i wanted to on the local machine to itself and not expose those shares on the network.
    but it maybe that windows 7 at does not allow that. i will keep checking with on this as i convert the machines.



    p purvis

    Comment


    • #3
      Disabling the File and Print sharing by default is a security measure.

      BTW, for all intends and purposes - you should have upgraded to the 64 bit version ... if 16 bit applications are still a need for you, as you've indicated, look at something like VirtualBox or DOSBox.

      Comment


      • #4
        Yes Knuth.
        Specially on workstations. I try to disable everything that will provide the upmost security and that usually comes to the Wordpress Disable, Disable Disable. And I really prefer REMOVE.

        Just to repeat because one thing does not seem possible.
        In XP sp3, where I just want to redirect to local printer ports, I did not have to have sharing accessible for non local connections but simply by uncheckimg the file and printer protocol that is listed under network properties for a network device and not removing the protocol entirely. I was able to get simple printing to LPT ports for software that does not print to windows printers. A big issue to overcome when dealing with many software printing.
        That is good to know. Knuth about the security.
        Our venders software keeps the big most important database files all the time except in the begging menu.
        Simce 2006 when we move over. I have not been able to get through to this old stubborn programmer on his bad practices that cause him all kinds of issues and me as well when things go bad.
        So there is not going to be any virtual software used when those possibilities exist and after a discussion last week with the developer, using non 16 bit code is not forseeable at this time. And I will probably now die first or not be involved in any way with what is being used.
        p purvis

        Comment


        • #5
          The printer driver can be used and eliminate LPT ports.
          Wireless printers automatically configure much differently using IP_192.168_xxx.xxx
          Not sure what printers would be wanted without wireless.

          Anything can be sent to a text file and printed using WinPrint, DDOC ox XPRINT
          using a SHELL command to replace all the print statements
          I pass additional commands on the shell line to tell the printing program what to do with the file.

          DDOC even has routines for printing sheets of labels (if needed.)
          Then again, not sure why the need for the registry or using:
          NET USE LPT2: /DELETE
          NET USE LPT2: \\MACHINENAME\PRINTERSHARE /PERSISTENT:YES

          If this is about deleting LPT ports for security it is the first time I've heard of doing it.







          https://www.tesla.com/roadster

          Comment


          • #6
            Mike, I was printing from a DOS TSR which shelling out is almost impossible.
            I do use the NET redirection command at logon. I have no idea why LPT fails intermittently to connect to the computer's own printers at times even after the redirection of drives has already taken place. I have placed SLEEP statements in the batch process that does all the connecting after a logon. I have notice that a few Windows 10 machines that there is a pause of seconds before items are run in the STARTUP folder.
            I did see where there was a hotfix for some of these issues in windows 7 just before they released windows 7 sp1.
            p purvis

            Comment


            • #7
              As info:
              I shell all the time from a PDS 7.1 program, but not TSR.
              WinLink.exe by Lance allows shell to allocate then my WinPrint.exe uses ddoc to print FileName$
              SHELL databasedir$ + "WINLINK.EXE " + "WinPrint.EXE " + Filename$

              Hopefully LPT1 isn't being used that might conflict with Windows.

              NET USE LPT2: /DELETE
              NET USE LPT2: \\MACHINENAME\PRINTERSHARE /PERSISTENT:YES

              Don't know what is happening, but printing from Windows might be the solution using a printer driver.
              https://www.tesla.com/roadster

              Comment


              • #8
                Mike. For Users, I try to keep things simple as I can and assigning LPT ports with a login batch file works.
                Just very odd that most the failed connections are to its own self.
                I might try putting in a user name and password if I keep getting the issues and it is not very often the connections are not make and i also give a a big warning to log off and back on.
                I have checks at the end of the batch routine to check for failed connections.

                But I wrote a batch routine today will likely help and actually in my scripts. It speeds the login scripts.
                I had put this off long enough.
                One of things you can do but I think it will bite you in the end if your networking breaks is that you can have logins have to wait on networking resources by setting some group policy settings.
                Had I set that, It would of cost me a days work in travel time to fix a damaged network card and there was a slower built in network card already in the machine that was turned off.
                We also stay away from Persistent also. I have never had an issue with a disconnect by timeout not reconnect on demand.
                No we do not use wireless networking cards for workstations either and i do not have network cards try to save a few cents a year by them not being on and not running at full speed either.

                code in calling batch file
                Code:
                IF EXIST C:\WSBAT\NETUSECT.BAT CALL C:\WSBAT\NETUSECT.BAT LPT1 \\%COMPUTERNAME%\LASER
                or
                Code:
                SET XNETUSECTPARAMETER1=LPT1
                SET XNETUSECTPARAMETER2=\\%COMPUTERNAME%\LASER
                IF EXIST C:\WSBAT\NETUSECT.BAT CALL C:\WSBAT\NETUSECT.BAT
                or
                Code:
                SET XNETUSECTPARAMETER1=LPT1
                SET XNETUSECTPARAMETER2=\\%COMPUTERNAME%\LASER
                SET XNETUSECTPARAMETER3=userspassword
                SET XNETUSECTPARAMETER4=/user:username
                IF EXIST C:\WSBAT\NETUSECT.BAT CALL C:\WSBAT\NETUSECT.BAT
                or
                Code:
                SET XNETUSECTPARAMETER3=userspassword
                SET XNETUSECTPARAMETER4=/user:username
                IF EXIST C:\WSBAT\NETUSECT.BAT CALL C:\WSBAT\NETUSECT.BAT LPT1 \\%COMPUTERNAME%\LASER

                Code:
                @echo off
                rem netusect.bat
                rem This batch file is designed to be called from another batch process.
                rem The main purpose of this batch process is to connect to devices and particular
                rem   to help solve a problem of connecting a LPT port to the same computers
                rem   shared printer devices and specially at time of login.
                rem I have seen too many times when a connection by way of "NET USE LPT" failed to
                rem   redirect its own LPT ports that do not exist or disabled back to
                rem   its own shared printer devices on the same machine.
                rem This batch process just makes use of a loop to try to make the redirected connection.
                rem Usually the command will be something like "NET use LPT1 \\%COMPUTERNAME%\SHAREPRINTERNAME"
                rem   and not even require a user name or password but this batch process can handle user names
                rem   and user passwords on peer to peer connections. Connecting to a domain server is not tested.
                rem In most all cases, problems with not connecting have been reduced but not fully solved by
                rem This program just makes use of a loop to try to make the connection.
                rem   giving some amount of time after a machine is either started or after a user logs in.
                rem This batch routine tries to make the period of the loop to connect only last about 45 seconds
                rem   before it gives up. If more time is needed, just increase the count in the loop.
                rem I have always seen more connections succeed with adding a sleep period after using the
                rem   "NET USE" command. Only Microsoft might know why.
                rem This routine will disconnect a local device if it is already redirected.
                rem If you want to use a connection that stays persistent or not. Use this command line prior
                rem   running this batch process. "NET USE /PERSISTENT:NO" or "Net USE /PERSISTENT:YES"
                rem I personally have always used "NET USE /PERSISTENT:NO" and have had no troubles and
                rem   I do not like upon a reboot the operating system complaining about not making connections
                rem   from a previous logged in session that is very confusing to most users.
                rem I usually always make connections on at the time of logon by login scripts.
                
                rem command line useage
                rem command line parameter 1 is the local device
                rem command line parameter 2 is the shared device
                rem command line parameter 3 is the user password
                rem command line parameter 4 is the users name with /user: preceeding it
                
                rem Some batch command line options such as an equal sign character  will be dropped
                rem by the operating system. So you must set these problem command line options in
                rem an environmental variable prior running this batch file
                
                rem all 4 command line option parameters can be preset in environmental variables
                rem XNETUSECTPARAMETER1 is the local device name
                rem XNETUSECTPARAMETER2 is the shared device name
                rem XNETUSECTPARAMETER1 is the users password
                rem XNETUSECTPARAMETER1 is the users name like "/user:joe"
                
                
                
                IF NOT "%1" == "" SET XNETUSECTPARAMETER1=%1
                IF NOT "%2" == "" SET XNETUSECTPARAMETER2=%2
                IF NOT "%3" == "" SET XNETUSECTPARAMETER3=%3
                IF NOT "%4" == "" SET XNETUSECTPARAMETER4=%4
                IF "%XNETUSECTPARAMETER1%" == "" GOTO NETUSECTEXIT2
                IF "%XNETUSECTPARAMETER2%" == "" GOTO NETUSECTEXIT2
                
                SET XNETUSECTHOUR=%time:~0,2%
                IF "%XNETUSECTHOUR:~0,1%" == " " set XNETUSECTHOUR=0%XNETUSECTHOUR:~1,1%
                SET XNETUSECTTIME=%XNETUSECTHOUR%%time:~3,2%%time:~6,2%%time:~9,2%0
                SET XNETUSECTDATE=%date:~-4%%date:~4,2%%date:~7,2%
                SET XNETUCSECTFILECHECK1=%TEMP%\NETUSECK%XNETUSECTTIME%.TXT
                SET XNETUCSECTFILECHECK2=%TEMP%\NETUSECT%XNETUSECTTIME%.TXT
                SET XNETUCSECTFILELOG=%TEMP%\NETUSECTLOG-%XNETUSECTDATE%-%XNETUSECTTIME%.TXT
                SET XNETUSECTTIME=
                SET XNETUSECTHOUR=
                SET XNETUSECTDATE=
                SET XNETUSECTLOCALDEVICE=%XNETUSECTPARAMETER1%
                SET XNETUSECTSHAREDDEVICE=%XNETUSECTPARAMETER2%
                NET USE > %XNETUCSECTFILECHECK1%
                find /I "%XNETUSECTLOCALDEVICE%"  %XNETUCSECTFILECHECK1% > NUL
                IF %ERRORLEVEL% == 1 GOTO STARTNETUSECT
                NET USE %XNETUSECTLOCALDEVICE% /D /Y > NUL
                SLEEP 1
                :STARTNETUSECT
                SET XNETUSECTVAR1=0
                SET XNETUSECTVAR2=0
                :TRYNETUSECT
                SET /A XNETUSECTVAR1=%XNETUSECTVAR1%+1
                SET /A XNETUSECTVAR2=%XNETUSECTVAR2%+1
                IF %XNETUSECTVAR1% EQU 2 ECHO Issues attempting to redirect %XNETUSECTLOCALDEVICE% to %XNETUSECTSHAREDDEVICE%
                IF %XNETUSECTVAR1% EQU 2 ECHO The system is now retrying for up to about 30 seconds. Do not interrupt this.
                IF %XNETUSECTVAR1% EQU 2 ECHO Unsuccessfull redirected connections will be logged in the file name below.
                IF %XNETUSECTVAR1% EQU 2 ECHO %XNETUCSECTFILELOG%
                
                IF %XNETUSECTVAR1% GTR 160 GOTO NETUSECTEXIT
                IF %XNETUSECTVAR2% GTR 9 SET XNETUSECTVAR2=0
                rem ECHO trying .... count %XNETUSECTVAR1% of 160
                ECHO NET USE %XNETUSECTLOCALDEVICE% %XNETUSECTSHAREDDEVICE%  %XNETUSECTPARAMETER3% %XNETUSECTPARAMETER4%  > %XNETUCSECTFILELOG%
                NET USE %XNETUSECTLOCALDEVICE% %XNETUSECTSHAREDDEVICE%  %XNETUSECTPARAMETER3% %XNETUSECTPARAMETER4%  1>> %XNETUCSECTFILELOG% 2>&1
                IF %XNETUSECTVAR2% NEQ 0 SLEEP .075
                IF %XNETUSECTVAR2% EQU 0 SLEEP 1
                NET USE > %XNETUCSECTFILECHECK1%
                find /I "%XNETUSECTLOCALDEVICE%"  %XNETUCSECTFILECHECK1% > %XNETUCSECTFILECHECK2%
                IF %ERRORLEVEL% == 1 GOTO TRYNETUSECT
                IF NOT EXIST %XNETUCSECTFILECHECK2% GOTO TRYNETUSECT
                find /I "%XNETUSECTLOCALDEVICE%"  %XNETUCSECTFILECHECK2% > NUL
                IF %ERRORLEVEL% == 1 GOTO TRYNETUSECT
                find /I "%XNETUSECTSHAREDDEVICE%"  %XNETUCSECTFILECHECK2%  > NUL
                IF %ERRORLEVEL% == 1 GOTO TRYNETUSECT
                ECHO Successfully redirected  %XNETUSECTLOCALDEVICE% to %XNETUSECTSHAREDDEVICE%
                IF EXIST %XNETUCSECTFILELOG% DEL %XNETUCSECTFILELOG% > NUL
                
                :NETUSECTEXIT
                IF EXIST %XNETUCSECTFILECHECK1% DEL %XNETUCSECTFILECHECK1% > NUL
                IF EXIST %XNETUCSECTFILECHECK2% DEL %XNETUCSECTFILECHECK2% > NUL
                SET XNETUSECTVAR2=
                SET XNETUSECTVAR1=
                SET XNETUSECTLOCALDEVICE=
                SET XNETUSECTSHAREDDEVICE=
                SET XNETUCSECTFILELOG=
                SET XNETUCSECTFILECHECK2=
                SET XNETUCSECTFILECHECK1=
                :NETUSECTEXIT2
                IF NOT "%1" == "" SET XNETUSECTPARAMETER1=
                IF NOT "%2" == "" SET XNETUSECTPARAMETER2=
                IF NOT "%3" == "" SET XNETUSECTPARAMETER3=
                IF NOT "%4" == "" SET XNETUSECTPARAMETER4=
                Last edited by Paul Purvis; 18 Aug 2018, 03:02 AM.
                p purvis

                Comment


                • #9

                  If you can't shell from program then create a shortcut to a batch file like GO.BAT to start yourprogram.exe.
                  When you want to do something, end program with an exit code.
                  Batch file uses exit code to run anything then restarts program or continues somewhere in batch file.
                  I stopped capturing printer ports a long time ago using this method.

                  The program "yourprogram.exe" creates output files that are processed by winprint.exe
                  Code:
                  REM GO.BAT
                  @echo off
                  cd /d %~dp0
                  :begin
                  yourprogram.exe
                  
                  :top
                  if errorlevel 100 if not errorlevel 101 goto 100
                  if errorlevel 99  if not errorlevel 100 goto 99
                  if errorlevel 98  if not errorlevel 99  goto 98
                  if errorlevel  1  if not errorlevel 2   goto begin
                  goto lastline
                  
                  :100
                  winprint.exe
                  goto top
                  
                  
                  :99
                  program99.exe
                  goto top
                  
                  :98
                  write.exe
                  goto top
                  
                  :97
                  goto begin
                  
                  :lastLine
                  https://www.tesla.com/roadster

                  Comment


                  • #10
                    I think I might of figured out the problem even though I have been able to see a problem lately.
                    I will have to look back at the batch file I just created to see if it leaving me a trail of error codes in the txt files it creates. But I sort of think the problem relies somewhere on not finding the computers own name in a lookup of computer names through SMB. You would think a computer could find itself. But somehow. I believe this is the problem. As far as I know. The connection can be made at a later time if the first tries after bootup failed. I know the computers do t advertise their existence all the time and it just has to be somewhere in that area of goings on.
                    It is too odd that other connections are made to other shared devices like on sever shares.
                    I would suppose I could use the ipaddress on the machine too.
                    Maybe there is a way to force that broadcast.
                    A sever is set to have the highest master number on maintaining those computer browser services.
                    Oh well. On with the funeral music.
                    p purvis

                    Comment


                    • #11
                      No network cards? 802.11ac is very fast and much more reliable than years ago.
                      Using Windows printer drivers makes life much easier for everyone if using something like ddoc.
                      I only put software on the file server and all stations map to the server to start a batch file.
                      Each work station uses the computer name to create unique output files that ddoc will print.
                      Just another way ...

                      Not sure why a TSR couldn't be bypassed to shell or use exit codes to shell and print.
                      https://www.tesla.com/roadster

                      Comment

                      Working...
                      X