Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1038
  • Last Modified:

Cannot launch .exe in C#

All, for some reason in C# WPF, this does  not launch the executable. Nothing happens when I click on the button.

 Any thoughts?

private void button1_Click_3(object sender, RoutedEventArgs e)
        {
           System.Diagnostics.Process.Start(@"C:\windows\System32\rstrui.exe");
        }

Open in new window

0
TeknikDev
Asked:
TeknikDev
  • 6
  • 3
  • 2
  • +5
1 Solution
 
Ivo StoykovCommented:
Permissions?
TaskManager?
EventViewer?

There are number of tools to monitor what's happend...
0
 
AndyAinscowCommented:
With that path my first thought is permissions.
My second thought is does the file exist in that location?  (Check, don't assume)
0
 
TeknikDevAuthor Commented:
Hi Andy, yes the file is there and how do I fix the permission issue? I mean it is able to execute other files with other extensionsin that folder, but not any .exe files.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
TeknikDevAuthor Commented:
Anyone?
0
 
Carl TawnSystems and Integration DeveloperCommented:
Are you sure the procedure is actually being hit? It may just be that your event has become detached from the control so isn't being called.
0
 
Bob LearnedCommented:
You should redirect the StandardOutput and StandardError to see if there are any errors.

Here is an example for redirecting StandardOutput:

C# RedirectStandardOutput
http://www.dotnetperls.com/redirectstandardoutput

using System;
using System.Diagnostics;
using System.IO;

class Program
{
    static void Main()
    {
	// Setup the process with the ProcessStartInfo class.
	var start = new ProcessStartInfo()
	{
              FileName = @"C:\7za.exe", // Specify exe name.
	      UseShellExecute = false,
	      RedirectStandardOutput = true,
        };
	
	// Start the process.
	using (var process = Process.Start(start))
	{
	    //
	    // Read in all the text from the process with the StreamReader.
	    //
	    using (var reader = process.StandardOutput)
	    {
		var result = reader.ReadToEnd();
		Console.Write(result);
	    }
	}
    }
}

Open in new window

0
 
AndyAinscowCommented:
What happens if you run your C# WPF app with administrator rights ?  Do the button event start the exe without problems.  (If it does then it almost certainly a permissions issue).


ps.  I assume the exe does run if you double clicked it from the explorer - not that everything is actually working.
0
 
Vadim RappCommented:
rstrui.exe is usually located not in %windir%\system32 but in %windir%\system32\restore. There are several other files in that place, so even if you copied the exe to system32, maybe those files are missing. Try to launch it from c:\windows\system32\restore .
0
 
AshokCommented:
Please post part of the code from XAML file where you have defined button1.

This is to make sure that you have attached "button1_Click_3" event correctly.

Thanks,
Ashok
0
 
Naman GoelCommented:
Try this (you'll need to import System.Runtime.InteropServices):

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);

Open in new window

private void button1_Click_3(object sender, RoutedEventArgs e)
        {
 IntPtr ptr = IntPtr.Zero;
            if (Wow64DisableWow64FsRedirection(ref ptr))
            {
                Process myProcess = new Process();
                myProcess.StartInfo.UseShellExecute = true;
                myProcess.StartInfo.FileName = "rstrui.exe";
                myProcess.Start();
                Wow64RevertWow64FsRedirection(ptr);
            }
        }
                                  

Open in new window


This is all because of 64 bit process can't access 32 bit path.
0
 
AndyAinscowCommented:
>>I mean it is able to execute other files with other extensionsin that folder, but not any .exe files.

That was from an earlier comment.  Odd the path is fine for anything other than an exe as the target.
0
 
Vadim RappCommented:
How do you execute files other than .exe??
0
 
AndyAinscowCommented:
.pdf files will open with a pdf viewer.
.doc files will open with winword
.....

<appended>
Well I took it to mean the above, like you say almost anything else doesn't make sense (.bat files ?)
0
 
AndyAinscowCommented:
>> From the question: System.Diagnostics.Process.Start(@"C:\windows\System32\rstrui.exe");

This does work on my system
System.Diagnostics.Process.Start(@"C:\xyz\abc.doc");
will open the document abc.doc in winword (I have checked, this isn't an assumption)
0
 
Naman GoelCommented:
Hey all, All things can be run from Process.Start, it is same as opening any file from command prompt or run command in windows. The problem with system32 is it is in system native folder and can't be accessed by 64 bit process.
0
 
AndyAinscowCommented:
>>The problem with system32 is it is in system native folder and can't be accessed by 64 bit process.
The 'can't be accessed by 64 bit process' may well be correct BUT the asker does state earlier that there are no problems with the path for other types of file in that folder.  This puzzles me if the problem really is concerning a 64 bit process - all should fail to run/open in that case.

(Alternatively - giving incorrect information is a very good way not to get a problem solved, or at least not quickly.)
0
 
Naman GoelCommented:
For me I just tried the given code in my environment and It didn't worked for me either :( ,  then only I got into this solution with windows api.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 6
  • 3
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now