Jump to content
Sign in to follow this  
johnmcloud

[SOLVED] Winactive and StringTrim problem

Recommended Posts

johnmcloud

Hi guys, this is my script:

$File1 = @WorkingDir & "\Test1.txt"
$File2 = @WorkingDir & "\Test2.txt"
$FileNameEstension = StringTrimLeft($File2, StringInStr($File2, "\", 0, -1))
$FileNameOnly = StringTrimRight($FileNameEstension, 4)
ClipPut(FileRead($File1))
Start($File2)
func Start($File2)
    If Not FileExists($File2) Then Return 0
    Return Run(@ComSpec & " /c " & "start " & FileGetShortName($File2),"",@SW_HIDE)
endfunc
If WinActive($FileNameOnly & " - Notepad") Then Send("^v")
Send("^s")
WinClose($FileNameOnly & " - Notepad")

First, would know if you can merge this part into a single string:

$FileNameEstension = StringTrimLeft($File2, StringInStr($File2, "\", 0, -1))
$FileNameOnly = StringTrimRight($FileNameEstension, 4)

The first line give me Test.txt, the second remove the extension. I try to connect with "&" but not work.

The script don't work becouse don't recognize the window name:

WinActive($FileNameOnly & " - Notepad")

I don't know what is the problem. Thanks for support :)

Edited by johnmcloud

Share this post


Link to post
Share on other sites
guinness

First, would know if you can merge this part into a single string:

Use this instead, to get just the filename.

ConsoleWrite(StringRegExpReplace(@ScriptFullPath, '.*|.[^.]*$', '') & @LF) ; By MrCreatoR - http://www.autoitscript.com/forum/topic/41897-pathsplitbyregexp/

Try this.

WinActive("[CLASS:Notepad]"")
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Emiel Wieldraaijer

I know this is poluting the thread but

ConsoleWrite(StringRegExpReplace(@ScriptFullPath, '.*|.[^.]*$', '') & @LF) ; By MrCreatoR - http://www.autoitscript.com/forum/topic/41897-pathsplitbyregexp/

is so awesome :)


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites
guinness

It's a nice little UDF he created, plus I'm in the midst of perfecting my knowledge of SREs so this is a great foundation to learn from.

Edit: Spelling mistake.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
johnmcloud

Use this instead, to get just the filename.

ConsoleWrite(StringRegExpReplace(@ScriptFullPath, '.*|.[^.]*$', '') & @LF) ; By MrCreatoR - http://www.autoitscript.com/forum/topic/41897-pathsplitbyregexp/

Not work for me ;)

$var = ConsoleWrite(StringRegExpReplace(@WorkingDir & "Test.txt", '.*|.[^.]*$', '') & @LF)
MsgBox(0,0,$var)

The result is 5 :)

Share this post


Link to post
Share on other sites
guinness

Please look at the Help file to see what ConsoleWrite is, the actual code is inside the ConsoleWrite syntax see...

StringRegExpReplace(@ScriptFullPath, '.*|.[^.]*$', '') ; By MrCreatoR
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
johnmcloud

Please look at the Help file to see what ConsoleWrite is, the actual code is inside the ConsoleWrite syntax see...

StringRegExpReplace(@ScriptFullPath, '.*|.[^.]*$', '') ; By MrCreatoR

Sorry, i'm never used ConsolWrite, but i have another problem.

Send("^v")

Seems not work, but if i click manually control+V it past:

$File1 = @WorkingDir & "Test1.txt"
$File2 = @WorkingDir & "Test2.txt"
ClipPut(FileRead($File1))
Start($File2)
func Start($File2)
    If Not FileExists($File2) Then Return 0
    Return Run(@ComSpec & " /c " & "start " & FileGetShortName($File2),"",@SW_HIDE)
endfunc
If WinActive("[CLASS:Notepad]") Then Sleep(500)
Send("^v")
Send("^s")
WinClose("[CLASS:Notepad]")

Thanks guinness for your help

Edited by johnmcloud

Share this post


Link to post
Share on other sites
guinness

ControlSend perhaps?


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
johnmcloud

ControlSend perhaps?

The problem wasn't send command, but WinActive:

$File1 = @WorkingDir & "Test1.txt"
$File2 = @WorkingDir & "Test2.txt"
ClipPut(FileRead($File1))
Start($File2)
func Start($File2)
    If Not FileExists($File2) Then Return 0
    Return Run(@ComSpec & " /c " & "start " & FileGetShortName($File2),"",@SW_HIDE)
endfunc
If WinWaitActive("[CLASS:Notepad]") then Send("^v")
Send("+{F12}")
;SHIFT + F12 for save
WinClose("[CLASS:Notepad]")

I'll change with WinWaitActive, now working file. I try tu use the name of notepad windows, but don't accept it. but cherish the script for future events.

Thanks all :)

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Similar Content

    • chriswaldeck
      By chriswaldeck
      I am capturing data from a web page as soon as it opens. The problem is I am running a dual screen setup and the script don't capture the data when the window is opened up in the non default monitor. On the default monitor it works fine.
      Func Monitor() Local $hTimer = TimerInit()             Do             $fDiff = TimerDiff($hTimer)         Until WinActive("ActivityDetail - Internet Explorer") Or $fDiff >= 5000     ; Only sees window on default monitor.         If WinActive("ActivityDetail - Internet Explorer") Then                                 ; Only sees window on default monitor.             Local $hWnd = WinGetHandle("ActivityDetail - Internet Explorer", "")             Local $oIE = _IEAttach($hWnd, "hwnd")             If @error Then                 $oIE.Quit()             Else                 Local $oForm = _IEGetObjByName($oIE, "lblHeaderActRefValue")                 Local $Ref = _IEPropertyGet($oForm, "innertext")                 Local $oForm = _IEGetObjByName($oIE, "lblCompileDate")                 Local $Compile = _IEPropertyGet($oForm, "innertext")                 Local $oForm = _IEGetObjByName($oIE, "Table2")                 Local $Description = _IEPropertyGet($oForm, "innertext")                 $Description = StringTrimLeft($Description, 49)                 Local $iLength = StringLen($Description)                 Local $iPosition = StringInStr($Description, "Network Tag")                 Local $sString = StringTrimRight($Description, ($iLength - ($iPosition - 1)))                 Local $sString1 = StringStripWS($sString, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES)                 Local $sString = $sString1                 Local $oForm = _IEGetObjByName($oIE, "lblDisruption")                 Local $Disruption = _IEPropertyGet($oForm, "innertext")                 If $flag <> $Ref And $Ref <> 0 and $Compile <> 0 Then                     $ICount = _GUICtrlListView_GetItemCount($ListView1)                     _GUICtrlListView_AddItem($ListView1, $Compile, $ICount)                     _GUICtrlListView_AddSubItem($ListView1, $ICount, $Ref, 1)                     _GUICtrlListView_AddSubItem($ListView1, $ICount, $Disruption, 2)                     _GUICtrlListView_AddSubItem($ListView1, $ICount, $sString, 3)                     _FileWriteLog(@ScriptDir & "\" & @YEAR & @MON & ".txt", $Ref & " " & $Disruption & " " & $sString & @CRLF)                     $flag = $Ref                 EndIf             EndIf         EndIf EndFunc   ;==>Monitor  
    • Miliardsto
      By Miliardsto
      Hello . How to do that
      $regexp = starts from "abcdef" and after this could be anything in name
      WinActivate($regexp)
    • NiceBoy1234
      By NiceBoy1234
      I want to check if the cmd.exe + window of it is running, if it is running I want to put the window to the foreground, but somehow this does not work:
       
      Local $sCommandlinePath = "C:\Windows\system32\cmd.exe" RunCm() Func RunCm() If FileExists($sCommandlinePath) Then If ProcessExists("cmd.exe") Then If WinExists("[CLASS:ConsoleWindowClass]") And WinActive("[CLASS:ConsoleWindowClass]") Then Local $hCmdWindow = WinGetHandle("[CLASS:ConsoleWindowClass]") WinSetOnTop($hCmdWindow, "", $WINDOWS_ONTOP) EndIf Else Local $iCmMax = Run($sCommandlinePath, "", @SW_SHOWMAXIMIZED) EndIf EndIf EndFunc I started the command line and put another window above it then I started my script and it did not put the command line window to the foreground.
×