locked
Small, newbie question about Developing Windows Store app with Javascript RRS feed

  • Question

  • Hi guys, I have some questions on developing Windows Store Apps. I'm a newbie in this, but I'm studying Java in my college. So I'm not that blank in programming. Lets call my developing program as xApp and here are my questions:

    1. How do I make a function which will launch an app from specific directory? Let say that I have a program "C:\Program Files\ProgramDir\Program.exe", I want to launch the "Program.exe", but the source code I downloaded didn't allow me to. I got an error message, in which I believe that it is because the syntax I use only read xApp subdir.
    Here's the code I use:

    var fileToLaunch = "images\\splashscreen.png";

        function launchFile() {
    image directory.
            Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(fileToLaunch).done(
                function (file) {   
                 Windows.System.Launcher.launchFileAsync(file).done(
                        function (success) {
                            if (success) {
                            } else {
                            }
                        });
                });
        }

    When I change the fileToLaunch into "C:\\Program Files\\ProgramDir\\Program.exe", it doesn't work. I got an error message.

    2.How to modify my xApp so it will have a progress like "Launch xApp->Launch Program.exe->Close xApp". And it's all automated. The xApp will close by the time the Program.exe ends, or if it possible, could I make it that the xApp closes after it launch the Program.exe? If it is in VB6, the code would be:

    .....//xApp launched
    Shell "C:\Program Files\ProgramDir\Program.exe" 'Launch Program.exe and doesn't wait for the program to finish
    Unload Me 'Close xApp as soon as the code above executed
    3. How to build/compile/create installer file for my xApp? Because I want to use it for my personal use, since it only has the function to launch another app (much like a shortcut). I don't want to pin my program's exe into start menu, because it is not as beautiful as tile. My tile is wide, not the square.

    Thanks in advance and sorry for my English :)
    Tuesday, January 8, 2013 11:24 PM

Answers

  • A-SM - Normal desktop application exe files are handled to launch by Windows.  Windows 8 Applications (both HTML/JS, XAML/C#/C++) are not the same as desktop .exe applications (even if C#/C++ end with a '.exe' extension).  They run in a very sandboxed environment and the Windows Runtime tightly controls what they are permitted to do.  One of the things that is blocked is launching random .exe files located on the file system.  You can only use the Launcher API to open files and have the default application registered, if any, handle them.  Your application cannot specify which application opens a particular file, only the user can (via their default settings or in the choose program dialog if no default is currently set). 

    Likewise, you also cannot access arbritrary locations on the file system, like "C:\Program Files\..." - you can only access permitted locations within the sandbox such as your applications AppData folder (local & roaming), your app's temp folder, you app's install folder, etc. as well as locations that you were granted permission to via a capability in your manifest (Pictures Library, Documents Library, Music Library, etc.).  All other locations are not accessible by a Windows 8 Application.

    Ealsur - you are mostly correct, but I just wanted to clarify that the restriction isn't limited to HTML/JS - no Windows 8 Application can directly launch another .exe.  A desktop application can behave like it always had and has much broader access to the file system than a modern Windows 8 app does, regardless of the language it is written with.  Also, registering a file extension isn't limited to store apps; non-store apps can register a file extension on the machine that the launcher API will use, like Microsoft Word does.



    Thursday, January 10, 2013 6:57 AM

All replies

  • You cannot launch another program directly from a Windows 8 application.  The only way to get close to what you'd like to do would be to open a file that is registered for a specific program to have the default application launch to open it (e.g. a *.docx file to launch Microsoft Word).  You can use the Launcher API to do this like you are above.

    Wednesday, January 9, 2013 3:59 AM
  • Hm, I don't really understand what you're saying but isn't .exe already registered to be opened by Windows default application launcher (I forget the name)? Or should I create my own installer, like creating a new folder in my xApp subdir and then copy all the files needed (let say CCleaner). Is it possible?
    Wednesday, January 9, 2013 4:48 AM
  • The thing is, Windows 8 Apps in HTML/CSS do not run like a Windows 8 App in C#/XAML (.exe), they run within a context host called "wwahost" (if I remember correctly) which then uses an HTML renderer (the same as IE10) + WinJS (making WinRT available).

    Within that context you can access your App folders (local / roaming / temp) but you can't access a path in c:\program files\ or execute an exe.

    What Gearard suggested is that, one way for two Apps to communicate (both have to be Store Apps, not Exes laying around on the Hard drive) is for one App to register a file association (something like Word registering DOC extension so that any DOC is opened by Word), it's not really a file association but an URI scheme association (declared on the Manifest). It says something like, any URI of this format will be handled by me, so a second App, knowing that scheme, can use it to communicate with the first App.

    URI Schemes (Windows)

    Launching Apps from URI Scheme

    MSDN Association launcher sample

    Wednesday, January 9, 2013 7:28 PM
  • A-SM - Normal desktop application exe files are handled to launch by Windows.  Windows 8 Applications (both HTML/JS, XAML/C#/C++) are not the same as desktop .exe applications (even if C#/C++ end with a '.exe' extension).  They run in a very sandboxed environment and the Windows Runtime tightly controls what they are permitted to do.  One of the things that is blocked is launching random .exe files located on the file system.  You can only use the Launcher API to open files and have the default application registered, if any, handle them.  Your application cannot specify which application opens a particular file, only the user can (via their default settings or in the choose program dialog if no default is currently set). 

    Likewise, you also cannot access arbritrary locations on the file system, like "C:\Program Files\..." - you can only access permitted locations within the sandbox such as your applications AppData folder (local & roaming), your app's temp folder, you app's install folder, etc. as well as locations that you were granted permission to via a capability in your manifest (Pictures Library, Documents Library, Music Library, etc.).  All other locations are not accessible by a Windows 8 Application.

    Ealsur - you are mostly correct, but I just wanted to clarify that the restriction isn't limited to HTML/JS - no Windows 8 Application can directly launch another .exe.  A desktop application can behave like it always had and has much broader access to the file system than a modern Windows 8 app does, regardless of the language it is written with.  Also, registering a file extension isn't limited to store apps; non-store apps can register a file extension on the machine that the launcher API will use, like Microsoft Word does.



    Thursday, January 10, 2013 6:57 AM
  • Thanks for clarifying Gearard, I thought the restriction applied to Store Apps only. Everyday we learn something new :)
    Thursday, January 10, 2013 12:32 PM