' NAME: GetLongName.vbs ' ' AUTHOR: alan dot Kaplan at VA dot Gov ' DATE : 4/24/2014 ' ' COMMENT: Gets the Long File Name from a Short File Name on local or remote computer. ' '========================================================================== Option Explicit dim wshShell:Set wshShell = WScript.CreateObject("WScript.Shell") Dim strLongUNC, strLong, strShortName dim strComputer: strComputer = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%") strComputer = InputBox("Get Long File name from short name on which PC","Computer Name",strComputer) If strcomputer = "" Then WScript.Quit strComputer = UCase(strComputer) strShortName = InputBox("Enter the short pathname","Short File Name") If strShortName = "" Then WScript.Quit 'Create UNC path and get Long Name strLongUNC = GetLongPath ("\\" & strComputer & "\" & replace(strShortName,":","$")) 'Back to non-UNC Path Dim iStart:iStart = Len(strComputer)+4 strLong = Replace( Mid(strLongUNC,iStart),"$",":" ) Dim Message, retVal message = strShortName & " on " & strComputer & " is" & VbCrLf & strLong & VbCrLf & _ "Send name to clipboard? (This uses IE object, permit on prompt)" retVal = MsgBox (Message,vbInformation + vbYesNo,"Long Name") If retVal = vbYes Then Dim objIE Set objIE = CreateObject("InternetExplorer.Application") objIE.Navigate("about:blank") objIE.document.parentwindow.clipboardData.SetData "text", strLong objIE.Quit wshShell.Popup "Done",3,"Info copied" End If '=============================== Function GetLongPath(strShortPath) dim quote:quote=chr(34) strShortPath = Replace(strShortPath,quote,"") 'based on code originally found at http://www.myitforum.com/forums/m_168099/mpage_1/key_/tm.htm#168187 On Error Resume Next dim oSC, sLongName ' No link will be created Set oSC = wshShell.CreateShortcut("foo.lnk") oSC.TargetPath = strShortPath sLongName = oSC.TargetPath GetLongPath = sLongName If Err.Number > 0 Then Err.Clear GetLongPath = strShortPath 'could not resolve End If End Function Function IsCScript() If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then IsCScript = True Else IsCScript = False End If End Function