|
| 1 | +<# |
| 2 | + Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + or more contributor license agreements. See the NOTICE file |
| 4 | + distributed with this work for additional information |
| 5 | + regarding copyright ownership. The ASF licenses this file |
| 6 | + to you under the Apache License, Version 2.0 (the |
| 7 | + "License"); you may not use this file except in compliance |
| 8 | + with the License. You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, |
| 13 | + software distributed under the License is distributed on an |
| 14 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + KIND, either express or implied. See the License for the |
| 16 | + specific language governing permissions and limitations |
| 17 | + under the License. |
| 18 | +#> |
| 19 | + |
| 20 | +param( |
| 21 | + [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] |
| 22 | + [string] $ID <# package.appxmanifest//Identity@name #> |
| 23 | +) |
| 24 | + |
| 25 | +$code = @" |
| 26 | +using System; |
| 27 | +using System.Runtime.InteropServices; |
| 28 | +namespace PackageDebug |
| 29 | +{ |
| 30 | + public enum PACKAGE_EXECUTION_STATE |
| 31 | + { |
| 32 | + PES_UNKNOWN, |
| 33 | + PES_RUNNING, |
| 34 | + PES_SUSPENDING, |
| 35 | + PES_SUSPENDED, |
| 36 | + PES_TERMINATED |
| 37 | + } |
| 38 | +
|
| 39 | + [ComImport, Guid("B1AEC16F-2383-4852-B0E9-8F0B1DC66B4D")] |
| 40 | + public class PackageDebugSettings |
| 41 | + { |
| 42 | + } |
| 43 | +
|
| 44 | + [ComImport, Guid("F27C3930-8029-4AD1-94E3-3DBA417810C1"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] |
| 45 | + public interface IPackageDebugSettings |
| 46 | + { |
| 47 | + int EnableDebugging([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, [MarshalAs(UnmanagedType.LPWStr)] string debuggerCommandLine, IntPtr environment); |
| 48 | + int DisableDebugging([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); |
| 49 | + int Suspend([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); |
| 50 | + int Resume([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); |
| 51 | + int TerminateAllProcesses([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); |
| 52 | + int SetTargetSessionId(int sessionId); |
| 53 | + int EnumerageBackgroundTasks([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, |
| 54 | + out uint taskCount, out int intPtr, [Out] string[] array); |
| 55 | + int ActivateBackgroundTask(IntPtr something); |
| 56 | + int StartServicing([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); |
| 57 | + int StopServicing([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); |
| 58 | + int StartSessionRedirection([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, uint sessionId); |
| 59 | + int StopSessionRedirection([MarshalAs(UnmanagedType.LPWStr)] string packageFullName); |
| 60 | + int GetPackageExecutionState([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, |
| 61 | + out PACKAGE_EXECUTION_STATE packageExecutionState); |
| 62 | + int RegisterForPackageStateChanges([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, |
| 63 | + IntPtr pPackageExecutionStateChangeNotification, out uint pdwCookie); |
| 64 | + int UnregisterForPackageStateChanges(uint dwCookie); |
| 65 | + } |
| 66 | +
|
| 67 | + public class DebugTool |
| 68 | + { |
| 69 | + public static void EnableDebug(String packageFullName) |
| 70 | + { |
| 71 | + // Set debug mode for App and activate installed application |
| 72 | + var debugSettings = (IPackageDebugSettings)(new PackageDebugSettings()); |
| 73 | + debugSettings.EnableDebugging(packageFullName, null, (IntPtr)null); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | +"@ |
| 78 | + |
| 79 | +Add-Type -TypeDefinition $code |
| 80 | + |
| 81 | +$packageFullName = $(Get-AppxPackage $ID).PackageFullName |
| 82 | +Write-Host "Setting debug mode for application:" $ID |
| 83 | +[PackageDebug.DebugTool]::EnableDebug($packageFullName) | Out-Null |
0 commit comments