在AutoIt中重写一个字符串只能工作一次,但不是第二次

时间:2016-11-10 15:21:53

标签: windows network-programming autoit

我正在研究一些AutoIt代码,以帮助我解决办公室恶作剧和其他问题。第一个字符串用于将字符串“shutdown pc00xxx”重写为shutdown /r /m pc00xxx /t 0,但我无法获得第二个字符串。

我有以下代码:

func RunProc($string)
    Local $command = StringLower($string)
    Local $subs = StringMid($command, 1, 4)
    Local $computer = StringInStr($command, "pc")

    if $subs == "shut" Then

        Run("shutdown /r /m " & StringMid($command, $computer) & " /t 0")

    ElseIf $subs == "clos" Then

        Local $prleft = StringTrimLeft($command, 6)
        Local $extend = StringInStr($command, "on")
        Local $pright = StringTrimRight($prleft, $extend)
        Local $strclose = StringMid($string, $prleft, $pright)
        Run("taskkill.exe /S "& StringMid($command, $computer) & "  /im " & $strclose & ".exe")
    EndIf

问题是我正在尝试重写短语“CLOSE”SOMETHING“ON”pc00xxx“为taskkill.exe / S pc00xxx / im SOMETHING.exe,我试图获取”CLOSE“和”之间的子串“在pc00xxx上。

因此,举例来说,我会在PC00xxx上键入CLOSE OUTLOOK,并且$ strclose的值为:

$strclose = outlook

2 个答案:

答案 0 :(得分:0)

试试这个:

$string = 'CLOSE OUTLOOK ON PC00xxx'
$aMatch = StringRegExp($string, '(?i)close (.+) on pc.+', 1)
If IsArray($aMatch) Then ConsoleWrite('App: ' & $aMatch[0] & @CRLF)

答案 1 :(得分:0)

或者,使用StringSplit:

$string = 'CLOSE OUTLOOK ON PC00xxx'
$stringcomponents=StringSplit(StringStripWS($string,4)," ")
$strclose=$stringcomponents