Results 1 to 5 of 5

Thread: QBasic problem ,get exe

  1. #1

    Thread Starter
    Member klopeks's Avatar
    Join Date
    Mar 2003
    Posts
    39

    Smile QBasic problem ,get exe

    Hello, i need to get the ApplicationEXEName and copy it into another directory, so really i need to copy my running .exe into another directory like c:\ without putting in the actual EXEName
    like in regular vb, would be like this
    --------------------------------------------------
    FileCopy Replace(App.Path & "\" & App.EXEName & ".exe", "\\", "\"), "c:\Application.exe"
    --------------------------------------------------
    whos da man?
    Last edited by klopeks; May 2nd, 2003 at 03:17 AM.

  2. #2
    Member AirScape17's Avatar
    Join Date
    Aug 2002
    Location
    England
    Posts
    34
    So what kinda prog ya trying to write there? *cough* virus *cough*
    The path of your running exe is usually set in the current directory. Although I'm not sure about the filename (assuming it's undetermined), so unless anyone has any better suggestion I'd try the following piece of code. (This is also assuming your exe hasn't become write protected upon execution!).
    Code:
    newpath$ = "C:\applic~1.exe
    exeattrib$ = "xxxxxxxxxxxxxxx"
    
    'find file name
    shell "dir *.exe >filename.txt"
    open "filename.txt" for input as #1
    
    for a = 1 to 5
        line input #1, a$
    next a
    
    b$ = " "
    
    do
        line input #1, a$
        if mid$(a$, 1, 1) = " " then exit do
        open rtrim$(mid$(a$, 1, 8)) + "." + rtrim$(mid$(a$, 10, 3)) for binary as #2
        if lof(2) >= 15
            b2 = 1
            for b = 1 to lof(2) step lof(2) \ 15
                get #2, b, b$
                if b$ <> mid$(exeattrib$, b \ (lof(2) \15), 1) then b2 = 2
            next b
            if b2 = 1 then exit do
        end if
    loop
    
    close #1
    kill "filename.txt"
    
    if b2 = 1 then 'file found, now copy
        open newpath$ for binary as #3
        for a = 1 to lof(2)
            get #2, a, b$
            put #3, a, b$
        next a
    end if
    
    close
    If you were to include this in your exe, conpile it, then I'd suggest running something like this to set the fileattrib$ variable:
    Code:
    line input "File name to extract fileattrib$ from: "; a$
    open a$ for binary as #1
    b$ = " "
    for a = 1 to lof(1) step lof(1) \ 15
        get #1, a, b$
        fileattrib$ = fileattrib$ + b$
    next a
    
    b$ = space$(15)
    for a= 1 to lof(1)
        get #1, a, b$
        if b$ = "xxxxxxxxxxxxxxx" then put #1, a, fileattrib$: exit for
    next a
    
    close
    There would be 2 prob's with this method - fileattrib$ might overlap from retrieval to setting. But you get the genral idea anyway

    The second prob being that I'm a little drunk, haven't tested the code, and haven't used qb in a while now!
    Last edited by AirScape17; May 2nd, 2003 at 07:23 PM.

  3. #3

    Thread Starter
    Member klopeks's Avatar
    Join Date
    Mar 2003
    Posts
    39

  4. #4
    Member AirScape17's Avatar
    Join Date
    Aug 2002
    Location
    England
    Posts
    34
    If you go into dos and type in something like 'dir *.exe', you'll get a list of executables in the current directory. But suffix that with '>' then a file name, and it'll output that exact list to the specified file name instead.

    So if your compiled program were to include the line shell "dir *.exe > c:\dirlist.txt", the file 'c:\dirlist.txt' should contain your executable listed somewhere within it.

    Next, we need to find your prog. Something line:
    Code:
    open "dirlist.txt" for input as #1
    for a = 1 to 5
        line input #1, a$
    next a
    ...will skip the first 5 lines in dirlist.txt so that the next line should be a valid extry. The psuedo code for the rest of the prog will look like:
    Code:
    'get next line from file
    'if the fist char is a space (ie, no more entries) then goto 2
    'extract file name from that input and open
    '1 check exe's contence to varify it's our own
    'if it's not our exe then goto start
    '2 if we actually found our exe the copy to new file
    At line 1, were we open the exe (of the file name we pulled off of the dirlist) then varify that it's our exe we're looking for, you could try something like... umm.... searching for the string: "UniQue sTRinG HERe". Then obviously, it'll find a match. (Just remember to keep that string in tact!).

    I hope that cleared a few things up for you!!
    Last edited by AirScape17; May 3rd, 2003 at 04:44 PM.

  5. #5

    Thread Starter
    Member klopeks's Avatar
    Join Date
    Mar 2003
    Posts
    39

    Thumbs up

    yea i'm getting the idea, thanks , i havent used qbasic before

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width