简体   繁体   中英

.EXE does not start with Process.Start(path_to.exe)

I have created DatePicker.exe with Inno Setup.

Directory: C:\Program Files (x86)\MyJournal

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        8/17/2017   4:44 AM                Log
-a----        8/17/2017   3:30 PM           2747 appointments.bin
-a----        8/17/2017   1:46 PM          45056 DatePicker.exe
-a----         8/8/2017   8:35 AM            189 DatePicker.exe.config
-a----        8/17/2017   1:46 PM          79360 DatePicker.pdb
-a----        8/15/2017  10:17 AM           1122 DatePicker.SED
-a----        8/17/2017   1:47 PM          12946 unins000.dat
-a----        8/17/2017   1:47 PM         725157 unins000.exe

This does not work - DatePicker.exe does not open, and there are no errors:

Process.Start(@"C:\Program Files (x86)\MyJournal\DatePicker.exe");

But this works

Process.Start(@"C:\Users\Public\Desktop\MyJournal.lnk");

Link from desktop points to the same path as above.

Why does the first example not work?

UPDATE.

As suggested I have tried to set the working directory. But no luck so far. This did not work for me.

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WorkingDirectory = @"C:\Program Files(x86)\MyJournal";
startInfo.FileName = @"DatePicker.exe";
startInfo.CreateNoWindow = true;

Process myProcess = Process.Start(startInfo);

UPDATE # 2 ;

It finally works with
var psi = new ProcessStartInfo(@"C:\Program Files (x86)\MyJournal\DatePicker.exe");
                psi.WorkingDirectory = @"C:\Program Files (x86)\MyJournal";
                Process.Start(psi);

Is it possible it's not running because the default directory is not set? Try using a StartInfo parameter instead, and set the working directory to the same as the program directory.

Have you tried starting it from the Command Promt? If the application is working fine when manually opening it, it may be because of UseShellExecute begin true by default.

Try startInfo.UseShellExecute = false;

According to MSDN startInfo.CreateNoWindow = true; is ignored when UseShellExecute is true or if the UserName and Password properties are not null .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM