List and run windows 8.1 metro apps

Published on by Yousfi Benameur

Preambule

All the applications that are installed through the Store are physically stored in the folder %ProgramFiles%\WindowsApps, which usually is C:\Program Files\WindowsApps.

In this folder stay all the files that are needed for the application to run, and, by default, this folder has the permissions set in a way that prevents the normal user to access its content
The data files for each application are stored in the folder %USERPROFILE%\AppData\Local\Packages\

The Store application is not stored in the same folder as all the other Windows Store applications, and is located at %windir%\WinStore, which usually is C:\Windows\WinStore,

 

*I searched but Windows dont give any way to list all metro apps installed on system.that why the parsing solution is more indicated.(thanks to Rahul moudgill to raise  the parsing solution in foxite forum).

 

 

*This code searches for all windows metro apps in the system folder<program files\WINDOWSAPPS>
*it can run each application by a simple click (if allowed otherwise raise a windows message)
*the files embedding metro app are xml extensions.when browsing the cursor and editing one can see the  windows metro app between two strings delimiters then can parse and extract the real name.
*this is what this code does.
*can run these applications with shell.run method or windows explorer as any other windows app.
*some Microsoft  metro apps recquire a account to access to it.must registered (follow the MS registration form).

*you can make with this prg a small proj+config.fpw  and compile to an exe as utility for this tasks.
*all these apps are in registry in this key (security protected,not openable).in my Win8.1:
* HKEY_CURRENT_USER\Software\Classes\Extensions\ContractId\Windows.Protocol\PackageId

*these can also located in the folders of "c:\program files\windowsapp\"

with this syntax getdir() can explore the folder "c:\program files\windowsapps" and all its subfolders+files  without any permission !( its a problem with microsoft ?).

