--- In [email protected], "Sheri" <[EMAIL PROTECTED]> wrote:

> I am finding that regardless of how I actually enter the command,
> wmic's "Get" has the path, ".exe" (or ".EXE") and surrounding quotes
> around the app portion of the command line. So maybe there's no need
> to allow for no quotations.

I see that is not true if the app was initiated by an entry at the
Command Prompt.

New version captures the command and it's parameters one way if the
command line starts with a double quote and another way it doesn't.
Ignores blank lines in the string returned by wmic and the one that
starts with "CommandLine". Seems to do the job.

Regards,
Sheri

llocal rescmd resparams
local clipcontent=clip.get
clip.clear
local apphandle=win.handle("under")
local appprocess=win.getprocessid(apphandle)
local wmicmd= ;;+
?"/c wmic /output:clipboard process "++appprocess++" GET commandline"
file.runwait(0, env("COMSPEC"), wmicmd, "", "hide")
local res=clip.get
clip.set(clipcontent)
win.terminateprocess(appprocess)
local pattern=?"(?m)^(?(?=\x22))" ;;+
           
++?"(?<quotedcmd>\x22[^\x22\r\n]+\x22)\x20*+(?<qparams>.*)" ;;+
            ++?"|^(?!CommandLine)" ;;+
            ++?"(?<unquotedcmd>[^\x20\r\n]+)\x20*+(?<uparams>.*)"
local pos=regex.pcrematch(pattern, res)
if (pos>0) do
  local rescmd=regex.pcregetnamedsubstring("quotedcmd")
  local resparams=regex.pcregetnamedsubstring("qparams")
  if (rescmd=="") do
    rescmd=regex.pcregetnamedsubstring("unquotedcmd")
    resparams=regex.pcregetnamedsubstring("uparams")
  endif
  do(rescmd,resparams)
endif
/*
win.debug("==============")
win.debug("restored clipboard:", clip.get)
win.debug("res from wmic:", res)
win.debug("quoted:", regex.pcregetnamedsubstring("quotedcmd"))
win.debug("qparams:", regex.pcregetnamedsubstring("qparams"))
win.debug("unquoted:", regex.pcregetnamedsubstring("unquotedcmd"))
win.debug("uparams:", regex.pcregetnamedsubstring("uparams"))
win.debug("rescmd:", rescmd)
win.debug("resparams:", resparams)
win.debug("==============")
*/
quit


Reply via email to