Dll cannot loaded when running application from another application - c#

I have two application, first is my main application and second is application to call main application. I want to run my first application from second application. why when my first application was calling from second application, the DLL could not be loaded?
Can someone tell me and help me?

Launch console application from another application:
using System.Diagnostics;
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.Arguments = "Some argument";
processInfo.FileName = "Your console .exe path";
int exitCode;
using (Process process = Process.Start(processInfo))
{
process.WaitForExit();
exitCode = process.ExitCode;
}

try this:
Process ExternalProcess = new Process();
ExternalProcess.StartInfo.FileName = "ConsoleApplication.exe";
ExternalProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
ExternalProcess.Start();
ExternalProcess.WaitForExit();
if this won't work, kindly share the error.

I solved my problem with #Sudipta Maiti answer and I add dll into second application, and I store both off my application in one folder.
:)
thank you

Related

Start one windows form application from another windows form application in C# [duplicate]

I need help in trying to execute an executable from my C# application.
Suppose the path is cPath, the EXE is HHTCtrlp.exe and the parameter that has to be passed is cParams.
How would I go about this?
The reason why the path is a variable is that there are 3 different EXE files to run and the path will change depending on which one will run, same with the parameter string.
Any help would be greatly appreciated.
To start the process with parameters, you can use following code:
string filename = Path.Combine(cPath,"HHTCtrlp.exe");
var proc = System.Diagnostics.Process.Start(filename, cParams);
To kill/exit the program again, you can use following code:
proc.CloseMainWindow();
proc.Close();
System.Diagnostics.Process.Start("PATH to exe", "Command Line Arguments");
ProcessStartInfo startInfo = new ProcessStartInfo(string.Concat(cPath, "\\", "HHTCtrlp.exe"));
startInfo.Arguments =cParams;
startInfo.UseShellExecute = false;
System.Diagnostics.Process.Start(startInfo);

Launch an app running as admin - by passing the filename.sln (UseShellExecute)

I can call Process.Start(filename.sln) and it launches VisualStudio with that solution.
But doing so using ProcessStartInfo with Verb="runas" and I get an exception. Even with UseShellExecute=true.
Is there a way to launch an app running as admin where I pass it the app's data file and don't have the application.exe filename?
Found the answer - when you run as admin you can only give it the executable file, not the app for the program to run. So you have to pass devenv.exe, not filename.sln
ProcessStartInfo processInfo = new ProcessStartInfo(); //new process class
processInfo.Verb = "runas"; //wanna admin rights
processInfo.FileName = sDevPath + "devenv.exe"; //exe file path
processInfo.Arguments = sPrjPath + "mConverter.sln"; //sln file as argument
try
{
Process.Start(processInfo); //try to start
}
catch (Win32Exception)
{
//oops
}

Permission issues when running JScript from C# Console application

I'm trying to run a Jscript task from a C# console application.
The Jscipt file is not mine so I can't change it. The script moves some files and this is what is causing the issues.
When I run the script manually, i.e. form the shell it executes correctly. When I try and run the script from my console application the bulk of the process runs but I get a ":Error = Permission denied" error when it tries to move the files.
I've tried every permutation of the Diagnostics.Process class that I can think of but I've had no luck.
My current code:
Process process = new Process();
process.StartInfo.WorkingDirectory = Path.GetDirectoryName((string)path);
process.StartInfo.FileName = #"cmd.exe";
process.StartInfo.Arguments = "/C " + (string)path;
process.StartInfo.UseShellExecute = false;
process.StartInfo.Verb = "runas";
process.StartInfo.LoadUserProfile = true;
process.StartInfo.Domain = "admin";
process.StartInfo.UserName = #"cardax_sync_test";
process.StartInfo.Password = GetSecureString("abc123");
process.Start();
process.WaitForExit();
Any ideas?
Thanx
Rookie Mistake!
I forgot to close the text reader that creates one of the input files for the jscript.
I'll submit this question for deletion when it get's old enough. Don't want more useless info clogging up the net!

How to start a process in the same folder as its executable

I'm trying to start an application programatically, but it always runs it in the folder of my application... For example:
If my app is located in C:\MyApp\myapp.exe and the other app is in C:\OtherApp\otherapp.exe, how can I start the other app in the folder in which it resides, rather than in the folder where my app resides?
Here is how I start the other app:
private void StartApp(OtherApp application)
{
Process process = new Process();
process.StartInfo.FileName = application.FileName;
process.StartInfo.Arguments = application.AppName;
process.Start();
}
I guess you mean ProcessStartInfo.WorkingDirectory Property
Use process.StartInfo.WorkingDirectory = pathToTheFolder;.
Just set the WorkDirectory property.
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(application.Filename);

Launching an application (.EXE) from C#?

How can I launch an application using C#?
Requirements:
Must work on Windows XP and Windows Vista.
I have seen a sample from DinnerNow.net sampler that only works in Windows Vista.
Here's a snippet of helpful code:
using System.Diagnostics;
// Prepare the process to run
ProcessStartInfo start = new ProcessStartInfo();
// Enter in the command line arguments, everything you would enter after the executable name itself
start.Arguments = arguments;
// Enter the executable to run, including the complete path
start.FileName = ExeName;
// Do you want to show a console window?
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;
int exitCode;
// Run the external process & wait for it to finish
using (Process proc = Process.Start(start))
{
proc.WaitForExit();
// Retrieve the app's exit code
exitCode = proc.ExitCode;
}
There is much more you can do with these objects, you should read the documentation: ProcessStartInfo, Process.
Use System.Diagnostics.Process.Start() method.
Check out this article on how to use it.
Process.Start("notepad", "readme.txt");
string winpath = Environment.GetEnvironmentVariable("windir");
string path = System.IO.Path.GetDirectoryName(
System.Windows.Forms.Application.ExecutablePath);
Process.Start(winpath + #"\Microsoft.NET\Framework\v1.0.3705\Installutil.exe",
path + "\\MyService.exe");
System.Diagnostics.Process.Start("PathToExe.exe");
System.Diagnostics.Process.Start( #"C:\Windows\System32\Notepad.exe" );
If you have problems using System.Diagnostics like I had, use the following simple code that will work without it:
using System.Diagnostics;
Process notePad = new Process();
notePad.StartInfo.FileName = "notepad.exe";
notePad.StartInfo.Arguments = "mytextfile.txt";
notePad.Start();
Additionally you will want to use the Environment Variables for your paths if at all possible: http://en.wikipedia.org/wiki/Environment_variable#Default_Values_on_Microsoft_Windows
E.G.
%WINDIR% = Windows Directory
%APPDATA% = Application Data -
Varies alot between Vista and XP.
There are many more check out the link for a longer list.
Just put your file.exe in the \bin\Debug folder and use:
Process.Start("File.exe");
Use Process.Start to start a process.
using System.Diagnostics;
class Program
{
static void Main()
{
//
// your code
//
Process.Start("C:\\process.exe");
}
}
Try this:
Process.Start("Location Of File.exe");
(Make sure you use the System.Diagnostics library)

Categories

Resources