TC-Command: How to Pass file name as \\UNC\path ?

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
eee
Junior Member
Junior Member
Posts: 4
Joined: 2016-02-29, 08:38 UTC

TC-Command: How to Pass file name as \\UNC\path ?

Post by *eee »

Dialog box: Configuration - Change button bar...
One can pass the file name as a parameter using %P%N.
How can this be formatted as the UNC path to the file?
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

VBScript: _ForEachSelFileDo - UtilizeUNCname.vbs

Post by *Stefan2 »

Hi and welcome, eee.

There is only "copy with UNC to clipboard" command: cm_CopyNetNamesToClip


For to utilize such UNC name in user command as in a button,
we have to utilize a script to lookup driveletter to UNC "\\server\share" syntax.

Something like that VBScript > http://ghisler.ch/board/viewtopic.php?t=43587


Here adjusted for your issue.

'// Example: If "\\server.name.tld\share_SW" is mapped as drive W:
'// cm_CopyFullNamesToClip: W:\TOOLs\Notepad2\Notepad2.exe
'// cm_CopyNetNamesToClip: \\server.name.tld\share_SW\TOOLs\Notepad2\Notepad2.exe
'// Script result: \\server.name.tld\share_SW\TOOLs\Notepad2\Notepad2.exe



Add this script to your button instead of your tool
'// TC Button:
'// CMD: "D:\rive\path\to\this\script.vbs"
'// PARAM: "%L"



And change the "Users Work" section to your needs at:

USERs' WORK HERE
sUNCName = replace(sFullName,sDriveLetter,sShareName) & vbCRLF
>>> insert here your tool, e.g. with --WSO.run ".....",1,true--
If you need help with change the call to your tool from button to WSO.run, just ask with examples.



_ForEachSelFileDo - UtilizeUNCname.vbs

Code: Select all


'// =========================================================== Script Purpose
'// VBScript for Total Commander, by Stefan
'// _ForEachSelFileDo - UtilizeUNCname.vbs, v00.1, 2016-02-29
'// Forum: http://ghisler.ch/board/viewtopic.php?p=305593#305593 (Pass file name as UNC)
'// Purpose: Change each selected name to UNC name, change "Drive letter:\" to "\\Server\share\"
'//     Example: 
'//     Example: If "\\server.name.tld\share_SW" is mapped as drive W:
'//         cm_CopyFullNamesToClip:  W:\TOOLs\Notepad2\Notepad2.exe
'//         cm_CopyNetNamesToClip:   \\server.name.tld\share_SW\TOOLs\Notepad2\Notepad2.exe
'//         Script result:           \\server.name.tld\share_SW\TOOLs\Notepad2\Notepad2.exe
'//
'// USAGE: Change code on "USERs' WORK HERE" section below, save the script,
'//        create button, select your files, execute this script... done.
'//
'// NOTE: lines with leading '-sign or '//-signs are comments.
'//
'// =========================================================== Call from Button or userCmd.ini
'// TC Button:
'//         CMD:   "D:\rive\path\to\this\script.vbs"
'//        (portable use, CMD:   "%Commander_Path%\MyTools\script.vbs")
'//         PARAM: "%L"
'//        (open button dialog and press F1-key on keyboard for more help)
'//
'// =========================================================== Script Basics
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSO = CreateObject("WScript.Shell")
Set NET = CreateObject("WScript.Network")
'// =========================================================== Read TCs temp list:
If(Wscript.arguments.Count >= 0) Then
    sTCtempList = Wscript.arguments.Item(0) ' The TC temp file due the "%L"
Else
    MsgBox "Missing parameter. Read this script source code for help.",,"TC-Script - ERROR"
    WScript.Quit
End If
If  FSO.FileExists(sTCtempList) Then
    Set oTextStream = FSO.OpenTextFile(sTCtempList,1) 'FORREADING = 1
    sFileContent = oTextStream.ReadAll
    oTextStream.Close
    aLineArray = split(sFileContent,vbCRLF)
