0

I need to open files of different types with their associated application. It works fine like this:

System.Diagnostics.Process.Start(@"C:\foo.jpg");

But when I need to open it with a specific user, I need to supply an executable, I can't open a document/image etc. ("The specified executable is not a valid application for this OS platform") Is there a smart workaround or would I need to get the associated application's data from registry and run the application with the document/image as argument? (So the question is not about how to run Process.Start() with arguments!)

IngoB
  • 2,552
  • 1
  • 20
  • 35
  • See https://stackoverflow.com/a/12903698/68432 - Can't you just pass your executable and so on to `runas`? – Paul Suart Mar 14 '18 at 13:11
  • Possible duplicate of [c# open file with default application and parameters](https://stackoverflow.com/questions/11365984/c-sharp-open-file-with-default-application-and-parameters) – Enfyve Mar 14 '18 at 13:11
  • The point is I don't want to search the registry for each file type's application and run this with the file as argument. Isn't there a way to just open the file with Process.Start(@"C:\foo.jpg")) and still use Domain/UserName/Password? – IngoB Mar 14 '18 at 13:15
  • @Paul Suart: Same problem with "runas". – IngoB Mar 14 '18 at 13:27
  • I understand the question but not what you are trying to achieve (sometimes we can think of a better way if we know the end goal). Why do you want to open a file in the current session, as another user, using that other user's choice of executable? (or do you in fact want the file to open in YOUR registered app, but using someone else's credentials?) – Stephen Kennedy Mar 14 '18 at 13:57
  • If you do think about delving into the registry, it is better to use Win API https://stackoverflow.com/a/17773402/397817 – Stephen Kennedy Mar 14 '18 at 14:02
  • @Stephen Kennedy: My application saves files on a network share where every user can just access them. The idea was to set file security on the files for a special "app user" so that only the app user (= the app) can open the files again, but no other/normal user. That's why I started using ProcessStartInfo with Domain/Username/Password. – IngoB Mar 14 '18 at 14:43
  • 1
    Perhaps you could launch `cmd.exe` under a specific user with the `/c start document` command line and have it launch the file - this will use the app user's association, of course. – NetMage Mar 15 '18 at 00:32
  • @NetMage: Good idea, thanks! But I don't get cmd.exe launched under another user, even after setting explicit read+execute permissions on it ("The directory name is invalid"). – IngoB Mar 15 '18 at 11:22
  • I had no problem making it work after I opened a cmd.exe console under the user and setup the document association - my user had no default association for `txt`. – NetMage Mar 15 '18 at 18:29

0 Answers0