Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Leap from NT4 to Windows 10 and QBasic to VB Script idea  (Read 625 times)

0 Members and 1 Guest are viewing this topic.

DaveLembke

    Topic Starter


    Sage
  • Inventor of the Magna-Broom 3000 =)
  • Thanked: 596
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 7
Leap from NT4 to Windows 10 and QBasic to VB Script idea
« on: February 25, 2018, 09:20:16 AM »
About 3 years ago Foxidrive helped me greatly with a need that I had to be able to change some config files that had a value of N to switch to Y. The situation was that my employer does not allow external programs on media to be installed to these tightly controlled systems, BUT I am allowed/approved by my boss to code directly to the systems in their clean secured environment. So I can code/script openly or reading off of a piece of paper typing it all into notepad etc and saving it to run it etc.  :)

The systems originally were Windows NT4 and I needed to be able to change a value from N to Y in a bunch of config files on a weekly basis. I figured this might be able to be handled in batch. Foxidrive pointed out issues with pure batch to pull this off and suggested that instead the batch itself generates a QBasic program and runs that. That worked awesome until I heard that the NT4 systems that have been running since the late 1990s ( Pentium 3 700Mhz systems ) are to be replaced in the near future with modern computers running Windows 10 64-bit.

Knowing that 64-bit Windows 10 does not handle 16-bit programs, instantly I knew that I need to work on the next solution. ( Its too bad that Windows 10 64-bit doesnt support 16-bit programs because a solution could have been to connect the old and new system to their network and transfer over a file share QBasic from the NT4 system to Windows 10 and not have to rewrite a program all over again that is no longer supported by newer OS. )  ;D  I have done this sort of thing in the past where older Windows versions had programs that newer OS lacked and copy copying them forward you could legacy support older stuff on newer OS.

So the next solution is to once again pull this off without installing any external programs, it all has to happen within the natural environment of Windows 10 64-bit and I have to manually key in the program or script(s) within Windows environment. I was thinking that VB Script might be the best solution for this however looking for suggestions on a suitable replacement for the batch that generates this QBasic program below given the limitations?   It kind of stinks that I cant do this using any languages I am ok with and to pull this off involves scripting that I rarely dabble in. If allowed to create this in C++ I would do it up and compile it and bring it in as a EXE, but thats not allowed.  ::)

Below is the .bas program generated and run from within batch that runs for as many files exist at the root of where it is run. It searches for "LS: N" and "$LASTSORT N" and it changes the N's to Y's for "LS: Y" and "$LASTSORT Y" and saves the change to config files with .piv and .stf file extensions.

Quote
dir /b /a-d *.piv *.stf >tempfile.tmp

set "file=edit.bas"
>"%file%" echo OPEN "tempfile.tmp" FOR INPUT AS #3
>>"%file%" echo DO WHILE NOT EOF(3)
>>"%file%" echo  LINE INPUT #3, file$
>>"%file%" echo   OPEN file$ FOR INPUT AS #1
>>"%file%" echo   OPEN "temp.txt" FOR OUTPUT AS #2
>>"%file%" echo    DO WHILE NOT EOF(1)
>>"%file%" echo     LINE INPUT #1, a$: y=1
>>"%file%" echo     if not INSTR(ucase$(a$), "LS: N"        ) = 0 THEN ? #2,  "LS: Y"        : y=0
>>"%file%" echo     if not INSTR(ucase$(a$), "$LASTSORT N"        ) = 0 THEN ? #2,  "$LASTSORT Y"        : y=0
>>"%file%" echo     if y=1 then ? #2, a$
>>"%file%" echo    LOOP
>>"%file%" echo   CLOSE #1, #2
>>"%file%" echo   KILL file$
>>"%file%" echo   name "temp.txt" as file$
>>"%file%" echo   LOOP
>>"%file%" echo   SYSTEM

qbasic /run %file%





Salmon Trout



    Genius

    Thanked: 923
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Other
Re: Leap from NT4 to Windows 10 and QBasic to VB Script idea
« Reply #1 on: February 25, 2018, 01:59:36 PM »
Why doesn't anyone comment their code? I know memory was scarce but... ;)