'// =========================================================== Do basic things one time only:
    sFirstLine = aLineArray(0)
    If(InStr(sFirstLine,":")) Then sDriveLetter = Left(sFirstLine,2)
    sShareName  = GetUNCName(sDriveLetter)
    'sServerName = Split(sShareName, "\")(2) 
    'sIPAddress  = GetServerIP(sServerName)
    'sShareWithIP = replace(sShareName, sServerName, sIPAddress)
'// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
    '// =========================================================== vvv USERs' WORK HERE vvv
    REM      __  __                           _       __              __   
    REM     / / / /_____ ___   _____ _____   | |     / /____   _____ / /__ 
    REM    / / / // ___// _ \ / ___// ___/   | | /| / // __ \ / ___// //_/
    REM   / /_/ /(__  )/  __// /   (__  )    | |/ |/ // /_/ // /   / ,<   
    REM   \____//____/ \___//_/   /____/     |__/|__/ \____//_/   /_/|_|
    '// ===========================================================                              
    '// === For each line in TCs temp list:
    For i=0 To  UBound(aLineArray) -1
        sFullName  = aLineArray(i)


        sUNCName = replace(sFullName,sDriveLetter,sShareName) & vbCRLF
        sOUT = sOUT & sUNCName 
        
        
        '//WSO.Run strCommand [,intWindowStyle 0=Hide 1=Activate 2=mini 3=maxi ...] [,bWaitTillFinish? True/False]
        'iRetCode = WS.Run("%COMSPEC% /c Echo Y| cacls "_& strHomeFolder & " /t /c /g Administrators:f "_& strUser & ":F", 2, True)
		'If iRetCode <> 0 Then Wscript.Echo "Error"
		
		
        
    Next ' === next line of TCs temp list
    '// Output the result:
    sOUT = Left(sOUT, Len(sOUT)-2) '//removing trailing line break:
    'SetClipboard sOUT
    ShowHTML sOUT
    '// ===========================================================  
    REM       ______    _   __    ____ 
    REM      / ____/   / | / /   / __ \
    REM     / __/     /  |/ /   / / / /
    REM    / /___    / /|  /   / /_/ / 
    REM   /_____/   /_/ |_/   /_____/                          
    '// ===========================================================  ^^^ USERs' WORK ABOVE ^^^
'// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
Else
    MsgBox "Input file sTCtempList not found, or nothing selected." _
          & " Read this script source code for help.",,"TC-Script - ERROR"
    WScript.Quit
End If
'// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
'// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
'// =========================================================== HELPER FUNCTIONs
Function GetUNCName(sDriveLetter)
    On Error Resume Next
    '// change sDriveLetter like "W:" to "\\Server\share\"
    Set cDriveColl = NET.EnumNetworkDrives()
    GetUNCName = sDriveLetter 
    For iDrive = 0 To cDriveColl.Count - 1 Step 2
        If cDriveColl.Item(iDrive) = sDriveLetter Then 
           GetUNCName = cDriveColl.Item(iDrive+1) 
         End If
    Next
End Function
Function GetServerIP(sServerName)
    On Error Resume Next
    '// get IP-address of server 'sServerName'
    '// Translate 'sServerName' to something like '10.11.12.130'
	Set oExec = WSO.Exec("ping -n 1 " & sServerName)
	sStdOutRes = oExec.StdOut.ReadLine ' commands' first line is blank 
	sStdOutRes = oExec.StdOut.ReadLine
	If(sStdOutRes<>"") Then
        iPosS = InStr(sStdOutRes,"[")
        iPosE = InStr(sStdOutRes,"]")
        GetServerIP = mid(sStdOutRes,iPosS+1, iPosE-iPosS -1)
        If(GetServerIP="") Then GetServerIP = "Error-2"
    Else
        GetServerIP = "Error-1"
    End If
