Jump to content

Help on script to extract command line output substrings


Recommended Posts


i need to force closing of remotely opened file in specific path on my server, so i wanted to use the "net file" (standard Windows command)  or "psfile" (from Microsoft Pstools, better than "net file" because it doesn"t truncate the full path of opened file)  tool to list locked files and close them.

Here is what i already found to start :

$strCmdOutput = Run(@ComSpec & " /c C:\Temp\psfile.exe", "", Default, $STDERR_MERGED)
$strLockedFilesList = ""
While 1
    $strSTDOUT = StdoutRead($strCmdOutput)
    If $strSTDOUT <> "" Then $strLockedFilesList = $strLockedFilesList & @CRLF & $strSTDOUT
    If @error Then ExitLoop
MsgBox (0, "List of Locked cifs files", $strLockedFilesList)

Autoit code actually shows me the window you'll see in the attached screenshot.

Command line output will generally give something like that :


psfile v1.02 - psfile
Copyright ® 2001 Mark Russinovich

Files opened remotely on MYCOMPUTER:

[805307366] C:\Temp\efzefezfzefezfzefzefzef\erregregergregergerg\toto.pdf
    Locks:  0
    Access: Read
[805307371] C:\Temp
    Locks:  0
    Access: Read
[805307384] C:\Temp\titi.pdf
    Locks:  0
    Access: Read

What i need to do is to extract each lock numbers (numbers between the "[" and the "]") and run another command with them in parameter..

Thanks for your help



Link to comment
Share on other sites

try _StringBetween()

Signature - my forum contributions:



LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates


Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff


Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...