VBScript should be fairly easy, would look very similar, and you probably won't need a temp file.

But first... is this a fair summary of what you want to do?

Batch:
List all files in current folder
with extensions piv OR stf
into a temp file

Create QBasic file:

' This is the QBasic file
' Read temp file line by line
OPEN "tempfile.tmp" FOR INPUT AS #3
DO WHILE NOT EOF(3)
  ' Get a filename from list
    LINE INPUT #3, file$
  ' Open that file for input
    OPEN file$ FOR INPUT AS #1

    ' Open a new temp file for output
     OPEN "temp.txt" FOR OUTPUT AS #2
     
    'Read listed file line by line; each time setting y flag to 1
    DO WHILE NOT EOF(1)
        LINE INPUT #1, a$: y=1
       
        ' *** Isn't this double-backwards logic? ***
        ' if line *contains* "LS: N" THEN write "LS: Y" to temp file; flip y flag to 0
        if not INSTR(ucase$(a$), "LS: N"        ) = 0 THEN ? #2,  "LS: Y"        : y=0
         
        ' if line *contains* "$LASTSORT N" THEN write "$LASTSORT Y" to temp file; flip y flag to 0
        if not INSTR(ucase$(a$), "$LASTSORT N"        ) = 0 THEN ? #2,  "$LASTSORT Y"        : y=0
         
        ' if y flag is still 1 then the the last 2 tests were failed
        ' write the input line unchanged out to temp file
        if y=1 then ? #2, a$
       
        ' Finished with this file
   LOOP
  ' Close input & output streams
   CLOSE #1, #2

  ' Delete original file
   KILL file$
' 'Rename temp file to original file
   name "temp.txt" as file$

' Keep going until finished with file list
LOOP


'Done; quit
SYSTEM
« Last Edit: February 25, 2018, 02:22:57 PM by Salmon Trout »

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 972
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows XP
Re: Leap from NT4 to Windows 10 and QBasic to VB Script idea
« Reply #2 on: February 25, 2018, 02:18:40 PM »
Quote
Why doesn't anyone comment their code? I know memory was scarce but.
You read my mind.  :)
.. and thank you for the nice Qbasic code.
The 32bitversion of Windows 10 will Qbasic to run.
« Last Edit: February 25, 2018, 02:32:02 PM by Geek-9pm »

DaveLembke

    Topic Starter


    Sage
  • Inventor of the Magna-Broom 3000 =)
  • Thanked: 596
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 7
Re: Leap from NT4 to Windows 10 and QBasic to VB Script idea
« Reply #3 on: February 25, 2018, 04:18:30 PM »
Hey Salmon ... sorry about no comments ... typed it from printed form as for I cant use any media to share it from the system so I got lazy in not wanting to type so much and from printing it I typed it as short form as I could to show the important parts if its entirety. :)

The situation I have is basically I have a folder with a bunch of text files with .piv and .stf file extensions, and just need to have a script that runs through all of these files and when it finds LS: N it changes that to LS: Y and when it finds string of $LASTSORT N it changes that to $LASTSORT Y ... BUT I have to type it into notepad and then save it as a script to run it as for there are very tight restrictions on no media brought into a heavily controlled environment of automation controls where there is an over paranoia of malware so being completely isolated they protect themselves. Nothing like supporting systems feeling like your hands are tied knowing a way to do it if I could do it up in C++ but I cant write and compile it and bring it in on media, so my boss has allowed for me to whatever I can type within the limitations of the Windows OS as allowed because no malware risk. Prior to this weekly we had to manually edit like 40 or 50 config files and that was a pain. I have used this qbasic generating and launching batch that foxidrive gave me as a solution for about 3 years now and it was working sweet to make the weekly config file edits a 5 second process vs 30 minutes of manually editing files. The software that is used to generate the config files needs to be edited by engineering to allow the person who sets these up to select Y or N ... BUT while an engineer helped me with how to get the machine to run the way we need it through manually editing these config files, they are hands off with updating their software because they require orders to spend time/money on that. Our site runs different than others so we have been given exception to run outside of normal operating parameters when I chatted with an engineer who was cool and pointed out how to get the machinery to behave as we needed it to. Basically its so strictly enforced no external media brought in that I can be fired if I brought in a program that would be a solution on a disc, but whatever I can key in at the local computer is allowed. I work as an electronics technician for industrial automation controls and because I have computer science skills/background I am the go to guy there for IT stuff and I work between engineering and local plant operations as well as their IT department and operations in which I am given some limited privileges of approval with tight restrictions beyond what other ET's get there to bend rules within limitations.

