Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting another application from within C# code

How can I start another application from within C# code? I can't get this piece to work correctly

    System.Diagnostics.Process.Start(@"%userprofile%\AppData\Local\Google\Application\chrome.exe");

Edit: Wow I was dumb and just noticed what I forgot in the filepath. Thanks for the answers though they helped teach me some other useful things.

like image 330
Rumel Avatar asked Jan 03 '12 07:01

Rumel


People also ask

How can I invoke another program from within AC program?

In Linux system apart of system() function call, you can use following exec() library functions to execute new program.

Can a program be invoked from another program?

As I know, any address in a program only belongs itself, meaning that you can't invoke a function of another program thought its address. Data is code, code is data. As soon as your exploit payload (i.e. machine code) is read into memory by the process you're attacking, it has an address in the target process.

When a program call another program file the program must have the return command at the end?

When a program calls another program file, the called program must have the RETURN command at the end. False 57.


2 Answers

I don't think Process.Start expands environment variables for you. Try this:

var path = Environment.ExpandEnvironmentVariables(@"%userprofile%\AppData\Local\Google\Application\chrome.exe");
Process.Start(path);
like image 61
ChrisWue Avatar answered Sep 28 '22 19:09

ChrisWue


try this link for starting external program Also try this Similar Question on stackoverFlow

this is an example here

 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");

And in your case ,write the following on top where all the using namespaces are listed

        using System.Diagnostics;
        using System;

so then in your code directly write the above code...

like image 40
PresleyDias Avatar answered Sep 28 '22 18:09

PresleyDias