none
Starting a process from Click once

    Question

  • Hello; 

    I am opening a text file using process.Start() from within my application.  It works in debug mode, release mode but fails from a Click one deployment.  Is this a security thing?  My code is simple:

    string app =Properties.Settings.Default.editor;
    if (!File.Exists(app)) return;
    Process.Start(app, fname);

    I have checked that the fname exists. So there isn't any reason why it won't start.  It doesn't even start when the click once app is deployed on the development machine.  Oh, the app is in c:\program files (x86)\,. . . .

    Is it a security thing?  How can I get around it?

    Thanks.


    Robotuner
    Tuesday, September 27, 2011 9:40 PM

Answers

  • Thats the thing, the code is really simple:

    public static void OpenInEditor(string fname)
            {
                string app =Properties.Settings.Default.editor;
                Util.WriteToLogFile(string.Format("Editor: {0}", app));
                if (!File.Exists(app)) return;
                Process.Start(app, fname);
            }

    fname is checked before passing in to File.Exist(fname);

    Properties.Settings.Default.editor is set to the full path to Notepad++.exe.

    This runs every time when my WPF application is started in debug or release mode on my machine.  It works when I go to the release/bin directory and start the application.  It works when I copy the release/bin directory another machine, but it fails if I deploy it to a machine using Click Once.   Writing to a log file works, so I know that on the Process.Start or the File.Exists(app), which doesn't make sense to me either.


    Robotuner

    Hi Robotuner,

    Have you checked that the settings file can be downloaded after the ClickOnce applications installed?

    On the other hand, it seems that "Process.Start(app, fname);" is not as good as using the StartInfo which shown in my screenshot. Maybe you can have a test!

    I have done the same sample as yours, and it works fine after I publish it in a UNC folder. Here is the creenshot:

     If you have any questions, please feel free to tell us.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Robotuner Wednesday, October 05, 2011 8:40 PM
    Tuesday, October 04, 2011 6:19 AM

All replies

  • Hi Robotuner,

    You can not do something before install the ClickOnce application. But you can use the Setup Project and add the custom action to do it.

    You can do everything in the BeforeInstall event:

    http://msdn.microsoft.com/en-us/library/system.configuration.install.installer.beforeinstall.aspx 

    If you have any questions, please feel free to tell us.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Neddy Ren Monday, October 03, 2011 3:20 AM
    Thursday, September 29, 2011 9:20 AM
  • I'm not sure what the beforeinstall event is suppose to do.  I obviously need to re phrase the question.

     

    I have a button on my application that when clicked opens a text file.  I use the Process.Start() to start an editor with the text file as an argument.

    It works everywhere except when the application has been installed with Click Once.  Is there something in Click once the would prevent me from starting a process like that?


    Robotuner
    Saturday, October 01, 2011 5:59 PM
  • I have a button on my application that when clicked opens a text file.  I use the Process.Start() to start an editor with the text file as an argument.

    It works everywhere except when the application has been installed with Click Once.  Is there something in Click once the would prevent me from starting a process like that?

    Hi, Robotuner

    Could you please help us reproduce it? Or show your code here so that we can demonstrate it!


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 03, 2011 8:08 AM
  • Thats the thing, the code is really simple:

    public static void OpenInEditor(string fname)
            {
                string app =Properties.Settings.Default.editor;
                Util.WriteToLogFile(string.Format("Editor: {0}", app));
                if (!File.Exists(app)) return;
                Process.Start(app, fname);
            }

    fname is checked before passing in to File.Exist(fname);

    Properties.Settings.Default.editor is set to the full path to Notepad++.exe.

    This runs every time when my WPF application is started in debug or release mode on my machine.  It works when I go to the release/bin directory and start the application.  It works when I copy the release/bin directory another machine, but it fails if I deploy it to a machine using Click Once.   Writing to a log file works, so I know that on the Process.Start or the File.Exists(app), which doesn't make sense to me either.


    Robotuner
    Monday, October 03, 2011 7:16 PM
  • Thats the thing, the code is really simple:

    public static void OpenInEditor(string fname)
            {
                string app =Properties.Settings.Default.editor;
                Util.WriteToLogFile(string.Format("Editor: {0}", app));
                if (!File.Exists(app)) return;
                Process.Start(app, fname);
            }

    fname is checked before passing in to File.Exist(fname);

    Properties.Settings.Default.editor is set to the full path to Notepad++.exe.

    This runs every time when my WPF application is started in debug or release mode on my machine.  It works when I go to the release/bin directory and start the application.  It works when I copy the release/bin directory another machine, but it fails if I deploy it to a machine using Click Once.   Writing to a log file works, so I know that on the Process.Start or the File.Exists(app), which doesn't make sense to me either.


    Robotuner

    Hi Robotuner,

    Have you checked that the settings file can be downloaded after the ClickOnce applications installed?

    On the other hand, it seems that "Process.Start(app, fname);" is not as good as using the StartInfo which shown in my screenshot. Maybe you can have a test!

    I have done the same sample as yours, and it works fine after I publish it in a UNC folder. Here is the creenshot:

     If you have any questions, please feel free to tell us.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Robotuner Wednesday, October 05, 2011 8:40 PM
    Tuesday, October 04, 2011 6:19 AM
  • Your test looks identical to mine. with the exception of using StartInfo
    Robotuner
    Wednesday, October 05, 2011 8:40 PM