TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
DrDavid Bowman
NA
5
7.1k
Loading up an External EXE Program into Memory and Run it
Aug 18 2019 6:48 PM
A very good day to you All,
I hope you are doing Very Well,
Please kindly see the attached code for a C# Program
This C# Program will Load an External EXE Program into Memory
This C# Program will then do a Function Call to Run that EXE Program that sits in Memory
The External EXE Program is an Executable that sending Keypress to the Desktop
It does nothing except sending out keypresses to the Desktop
The Calling Function to Run the EXE From Memory is listed below
//Execute the assembly
exeAssembly.EntryPoint.Invoke(null, null); //no parameters
Is there any way for me to call the above function as many times as I want so that I can keep on running the EXE from memory as many times as I want ?
The below code works for the 1st call to run the EXE
On the second call to run the EXE - The code returns an error message and is not able to proceed any further
What I would like to be able to do is to
1) Load the EXE into Memory
2) Set it up in such a way where I can Call the Invoke Function as many times as I wish in order to Run the External Keypress Program as many times as I wish
Is there any way to do this ?
Secondly I would like for the external EXE program to be able to interact with all the surrounding applications that are running on the Windows Desktop
This is because the external EXE program is actually a program that sends out keypresses
I am calling and running this external EXE program multiple times in order to deliver multiple keypresses many many times over
The keypresses are to interact with any Running APP that I have opened in the Windows desktop
And thus I would like for this keypresses app to be able to affect and interact with all the apps on the Windows desktop
How can I modify the code so that I can allow for this external EXE to be able to interact with all running desktop apps?
using
System;
using
System.Collections.Generic;
using
System.Windows.Forms;
//Needed
using
System.Reflection;
using
System.IO;
namespace
MemoryLauncher
{
static
class
Program
{
///
/// The main entry point for the application.
///
[STAThread]
static
void
Main()
{
RunInternalExe(
"x.exe"
);
}
private
static
void
RunInternalExe(
string
exeName)
{
//Get the current assembly
Assembly assembly = Assembly.GetExecutingAssembly();
//Get the assembly's root name
string
rootName = assembly.GetName().Name;
//Get the resource stream
Stream resourceStream = assembly.GetManifestResourceStream(rootName +
"."
+ exeName);
//Verify the internal exe exists
if
(resourceStream ==
null
)
return
;
//Read the raw bytes of the resource
byte
[] resourcesBuffer =
new
byte
[resourceStream.Length];
resourceStream.Read(resourcesBuffer, 0, resourcesBuffer.Length);
resourceStream.Close();
//Load the bytes as an assembly
Assembly exeAssembly = Assembly.Load(resourcesBuffer);
//Execute the assembly
exeAssembly.EntryPoint.Invoke(
null
,
null
);
//no parameters
}
}
}
Reply
Answers (
3
)
Designing a database for c# program and UI
ASP.State DB session expiring earlier than expected duration