Solved

Cannot launch .exe in C#

Posted on 2014-01-03
20
867 Views
Last Modified: 2014-01-13
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
Comment
Question by:TeknikDev
  • 6
  • 3
  • 2
  • +5
20 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
Comment Utility
Permissions?
TaskManager?
EventViewer?

There are number of tools to monitor what's happend...
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
With that path my first thought is permissions.
My second thought is does the file exist in that location?  (Check, don't assume)
0
 

Author Comment

by:TeknikDev
Comment Utility
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
 

Author Comment

by:TeknikDev
Comment Utility
Anyone?
0
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
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
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
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
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Expert Comment

by:Ashok
Comment Utility
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
 
LVL 13

Accepted Solution

by:
Naman Goel earned 500 total points
Comment Utility
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
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
>>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
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
How do you execute files other than .exe??
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
.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
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
>> 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
 
LVL 13

Expert Comment

by:Naman Goel
Comment Utility
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
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
>>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
 
LVL 13

Expert Comment

by:Naman Goel
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now