VBRocks
asked on
Is it possible to add an executable to your project, and use it?
Hi, I know it's possible to add an executable to your project... I've already done that (Project menu |
Add Existing Item...).
My question is, can you use it internally? If so, how?
My situation is: My company purchased a command line utility that we want to deploy to our clients.
I wrote an application that uses this command line utility. So, we will have to send both executables
(mine and the command line utility) to our clients.
I would rather add the command line utility to my project, and somehow internally send the command line
arguments to it and execute it. This would enable me to send 1 executable to our clients, instead of 2,
simplifying life, and protecting the command line utility that we purchased.
So is it possible?
Thanks for your help.
Add Existing Item...).
My question is, can you use it internally? If so, how?
My situation is: My company purchased a command line utility that we want to deploy to our clients.
I wrote an application that uses this command line utility. So, we will have to send both executables
(mine and the command line utility) to our clients.
I would rather add the command line utility to my project, and somehow internally send the command line
arguments to it and execute it. This would enable me to send 1 executable to our clients, instead of 2,
simplifying life, and protecting the command line utility that we purchased.
So is it possible?
Thanks for your help.
WEll can you not use the built in onetouchdeployment...this puts executables on the web so one can access them without a command line
Hi
You can use Process class to invoke external processes like you batch...
Here is a sample code...
I hope it will be useful
Bye
You can use Process class to invoke external processes like you batch...
Here is a sample code...
I hope it will be useful
Bye
try
{
Process process = new Process();
process.StartInfo.FileName = //What you want to execute
process.StartInfo.Arguments = //the arguments
process.Start();
while (!process.HasExited) if (DateTime.Now.Subtract(process.StartTime).Minutes >= 15/*Timeout*/) return;
}
catch (Exception e)
{
MessageBox.Show("Error" + e.Message, "Error");
}
ASKER
No worries. I'm working with a Windows app.
ASKER
Hi anmalaver,
I do know how to use that, but that is for an external executable. Any ideas how to execute a process
on an executable that is internal?
I do know how to use that, but that is for an external executable. Any ideas how to execute a process
on an executable that is internal?
m... ok, I understand...
Let me see...
Let me see...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok. I think I can work with that. Thank you anmalaver!
Here's what I did:
Private Shared Function CreateExecutable() As String
'Create a temporary path for our executable
Dim tempPath As String = IO.Path.ChangeExtension(IO .Path.GetT empFileNam e(), ".exe")
'Get the Current Assembly information
Dim currentAssembly As Reflection.Assembly = Reflection.Assembly.GetExe cutingAsse mbly()
'Resource will store the full name of our embeded dpe.exe resource file
Dim resource As String = String.Empty
'Get all resource names and find the full embeded dpe.exe resource file name
Dim arrResources As String() = currentAssembly.GetManifes tResourceN ames()
For Each resource In arrResources
If resource.IndexOf("dpe.exe" ) > -1 Then _
Exit For
Next
'Open the Embeded dpe.exe resource
Dim resourceStream As IO.Stream = currentAssembly.GetManifes tResourceS tream(reso urce)
'Open FileStream to write out to
Dim writer As New IO.FileStream(tempPath, IO.FileMode.Create, IO.FileAccess.Write)
'Write out all bytes of the stream
Const size As Int16 = 4096
Dim bytes(size) As Byte
Dim numBytes As Int32 = 0
Do
numBytes = resourceStream.Read(bytes, 0, size)
writer.Write(bytes, 0, numBytes)
Loop While (numBytes > 0)
'Close both streams and clean up
resourceStream.Close()
resourceStream.Dispose()
writer.Close()
writer.Dispose()
Return tempPath
End Function
Here's what I did:
Private Shared Function CreateExecutable() As String
'Create a temporary path for our executable
Dim tempPath As String = IO.Path.ChangeExtension(IO
'Get the Current Assembly information
Dim currentAssembly As Reflection.Assembly = Reflection.Assembly.GetExe
'Resource will store the full name of our embeded dpe.exe resource file
Dim resource As String = String.Empty
'Get all resource names and find the full embeded dpe.exe resource file name
Dim arrResources As String() = currentAssembly.GetManifes
For Each resource In arrResources
If resource.IndexOf("dpe.exe"
Exit For
Next
'Open the Embeded dpe.exe resource
Dim resourceStream As IO.Stream = currentAssembly.GetManifes
'Open FileStream to write out to
Dim writer As New IO.FileStream(tempPath, IO.FileMode.Create, IO.FileAccess.Write)
'Write out all bytes of the stream
Const size As Int16 = 4096
Dim bytes(size) As Byte
Dim numBytes As Int32 = 0
Do
numBytes = resourceStream.Read(bytes,
writer.Write(bytes, 0, numBytes)
Loop While (numBytes > 0)
'Close both streams and clean up
resourceStream.Close()
resourceStream.Dispose()
writer.Close()
writer.Dispose()
Return tempPath
End Function