*begin code
Publi yform
yform=Newobject("ymetro_launcher")
yform.Show
Read Events
Retu
*
Define Class ymetro_launcher As Form
    BorderStyle = 2
    Height = 310
    Width = 500
    ShowWindow = 2
    BackColor=0
    AutoCenter = .T.
    Caption = "Windows  Metro Apps"
    MaxButton = .F.
    Name = "Form1"

    Add Object ylabel1 As Label  With ;
        AutoSize = .T.,;
        FontBold = .T.,;
        FontSize = 28,;
        BackStyle = 0,;
        Caption = "List & Run Window Apps",;
        Height = 47,;
        Left = 10,;
        Top = -6,;
        Width = 445,;
        ForeColor = Rgb(255,128,0),;
        Name = "yLabel1"


    Add Object ylabel2 As Label  With ;
        AutoSize = .T.,;
        FontBold = .T.,;
        FontSize = 28,;
        BackStyle = 0,;
        Caption = "List & Run Window Apps",;
        Height = 47,;
        Left = 15,;
        Top = -4,;
        Width = 445,;
        ForeColor = Rgb(255,255,0),;
        Name = "yLabel2"


    Add Object grid1 As Grid With ;
        Height = 324, ;
        Left = 1, ;
        MousePointer = 15, ;
        Top = 48 , ;
        Width = 500, ;
        Name = "Grid1"

    Procedure recursefolder
        Lparameters lcDir
        Local i,N, laFiles[1],yname
        m.nrep=m.nrep+1
        N = Adir( laFiles, lcDir + "*.*", "shd" )
        For i = 1 To N
            If ( Left( laFiles[i,1], 1 ) != '.' )
                If ( "D" $ laFiles[i,5] )
                    Thisform.recursefolder( lcDir + laFiles[i,1] + "\" )
                Else
                    *parsing and making some adjustments
                    If  Lower(Justext(laFiles[i,1])) $ "xml"     && files to search here
                        m.yname=Strextract( Filetostr(lcDir + laFiles[i,1]),'<Identity Name="','"',1)
                        m.yname=Substr(m.yname,11)
                        m.yname=Strtran(m.yname,"Zune","microsoft",1,1,3)
                        m.yname=Strtran(m.yname,"XBOXLIVE","xbox",1,1,3)

                        Insert Into tempfiles Values( lcDir + laFiles[i,1],m.yname )
                    Endi
                Endif
            Endif
        Endfor
    Endproc

    Procedure my
        Lparameters nButton, nShift, nXCoord, nYCoord
        Local loshell,cmdline
        Sele zcurs
        If Messagebox("RUN this app:"+Allt(winappname)+"://"+" (if allowed) ?",4+64+4096)=6
            loshell=Newobject("wscript.shell")
            Try
                loshell.Run(Allt(winappname)+"://")
            Catch
                Messagebox("An error was occured !",16+4096)
            Endtry
            *=Execscript("run/n explorer "+Allt(winappname)+"://")  &&can also use this syntax to run metro apps
        Endi
    Endproc

    Procedure Destroy
        Close Data All
        Dele File (Addbs(Sys(2023))+"asup.dbf")
        Clea Events
    Endproc

    Procedure Init
        Close Data All
        Set Safe Off
        Publi m.nrep,m.ltstart
        m.nrep=0
        m.ltstart = Datetime()

        Local m.myvar
        *the windows metro app are located in c:\program files\windosapps
        *if you issued getdir() you dont see this folder (hidden for windows permissions security reasons)
        *if you issued getdir("c:\","","",16384)  you can overjump this problem.
        Local m.yrep
        m.yrep=  "C:\PROGRAM FILES\WINDOWSAPPS\"    &&getdir("c:\","","",16384)
        If Empty(m.yrep)
            Return
        Endi
        Create Cursor tempfiles ( cFilename c(150), winappname c(50) )  
        Thisform.recursefolder( m.yrep)
        Local nr
        nr=Reccount()
        Copy Fields winappname For !Empty(winappname) To (Addbs(Sys(2023))+"asup.dbf")
        Sele * Distinct From (Addbs(Sys(2023))+"asup.dbf") Into Cursor zcurs Readwrite

       *not detected by the parsing code ..simply added

       Insert Into zcurs Values("wlcalendar" )
        Insert Into zcurs Values("mschat" )
        Insert Into zcurs Values("wlpeople" )
        Insert Into zcurs Values("bingsearch" )
        Insert Into zcurs Values("netfix")
        Insert Into zcurs Values("mailto")
        Insert Into zcurs Values("onenote")
        Insert Into zcurs Values("ms-windows-store")

        Sele zcurs

        Locate
        With Thisform.grid1
            .Themes=.F.
            .Anchor=15
            .HeaderHeight=22
            .RecordSource="zcurs"
            .RecordSourceType=1
            .GridLines=0
            .DeleteMark=.F.
            .RecordMark=.F.
            .ReadOnly=.T.
            .FontBold=.T.
            .FontSize=14
            .column1.Width=500
            .SetAll("backcolor",0,"header")
            .SetAll("forecolor",255,"header")
            .SetAll("DynamicBackColor", "IIF(MOD(RECNO( ), 2)=0, RGB(255,255,255)  , RGB(220,255,200))", "Column")
            .column1.DynamicForeColor="rgb(255,0,0)"
            .Refresh
        Endwith

       Bindevent[thisform.grid1.column1.text1,;
"mousedown",Thisform,"my"] && typo editor here
        Thisform.Caption=Trans(Reccount())+" "+Thisform.Caption

    Endproc
Enddefine
*

*End code

 

 

*this is a more simple method to return the windows app stored on "c:\program files\windowsapps" folder
*when opening this folder with getdir(,16384)  can see a general rule to name these applications for ex:
*MICROSOFT.BINGFINANCE_2014.425.1751.3374_NEUTRAL_~_8WEKYB3D8BBWE
*the metro app name is between ("Microsoft."                                  and "_")-then can extract this name easily

*after this can tweak the records as above

 

 

*begin code
Close Data All
Local m.yrep,gnbre
m.yrep=Addbs("c:\program files\windowsapps")
gnbre=Adir(gabase,m.yrep+"*.*","D")
  &&directories only

Create Cursor ycurs (Winappname c(100))
For i=1 To gnbre
    If     Lower( "Microsoft.")   $   Lower( gabase(i,1) )
        Insert Into ycurs Values (gabase(i,1))
    Endi
Endfor

*Brow

Sele ycurs
Repl All Winappname With Strextract(Winappname,"MICROSOFT.","_",1,3)
Sele * Distinct From ycurs Into Cursor zcurs readwrite
 Insert Into zcurs Values("wlcalendar" )
        Insert Into zcurs Values("mschat" )
        Insert Into zcurs Values("wlpeople" )
        Insert Into zcurs Values("bingsearch" )
        Insert Into zcurs Values("netfix")
        Insert Into zcurs Values("mailto")
        Insert Into zcurs Values("onenote")
        Insert Into zcurs Values("ms-windows-store")
Sele zcurs

Brow

Close Data All
Retu

*endcode

 

if the application is not allowed to run windows raises a message as the 8th photo.
if the application is not allowed to run windows raises a message as the 8th photo.
if the application is not allowed to run windows raises a message as the 8th photo.
if the application is not allowed to run windows raises a message as the 8th photo.
if the application is not allowed to run windows raises a message as the 8th photo.
if the application is not allowed to run windows raises a message as the 8th photo.
if the application is not allowed to run windows raises a message as the 8th photo.
if the application is not allowed to run windows raises a message as the 8th photo.

if the application is not allowed to run windows raises a message as the 8th photo.

Published on Vsual foxpro, metro apps

To be informed of the latest articles, subscribe:
Comment on this post