Login / Register
▼
Binary Fortress
Binary Fortress Software
CheckCentral
ClipboardFusion
CloudShow
DisplayFusion
FileSeek
HashTools
LogFusion
Notepad Replacer
Online Base64 Decoder
Online Base64 Encoder
Online JSON Formatter
ShellSend
TrayStatus
VoiceBot
WallpaperFusion
Window Inspector
More Apps...
DisplayFusion
CheckCentral
CloudShow
ClipboardFusion
FileSeek
VoiceBot
WallpaperFusion
Home
▼
Download
Download
Change Log
Download Beta
Beta Change Log
License (EULA)
▼
Features
Features
Incredible Desktop Wallpaper
Monitor Configuration
Monitor Splitting
Powerful Functions
Triggers
Multi-Monitor Taskbars
Useful Windows 10 Tweaks
Useful Windows 8 Tweaks
Windows Lock Screen
Multi-Monitor Screen Savers
Monitor Fading
Window Snapping
Window Management
Mouse Management
Alt+Tab Handler
Window Position Profiles
Desktop Icon Profiles
Remote Control
Available in dozens of Languages
Easy Administration
Free vs Pro
Purchase
Screenshots
Languages
▼
Help
Help Guide
FAQ
Discussions
Contact Us
Find My License
Mailing Address
Advanced Settings
Scripted Functions (Macros)
Display
Fusion
WARNING: You currently have Javascript disabled!
This website will not function correctly without Javascript enabled.
Title
Message
OK
Confirm
Yes
No
Selected File to UNC Path
Return to DisplayFusion Scripted Functions (Macros)
Description
Select a file and get the full UNC path for it.
Language
C# (.Net)
Minimum Version
9.1+
Created By
Thomas Malloch (BFS)
Contributors
Manuel R.
Date Created
Feb 23, 2018
Date Last Modified
9d ago
Scripted Function (Macro) Code
Copy
Select All
Toggle Line Wrapping
using System; using System.Drawing; using System.Windows.Forms; using System.Text; using System.Runtime.InteropServices; using System.Collections.Specialized; using System.IO; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Diagnostics; // The 'windowHandle' parameter will contain the window handle for the: // - Active window when run by hotkey // - Trigger target when run by a Trigger rule // - TitleBar Button owner when run by a TitleBar Button // - Jump List owner when run from a Taskbar Jump List // - Currently focused window if none of these match public static class DisplayFusionFunction { [DllImport("mpr.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern int WNetGetConnection([MarshalAs(UnmanagedType.LPTStr)] string localName, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder remoteName, ref int length); [DllImport("user32.dll")] private static extern int GetWindowText(int hWnd, StringBuilder text, int count); [DllImport("user32.dll")] private static extern int GetWindowTextLength(IntPtr hWnd); [DllImport("user32.dll", PreserveSig = true, SetLastError = false, CharSet = CharSet.Unicode)] private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, IntPtr lpszWindow); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam); const int WM_GETTEXT = 13; public static void Run(IntPtr windowHandle) { //save clipboard to restore later string oldClip = BFS.Clipboard.GetText(); //copy the selected file to the clipboard BFS.Clipboard.Copy(); List<string> files = new List<string>(); foreach (string file in Clipboard.GetFileDropList()) { files.Add(file); } string originalPath; if (files == null || files.Count == 0) { // Retrieve handle of the Address bar according to class hierarchy IntPtr controlHandle; controlHandle = FindWindowEx(windowHandle, IntPtr.Zero, "WorkerW", IntPtr.Zero); controlHandle = FindWindowEx(controlHandle, IntPtr.Zero, "ReBarWindow32", IntPtr.Zero); controlHandle = FindWindowEx(controlHandle, IntPtr.Zero, "Address Band Root", IntPtr.Zero); controlHandle = FindWindowEx(controlHandle, IntPtr.Zero, "msctls_progress32", IntPtr.Zero); controlHandle = FindWindowEx(controlHandle, IntPtr.Zero, "Breadcrumb Parent", IntPtr.Zero); controlHandle = FindWindowEx(controlHandle, IntPtr.Zero, "ToolbarWindow32", IntPtr.Zero); StringBuilder builder = new StringBuilder(500); SendMessage(controlHandle, WM_GETTEXT, builder.Capacity, builder); originalPath = builder.ToString().Remove(0, builder.ToString().IndexOf(' ') + 1); //BFS.Dialog.ShowTrayMessage("DIR originalPath=" + originalPath); } else { BFS.Clipboard.SetText(oldClip); string uncPath; string pathToClipboard = String.Empty; foreach (var item in files) { originalPath = item; if (!Regex.IsMatch(originalPath, "^[a-zA-Z]:")) { uncPath = originalPath; } else { //set up variables for the WNetGetConnection function StringBuilder sb = new StringBuilder(512); int size = sb.Capacity; //try and get the full path with the WNetGetConnection. if it fails, return what was on the clipboard int hr = WNetGetConnection(originalPath.Substring(0, 2), sb, ref size); if (hr != 0) { uncPath = originalPath; } else { //build full path DirectoryInfo dir = new DirectoryInfo(originalPath); string path = Path.GetFullPath(originalPath).Substring(Path.GetPathRoot(originalPath).Length); //set the clipboard with the full path uncPath = Path.Combine(sb.ToString().TrimEnd(), path); } } bool ok = BFS.ScriptSettings.WriteValue("UNCPATH", uncPath); //BFS.Dialog.ShowTrayMessage("WRITE" + uncPath); ok = BFS.ScriptSettings.WriteValueBool("FLAG_UNCPATH_UPDATED", true); pathToClipboard += uncPath + Environment.NewLine; } Clipboard.SetText(pathToClipboard.Trim()); } } }
Copyright © 2007-2021 Binary Fortress Software
•
News
•
Discussions
•
FAQ
•
Support
•
Privacy
•
ToS
•
Get DisplayFusion Merch