Jump to content

Help on script to extract command line output substrings


fgilain
 Share

Recommended Posts

Hello,

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
WEnd
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 :

C:\>C:\Temp\psfile.exe

psfile v1.02 - psfile
Copyright ® 2001 Mark Russinovich
Sysinternals

Files opened remotely on MYCOMPUTER:

[805307366] C:\Temp\efzefezfzefezfzefzefzef\erregregergregergerg\toto.pdf
    User:   ADMINISTRATEUR
    Locks:  0
    Access: Read
[805307371] C:\Temp
    User:   ADMINISTRATEUR
    Locks:  0
    Access: Read
[805307384] C:\Temp\titi.pdf
    User:   ADMINISTRATEUR
    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

Florent

post-2780-0-60744300-1385719829_thumb.jp

Link to comment
Share on other sites

try _StringBetween()

Signature - my forum contributions:

Spoiler

UDF:

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

Apps:

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
 Share

  • Recently Browsing   0 members

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