Process.Start fails without ".exe" extension - vb.net

I am trying to running an executable without ".exe" extension, when I'm trying to run my ".bin" file (actually it's .exe but I renamed it with .bin for prevent confusion) It's shows to me program selector windows.
How can I avoid that?
If File.Exists("client.bin") Then
Process.Start("client.bin", param)
delay(100)
Terminate()
Else
MsgBox(Lang(6), MsgBoxStyle.Critical, TITLE)
Terminate()
End If

Your code is essentially asking the operating system's runtime to handle the file. It uses the file extension to determine what it should do. For example, a .doc extension would be opened with Word (ultimately the process handler would pass the file path as an argument to the target application: winword.exe {filepath}.doc).
Windows doesn't know how to handle a .bin file, so it turns to you for help - hence the program selector prompt.
You can only execute an executable, just change the file extension back to .exe.
What confusion are you trying to prevent? For example, if you're trying to stop users from accidentally running the application, can't you move it to a different place where it might be a little harder to find?
If you really want to call it something else (and this is really, really messy), you could rename the file just before and after you run it. However, I would highly recommend you don't do this, it's really bad design!

Related

Getting batch variables

Hi there. I am busy with making kind of script in batch.
I need to insert into it kind of "Resume" function.
I know how to write variables into a file.
But is it possbile to get it back?
Is it possible to get variables from registry?
I found a nice BAT => EXE converter. It looks really professional if you run .exe in place of .bat. I would like the user to download .exe installer of my batch program, and install the real program. But is it possible to install it (place file of program) as .exe? I don't know much about .exe languages.
If I understand your questions correctly,
Do you want to read a variable that was previously written to a file back into the batch script? Yes, it is possible to read a file into a variable as long as you know the file's format.
Yes, it is possible to read keys and values from the registry using the reg command.
Once you convert a .bat script into an .exe you can distribute it however you like. Place it in a .exe installer, zip it in a archive.

Implement a self extracting archive?

I know i can use 7z or winrar but i want to learn this for myself.
How would i implement a self extracting archive? I can use C# or C++ but let me run down the problem.
When i open the exe i need some kind of GUI asking where to extract the files. Once the user says ok I should obviously extract them. I implemented a simple example in C# winforms already BUT my problem is HOW do i get the filenames and binary of the files into an exe?
One upon a time i ask Is it safe to add extra data to end of exe? and the answer suggested if i just add data to the end of the exe it may be picked up by a virus scanner. Now its pretty easy to write the length of the archive as the last 4bytes and just append the data to my generic exe and i do believe my process can read my own exe so this could work. But it feels hacky and i rather not have people accuse me of writing virus just because i am using this technique. Whats the proper way to implement this?
Note: I checked the self-extracting tag and many of the question is how to manipulate self extracting and not how to implement. Except this one which is asking something else Self-extracting self-checking executable
-edit- I made two self extracting with 7z and compared them. It looks like... well it IS the 7z.sfx file but with a regular 7z archive appended. So... there is nothing wrong with doing this? Is there a better way? I'm targeting windows and can use the C# compiler to help but i don't know how much extra work or how difficult it may be programmatically and maybe adding data to end of exe isnt bad?
It is possible. I used the following technique once, when we needed to distribute updates for the application, but the computers were configured so that the end user had no permissions to change application files. The update was supposed to log on to administrator account and update required files (so we came across identical problem: how to distribute many files as a single executable).
The solution were file resources in C#. All you need to do is:
Create a resource file in your C# project (file ending with .resx).
Add new resource of type "file". You can easily add existing files as byte[] resources.
In program you can simply extract resource as file:
System.IO.FileStream file = new System.IO.FileStream("C:\\PathToFile",
System.IO.FileMode.OpenOrCreate);
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(file);
writer.Write(UpdateApplication.Data.DataValue, 0, UpdateApplication.Data.DataValue.Length);
(Here UpdateApplication.Data denotes binary resource).
Our solution lacked compression, but I believe this is easily achieved with libraries such as C#ZipLib.
I hope this solution is virus-scanner-safe, as this method creates complete, valid executable file.

VB.Net embedded Flash Object creates problems

Ì have had this problem in a number of projects and I have almost given up. I am sure there is a solution though. When I insert a Flash object in a VB.Net Windows Forms application, it works fine for a little while and then I see this error in the Design Screen. I am using Visual Studio 2010
Could not load file or assembly 'Interop.ShockwaveFlashObjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
I have read several descriptions of why this happens, and apparently it has something to do with strong naming (or lack thereof), but have not found a solution yet. I used Add Reference->COM->Shockwave Flash (C:\Windows\SysWOW64\Macromed\Flash\Flash32_11_2_202_235.ocx) If I ignore the error it appears to work fine, but I don't want my users to have a problem.
I know I can use a browser control and play the Flash in that, but for reasons I won't get into, I have to use a Flash control. Any ideas would help.
Okay. I can't promise this to work for you, but it worked for me.
First, you have to locate a file on your computer titled AxImp.exe. You have to run it from the command prompt. This file is located (for me at least) here:
C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\x64
Once you do find and run it, you have to point it to the correct Flash.ocx file you're using, like so:
AxImp.exe <path>\Flash.ocx
Once you've done that you should end up with 2 DLL files in the same directory as the .ocx file. One called AxShockwaveFlashObjects.dll and another called ShockwaveFlashObjects.dll.
You don't care about ShockwaveFlashObjects.dll, just AxShockwaveFlashObjects.dll.
Grab that file and the Flash*.ocx file and paste them into the project directory.
Then include them into your references. This should open up two new references, AxShockwaveObjects and ShockwaveObjects.
Make sure you're Using both of them.
After this, you have to register the Flash*.ocx using RegSvr32 from your command prompt (make sure to run CMD in admin mode). That is done like so:
C:\RegSvr32 <path>\Flash.ocx
This worked for me. I was having the exact same problem (which is what led me here). It could be a half backed hack workaround but for now, that's how it worked for me.
Let me know if it works for you or not.
Hope it goes well for you.
I know this is an old post but I had this issue yesterday and the solution, at least in my case, was very simple. All I had to do was to change the Platform and Platform Target to x86 (Build tab of project property).

Problems when editing. Exe file sc_serv.exe shoutcast

I need to edit an executable file from shoutcast, sc_serv.exe. If I just open this file in notepad, and save again without editing anything, after trying to run the program I get the message:
Program too big to fit in memory
How do I open and save the executable without interfering with its operation?
Thank you.
You can't just blindly edit an EXE, especially not with Notepad.
If you're trying to edit the admin interface for SHOUTcast, the best thing to do is proxy its returned data through PHP, or something else server-side, to create your own interface. I've done this, and found it to be fairly straight forward.

Creating File Associations in VB.NET?

How would one go about associating a file type with his application? I know how to read the command line arguments but I am not sure how I can "register" the file extension with Windows. Furthermore, my application is a stand-alone executable, so how would I keep Windows up-to-date on the location of my program?
I did a fair amount of searching and all I could find were old articles that didn't explain everything. How can I create file associations to a stand-alone executable in VB.NET?
Everything is handled by the registry. If you want to make your program self-register it's current location when run see this example.
http://www.codeproject.com/KB/dotnet/System_File_Association.aspx