Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create an executable with Copy & Paste

Status
Not open for further replies.

Helen1greece

Technical User
Jun 4, 2003
85
GR
I tried to open an executable file with windows notepad.Then I copied and pasted the letters which where in the notepad after opening the file in a textbox on a project in Visual Basic.Then with a command button I did this...

Open "C:\something.exe" For Output As #1
Print #1, Text1.Text
Close #1

Then I executed the created file and it doesn't work.Why is it doing that?Is there a way to make it work?
 
Notepad may be inserting special characters and breaks etc.

Why are you trying this??
 
I'm just curious,because somebody told me that is possible to do it.Do you have any way in mind?
 

Using the FileCopy command should do the same

I tried opening calc.exe in DOS Edit and Saving as another filename. I had to open the file in Binary mode for it to work.
 
Just curious why are u doing this.. and more over, why is notepad a medium?

You may try this function tho...

Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long

Public Function APIFileCopy(src As String, dest As String, _
Optional FailIfDestExists As Boolean) As Boolean

Dim lRet As Long

lRet = CopyFile(src, dest, FailIfDestExists)
APIFileCopy = (lRet > 0)

End Function

Use it like...

APIFileCopy "C:\something.exe", "C:\somethingcopy.exe"

 
When you open a binary file in Notepad, it replaces all the null characters (Chr$(0)) with the space characters (Chr$(32)).

The reasons behind this that Notepad uses an ordinary edit window for diplaying its content which cannot display null characters, infact the null character signals the end of the string. When you copy the text from notepad, paste in to your program and save it to disk, the exe file created in this way is corrupted as all the null characters in the original file are replaced with spaces resulting in loss of information.

If you open a file in Notepad and save it, it will be corrupted even if you do not change anything, the reason being the same that when the file is saved, all null characters are replaced with spaces.

MS-DOS Edit application has a special binary mode for opening binary files and displaying its content without loss of information. You can also edit binary files (like exe files) in binary mode and save them without destroying the contents.

Simply put, you cannot handle binary files in text mode.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top