Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add right-click on a folder as source folder and trigger tool (source included) #102

Open
That-Annoying-Guy opened this issue Jul 5, 2023 · 0 comments

Comments

@That-Annoying-Guy
Copy link

This is what it looks like:
image

It works in Windows 10 22H2 but should work in Windows 11, too.

Save the 2 files below then follow the How to Install section.

Save as IntuneWin File right-click.ps1

<#
.SYNOPSIS
Creates an .IntuneWin File by right-clicking on the source folder.

.DESCRIPTION
This script runs the Microsoft-Win32-Content-Prep-Tool from Windows explorer by right-clicking on the source folder
The source folder name will determine the name of the .IntuneWim file
The .IntuneWim file will be created in the PARENT FOLDER of the Source Folder.

How to Install:
0-Create C:\Program Files\Win32-Content-Prep-Tool\ folder
1-Copy the Microsoft-Win32-Content-Prep-Tool files to C:\Program Files\Win32-Content-Prep-Tool\
2-Copy this PS1 script to the same folder
3-Import "Create .IntuneWin File right-click.Reg" file into the registry

How to use:
1-Create your Intune package as normal
2-When done, Right-Click on the target folder and select: "Create .IntuneWin File with this folder"
3-A GUI will popup for you to select the Install Setup file (e.g. setup.exe or setup.msi or .CMD or .PS1).
4-The .IntuneWim file will be created in the PARENT FOLDER of the selected Source folder

.NOTE
You can copy the files to a different location but you'll need to edit the REG file to match
The Right-Click needs to have a static location for the EXE and PS1 files.

CAVEATS of the IntuneWinAppUtil.exe:
If the output file already exists, it is overwritten. 
If the output folder doesn't exist, it's created automatically.

Licence: MIT (Free for all uses)
#>

[CmdletBinding()]
Param (
    [Parameter(Mandatory = $false)]
    [String]$SourceFolder
)

Try {
	Write-host "`$SourceFolder [$SourceFolder]"
	[string]$DP0=[System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.path)
	[String]$IntuneWinExePath = "$DP0\IntuneWinAppUtil.exe"

	[String]$OutFolder	= [System.IO.Path]::GetDirectoryName($SourceFolder)
	[string]$ScriptNameBase=($MyInvocation.MyCommand.Name).Replace(".ps1","")
	Write-host "`$OutFolder [$OutFolder]"


	#Note: The dialog may appear in the background (behind the PowerShell console).
	[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
	$oOpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
	$oOpenFileDialog.Title = "[$ScriptNameBase] Select Install script or EXE"
	$oOpenFileDialog.InitialDirectory = $SourceFolder
	$oOpenFileDialog.ShowHelp=$true
	If($oOpenFileDialog.ShowDialog() -eq "OK") {
	    $sfile=$oOpenFileDialog.FileName
	    Write-host "You selected [$sfile]"
	    Start-Sleep -Second 6
	    }
	Else {
	    Write-host "You picked nothing"    #user clicked Cancel
	    Start-Sleep -Second 6
		$sfile = "$SourceFolder\DontExist.exe"
	}

	#Write-host "`$sFile [$sfile]"

	#Launch IntuneWinAppUtil.exe in the same folder as this script
	. "$IntuneWinExePath" -c "$SourceFolder" -s "$sfile" -o "$OutFolder"

	Write-host "Complete. Press Enter to close"
	Pause
	
} Catch {
	[String]$ErrorMessage = @{'Message:' = "$($_.Exception.Message)";'ScriptStackTrace:'="$($_.ScriptStackTrace)";'InnerException:'="$($_.Exception.InnerException)"} `
        | Format-Table -AutoSize -Wrap -HideTableHeaders | Out-String
	Write-host $ErrorMessage
	Pause
}

.
Save as IntuneWinAppUtil.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\IntuneWinAppUtil]
@="Create .IntuneWin File with this folder"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\IntuneWinAppUtil\Command]
@="Powershell.exe -file \"C:\\Program Files\\Win32-Content-Prep-Tool\\IntuneWin File right-click.ps1\" %1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant