write in file
Results 1 to 5 of 5

Thread: write in file

  1. #1
    Junior Member
    Join Date
    Mar 2002
    Posts
    26

    Question write in file

    hi...

    could you tell me how to write to autoexec.bat with VB/java/c ....

    please... i really want to know.... :P

    thanks for your help guys..

    ~6~

    * if you like you can send the source code on how to do it to may email: wh_th_world@lycos.com
    I am newbie who want to be programmer (~6~)

  2. #2
    Senior Member
    Join Date
    Feb 2002
    Posts
    170
    In VB you would use the FileSystemObject.

    <dry coded>
    Dim objFSO As Scripting.FileSystemObject
    Dim objFSO As File 'Or something...

    Set objFSO = New Scripting.FileSystemObject

    Set objFile = objFSO.OpenTextFile("c:\autoexec.bat",ForWriting)' There should be another param here. Check the overloads in your documentation.

    objFile.Write("yadayada")
    objFIle.Close()
    Set objFile = Nothing
    Set objFSO = Nothing
    </dry coded>

    In Java I guess you'd use a streamwriter but I'm not sure. Check google or the documentation on VB for more info. Writing to files is very straightforward.

    Cheers,
    Mankan

    \"The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise.\"
    - Edsger Dijkstra

  3. #3
    Mankan > You don't need to open the FileSystemObject if you know The autoexec.bat are located on C:\ on every pc.......

    FileSystemObject is god to use if you shall find the % systemroot % or som thing like that!

  4. #4
    The Iceman Cometh
    Join Date
    Aug 2001
    Posts
    1,209
    Autoexec.bat isn't always located on C:\. On Windows XP, it's down in the Windows folder, and, by default, it still gets parsed at logon, so, if you want to use your program on Windows XP (or 2000 for that matter), you would have to use the FileSystemObject.

    AJ

  5. #5
    Member
    Join Date
    Dec 2001
    Posts
    94
    using c++ you could do like this

    #include<fstream.h>
    #include<dir.h>
    int main()
    {
    ofstream fout;
    chdir("\\");
    fout.open("AUTOEXEC.BAT");
    fout<<"CLS\nDIR";
    fout.close();
    return 0;
    }

    this will write CLS in the 1st line and DIR in the 2nd line but it'll clean the contents first, use ios::app if you want to append in the end.

Posting Permissions

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