开发Outlook Web Add-In:如何用JS/jQuery获取系统.exe/.pkg路径?
Hey there! Let's break down how to tackle this problem—first, a critical note: Outlook Web Add-ins run in a sandboxed environment (whether in a browser or the desktop client's webview), so you can't directly access the local filesystem or system-level installed app lists. That said, there are workarounds depending on your target environment:
1. For Outlook Desktop Client (Windows/macOS)
If your add-in is primarily used in the desktop version of Outlook, you can pair your web add-in with a lightweight local proxy app to bridge the gap between the sandboxed web environment and the local system.
Windows: Fetching .exe Paths
- First, build a simple Windows desktop app (using C#/.NET Core, for example) that can query installed .exe paths. You can pull this info from the Windows Registry: check
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\UninstallorHKEY_CURRENT_USERfor entries that include the installed executable's path. - Next, have this local app spin up a localhost HTTP server (e.g., listening on
http://localhost:3000) that exposes an endpoint to return the list of .exe paths. - In your add-in's button click handler, use
fetchto call this local endpoint:document.getElementById('getExesBtn').addEventListener('click', async () => { try { const res = await fetch('http://localhost:3000/get-installed-exes'); const exePaths = await res.json(); console.log('Installed EXE paths:', exePaths); // Do something with the paths here } catch (err) { console.error('Failed to fetch EXE paths:', err); // Prompt the user to launch the local proxy app if needed } });
macOS: Fetching .pkg Paths
- Build a lightweight macOS app (Swift or Objective-C works well) that retrieves installed .pkg info. You can either:
- Check the
/Library/Receipts/directory for .plist files that track package installations, or - Run the
pkgutilcommand line tool (e.g.,pkgutil --pkgsto list packages, thenpkgutil --pkg-info <package-id>to get the installation path)
- Check the
- Have this app run a localhost HTTP server (e.g.,
http://localhost:3001) with an endpoint to return .pkg paths. - Your add-in's button logic will look similar to the Windows version:
document.getElementById('getPkgsBtn').addEventListener('click', async () => { try { const res = await fetch('http://localhost:3001/get-installed-pkgs'); const pkgPaths = await res.json(); console.log('Installed PKG paths:', pkgPaths); } catch (err) { console.error('Failed to fetch PKG paths:', err); } });
2. For Outlook Web (Browser-Only)
If your add-in needs to work in the pure browser version of Outlook, there’s no way to directly get local installed app paths—browser sandbox rules block this entirely. Your only option is to let users manually select the file via a file input, though note that browsers won’t expose the full local path (only the filename):
<!-- Hidden file input --> <input type="file" id="exeFilePicker" accept=".exe" style="display: none;"> <button id="selectExeBtn">Select Installed EXE</button> <script> document.getElementById('selectExeBtn').addEventListener('click', () => { document.getElementById('exeFilePicker').click(); }); document.getElementById('exeFilePicker').addEventListener('change', (e) => { const selectedFile = e.target.files[0]; // You can only get the filename, not the full local path console.log('Selected file:', selectedFile.name); // If needed, you can upload the file to your server, but can't access the local install path }); </script>
Key Considerations
- Security: Make sure your local proxy app only listens on
localhostto avoid external access, and request the minimum necessary system permissions (e.g., registry access on Windows, filesystem access on macOS). - User Guidance: Clearly inform users that they need to launch the local proxy app first to use this feature—otherwise, the add-in’s requests will fail.
内容的提问来源于stack exchange,提问作者Neha Soni