The way that all files were written from output of dir /b /a-d *.piv *.stf to the temp file was foxidrives original design for solution for this.

With comments added it looks correct.

Going from QBasic to VB Script I was thinking might be the easiest... further thought is that powershell might also be a solution as for that should be built into Windows 10 64-bit as well.

Its about time that they replace the old Pentium 3 computers running NT4 as for I have been frankensteining guts from other Pentium 3 donor systems of the same hardware flavor for the last 3 years as well as for they also have tight restrictions on what hardware has been approved by engineering for the machinery. So when a different machine with a computer with different part number I knew had the same internal hardware and was getting thrown away, I gutted it to have some spare parts on hand "mainly the motherboard" being the most important due to integrated network adapter use etc. Its kind of crazy that just about any computer could replace the Pentium 3 700Mhz with 384MB RAM but because of hardware restrictions imposed by engineering I cant use a healthy Pentium 4 or Pentium D system I have in place of it and need to play with strict hardware use rules which at times can be frustrating when a system is down and the solution is right in front of me, to replace the computer with another and add necessary drivers to make it communicate over the network, but everything gets its own part numbers and only can replace with same part number.

Prior to this career I was given full privileges to keep a food store chain running for 7 sites as system admin / IT guru for 6 years and any creative solution that worked and was legal was allowed in which I added all kinds of parachute solutions of redundancy and automatic fail-overs to get whatever failed service back up and running asap as for a point of sale system down is a VERY BAD thing for a business especially a food store that is busy.

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1083
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 8
Re: Leap from NT4 to Windows 10 and QBasic to VB Script idea
« Reply #4 on: February 25, 2018, 06:16:00 PM »
From your description it sounds like you effectively just need to do a string replace? Replace "LS: N" with "LS: Y" and "$LASTSORT N" with "$LASTSORT Y"?

If I understand correctly this should do what you want. Reads in a file, then replaces the text in every file specified in that file, writing the result to the same file.

Naturally, you should try it out before you go having it run amuck on the system(s) in question, but I'm sure that is your intention.

Code: [Select]
ForReading = 1
ForWriting = 2
InputFile = "D:\fileslist.txt"  'Set Input file. can be set to first argument provided with = WScript.Args(0)

Set FSO = CreateObject("Scripting.FileSystemObject")
Set FileListStream = FSO.OpenTextFile(InputFile, ForReading, False) ' Open the File List file.
InputFilesStr = FileListStream.ReadAll
FileListStream.Close

InputFiles = Split(InputFilesStr, Chr(13) + Chr(10))  'Split file list file contents we read in into an array.

For Each ReadFileName In InputFiles

    'read the contents of the file, close the file, replace the text, then write the replaced text back to the same file.
    Set InputStream = FSO.OpenTextFile(ReadFileName, ForReading, False)
    InputText = InputStream.ReadAll
    OutputText = Replace(Replace(InputText, "LS: N", "LS: Y"), "$LASTSORT N", "$LASTSORT Y")
    Set OutputStream = FSO.OpenTextFile(ReadFileName, ForWriting, False)
    OutputStream.Write OutputText
    OutputStream.Close

Next


I was trying to dereference Null Pointers before it was cool.

DaveLembke

    Topic Starter


    Sage
  • Inventor of the Magna-Broom 3000 =)
  • Thanked: 596
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 7
Re: Leap from NT4 to Windows 10 and QBasic to VB Script idea
« Reply #5 on: February 25, 2018, 08:26:09 PM »
Thank You BC

Tested it on my Windows 10 64-bit home computer after just changing path to C:\w10\fileslist.txt, saving as a .vbs, and making some test files. It replaced the correct strings in the files and fast. :)



[attachment deleted by admin to conserve space]