본문 바로가기

유니티(Unity)

uwp앱에서 exe파일 실행시키기

 

https://learn.microsoft.com/en-us/answers/questions/311271/run-an-exe-batch-file-from-uwp-app

 

Run an exe/batch file from UWP app - Microsoft Q&A

How to run an exe or batch file on a button click from a UWP app?

learn.microsoft.com

위 사이트에 과정이 잘 나와있다.

 

메인페이지cs스크립트에 다음과 같이 버튼이벤트를 작성해준다.

 

private async void Button_Click(object sender, RoutedEventArgs e)
{
	await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
}

아래는 매니페스트 파일이다.

 

<?xml version="1.0" encoding="utf-8"?>

<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  IgnorableNamespaces="uap mp">

  <Identity
    Name="metashopclient"
    Publisher="CN=KIM"
    Version="1.0.0.0" />

  <mp:PhoneIdentity PhoneProductId="3579d931-8e02-4bfa-876f-36d9182880ec" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

  <Properties>
    <DisplayName>MetaShopClient</DisplayName>
    <PublisherDisplayName>KIM</PublisherDisplayName>
    <Logo>Assets\StoreLogo.png</Logo>
  </Properties>

  <Dependencies>
    <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
  </Dependencies>

  <Resources>
    <Resource Language="x-generate"/>
  </Resources>

  <Applications>
    <Application Id="App"
      Executable="$targetnametoken$.exe"
      EntryPoint="MetaShopClient.App">
      <uap:VisualElements
        DisplayName="MetaShopClient"
        Square150x150Logo="Assets\Square150x150Logo.png"
        Square44x44Logo="Assets\Square44x44Logo.png"
        Description="MetaShopClient"
        BackgroundColor="transparent">
        <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
        <uap:SplashScreen Image="Assets\SplashScreen.png" />
      </uap:VisualElements>
      <Extensions>
      	<desktop:Extension Category="windows.fullTrustProcess" Executable="Assets/Test0811/MetaShopClient.exe" />
	<uap:Extension Category="windows.protocol">
    	 <uap:Protocol Name="metashopclientapp">
      	  <uap:Logo>Assets\Logo.png</uap:Logo>
      	  <uap:DisplayName>MetaShopClient</uap:DisplayName>
	 </uap:Protocol>
  	</uap:Extension>
       </Extensions>
    </Application>
  </Applications>

  <Capabilities>
    <Capability Name="internetClient" />
    <rescap:Capability Name="runFullTrust"/>
  </Capabilities>
</Package>

처음에 올린 웹사이트에 올라온 내용과 위의 내용을 참고하여 uwp앱에서 exe파일을 실행할 수 있다.

 

※ exe파일 및 데이터 파일들은 uwp에셋 폴더에 들어가 있는 상태이다. 만약 data폴더를 찾을 수 없다는 에러가 나오면

bin\x86\Release\AppX\Assets\ 와 같은 경로에 직접 파일들을 넣어주면 해결된다.

경로는 자신의 상황에 맞게 <Extensions> 부분의 Executable에 작성해주면된다.