End Function
Function SetClipboard(sToClipboard)
    On Error Resume Next
    Set oIE = CreateObject("InternetExplorer.Application")
    oIE.Navigate("about:blank")
    oIE.document.parentwindow.clipboardData.SetData "text", sToClipboard
    oIE.Quit
End Function
Function ShowHTML(strText)
'// Show 'strText' in a bigger InternetExplorer Window (as MsgBox replacement)
    '-------------------------------------------------
    sHTMLText = strText
    sHTMLText = replace(sHTMLText,"<" , "<"  )
    sHTMLText = replace(sHTMLText,">" , ">"  )
    sHTMLText = replace(sHTMLText,"&" , "&" )
    sHTMLText = replace(sHTMLText,"  ", "&nbsp;")
    sHTMLText = replace(sHTMLText,vbCRLF, "<BR>")
    '-------------------------------------------------
    SET oIE = CreateObject("InternetExplorer.Application")
    oIE.navigate "about:blank" : oIE.Toolbar=0 : oIE.Statusbar=0 : : oIE.MenuBar=0 : oIE.AddressBar=0 : oIE.resizable = 0 
    oIE.width=600 : oIE.height=500
    'objIE.Document.body.style.overflow = "auto" ' Hide the scrollbars
    oIE.Left = (oIE.Document.parentWindow.screen.availWidth  - oIE.Width ) \ 2  ' Center the dialog window on the screen
    oIE.Top  = (oIE.Document.parentWindow.screen.availHeight - oIE.Height) \ 2
    Do while (oIE.busy) : WScript.Sleep 900 : Loop

    SET oIEDoc = oIE.document : oIEDoc.open
    oIEDoc.writeln "<HTML><HEAD><TITLE>Total Commander Script</TITLE></HEAD><BODY>"
    'oIEDoc.writeln "<div align=""center"">" --- ' <PRE>
    oIEDoc.writeln  "<p><input type='hidden' id='OK'     name='OK'     value='0'>" 'WICHTIG. Trick für PAUSE
    oIEDoc.writeln  "<p><input type='hidden' id='Cancel' name='Cancel' value='0'>"
    'oIEDoc.writeln sHTMLText & "<BR>"
    oIEDoc.writeln "<textarea WRAP='OFF' style='font-size: 8pt' id='MyTE' contenteditable='true' name='MyTextArea' rows='27' cols='73'>" & strText & "</textarea>"
    oIEDoc.writeln "<BR><BR>"
    oIEDoc.writeln "<div align='Center'><input type='submit' id='OKButton'  value='OK'     onClick='VBScript:OK.value=1'>" 'Press Button to close the window
    oIEDoc.writeln " &nbsp; &nbsp; &nbsp; &nbsp; <input type='submit' id='CancelBtn' value='Cancel' onClick='VBScript:OK.value=2'></DIV>" 
    oIEDoc.writeln "</BODY></HTML>"
    oIEDoc.close : oIE.visible=1 : oIE.Document.all.OKButton.focus' Set focus on Cancel button

    On Error Resume Next
    Do While oIE.Document.all.OK.value = 0 and oIE.Document.all.Cancel.value = 0
        WScript.Sleep 900
        iErrorNum=Err.Number
        If iErrorNum <> 0 Then                'user clicked red X (or alt-F4) to close IE window
            ShowHTML = 0 :  oIE.Quit :  Set oIE = Nothing
            Exit Function
        End if
    Loop
    On Error Goto 0
    
    oIE.Visible = False
    'If(oIE.Document.all.OK.value = 1) Then ShowHTML = oIE.Document.all.MyTextArea.value Else ShowHTML = "CANCELLED"
    oIE.Quit : Set oIE = Nothing   
End Function 'ShowHTML
'// =========================================================== Results examples:
'// RESULTs:
'// =========================================================== 
'// ===========================================================
'// =========================================================== END




 
Post Reply