Batch: Stop Cortana Memory Hog

Googling for "Microsoft Windows 10 Cortana®" reveal MANY complaints about memory loss. My experience is 28-33% reported by Task Manager even when Cortana's voice listening and response services are DISABLED / "inactive"! The best advice found to-date has been "remove" or "rename it"!

Usually a BAD workaround! Especially since it was IMPOSSIBLE to do it manually.
Therefore this BATCH file is offered with the warning "EXAMPLE only! Do *NOT* attempt this on any computer. This batch file is ONLY OFFERED as an example of the "IF" statement and batch logic flow."

@echo off

rem set statusstring="end of %0"

SET /P ISADMIN=Are you RUNNING THIS AS ADMIN (usually from a shortcut 'RUN AS ADMIN') Y/N: =
if /I NOT "%ISADMIN%"=="Y" goto OOPS
rem KLUDGE to SOLVE MEMORY HOG PROBLEM
rem CORTANA is MICROSOFT's AUDIO LISTENER
rem it can take 20-30% or more of RAM
rem can't MANUALLY RENAME or MOVE it because Task Manager RELOADS it
rem SOLUTION: replace MANUAL steps with BATCH commands

setlocal
rem @echo on

echo step 1 kill SearchUI and rename
IF %ERRORLEVEL% GTR 1 SET ERRSTRING=errlevel%ERRORLEVEL%

for %%x in (ActionUriServer.exe PlacesServer.exe RemindersServer.exe RemindersShareTargetApp.exe SearchUI.exe backgroundTaskHost.exe) do IF EXIST %%x taskkill /T /F /PID %%x

rem taskkill /T /F /PID SearchUI.exe
rem taskkill /T /F /PID backgroundTaskHost.exe

echo step 2 rename folder and/or SearchUI.exe to stop RESTART of Cortana
IF EXIST C:\Windows\SystemApps\Microsoft.Windows.Cortana_cw5n1h2txyewy pushd C:\Windows\SystemApps\Microsoft.Windows.Cortana_cw5n1h2txyewy
IF EXIST SearchUI.exe rename SearchUI.exe zSearchUI.exe
pushd C:\Windows\SystemApps
IF EXIST Microsoft.Windows.Cortana_cw5n1h2txyewy move /Y Microsoft.Windows.Cortana_cw5n1h2txyewy Microsoft.Windows.½Cortana_cw5n1h2txyewy

dir /ad Microsoft.Windows.?C*

GOTO END
:OOPS
set statusstring=RUN AS ADMIN (right click on "%0" and Run As Admin)
echo %statusstring%
:END

echo ....
IF NOT "%ERRSTRING%"=="" echo %ERRSTRING%
ECHO FINISHED BATCH FILE %0
pause
endlocal

 

vB Regex Error Detection

This is a sample of "stub" code using REGEX (regular expressions) to find predefined Error words 

    1. detect and skip  Windows Certificate Errors or similar Error page that IE may surprise the user with
    2. Fill in a Login Form
  • To WORK: it needs you to identify the (login or other) form elements
    1. identify a unique STRING in the unexpected  Error (Certificate) page
'________________________

Function checkForError(strErr,strTag)' returns 1 of 3 strings FULL LARGE INNERTEXT STRING IF ERR FOUND, ELSE "PASS"
Dim names,ele,innerText,outerText,temp,bFlag' used as string to debug
temp=""
bFlag=False' flag True if ERR FOUND, false if ERR NOT FOUND
Set names=objIE.Document.getElementsByTagName(strTag)


' sample: needs IE page object to be defined and navigated to as current page, having login form elements

'√' CHECKING for and bypassing MICROSOFT CERTIFICATE WARNING



isUnsafe=findClickOkIfUnsafe("not recommended",testLinks)'bad string is first param signalling certificate error

If isUnsafe>=0then testLinks(isUnsafe-1).Click'(1) works if HARD CODED FROM OBSERVATION - code returns (2) ??
' testLinks(isUnsafe).Click ' using index as boolean???? xyz
call waitForReady(objIE)' do this after each click on menu
end If ' self documenting comments by doing "find" of H4 tag or any desired flag/tag

' LEAVING MICROSOFT CERTIFICATE WARNING INTO LOG IN PAGE



'_________ functions / subroutines _________

Function findClickOkIfUnsafe(strInnerText,someArray)' returns index if any member of someArray has "bad string"
Dim k,foundAt,strtmp
foundAt=-1
strtmp=""
'msgbox "array length: " & someArray.length,,"from Function findClickOkIfUnsafe" '
for debugging, tells you where you are
for k = 0 to someArray.length-1'LBound(someArray) to UBound(someArray)
If (boolRegExMatch ( someArray( k ).innerText, trim(strInnerText)) > 0)then
'booltemp = True '( True OR booltemp)
foundAt= k
exit for
end if
next 'k

findClickOkIfUnsafe=foundAt ' if for/next never entered then returns -1 from second line
End Function

'________________________

Function boolRegExMatch(regx,strng) ' returns COUNT no it's NOT boolean!!!!
Dim regEx,Match,Matches,n,tmp ' Create variable.
Set regEx=NewRegExp ' Create a regular expression.
regEx.Pattern=regx ' Set pattern.
regEx.IgnoreCase=True ' Set case insensitivity.
regEx.Global=True ' Set global applicability.
Set Matches=regEx.Execute(strng)' Execute search.
boolRegExMatch=Matches.count
Set Matches=Nothing
Set RegEx=Nothing
End Function

'________________________

Function checkForError(strErr,strTag)' returns 1 of 3 strings FULL LARGE INNERTEXT STRING IF ERR FOUND, ELSE "PASS"
Dim names,ele,innerText,outerText,temp,bFlag' used as string to debug
temp=""

bFlag=False' flag True if ERR FOUND, false if ERR NOT FOUND
Set names=objIE.Document.getElementsByTagName(strTag)

Foreacheleinnames
innerText=ele.innerText
If (boolRegExMatch(strErr,innerText)>0)Then
'If Instr(1, innerText, strErr) Then
temp=
"Fail: "&innerText' innerText

exit For' only reports first error found!?
Else
temp="PASS"
End If
Next
checkForError=temp
End Function
'________________________
Function fnLogin(uid,pwd)
Dim inputs,strPageStatus
Set inputs=objIE.Document.getElementsByTagName("INPUT")

' inputs(1).Value = uid
' on Error Resume Next
inputs(2).Value=uid
inputs(3).Value=pwd
inputs(4).Click

' on Error GoTo 0
' If Err.Number then strPageStatus = "FAILERROR: CLOSE DUPLICATE BROWSER SESSION" & vbCrlf & Err.Description else
waitForReady(objIE)
strPageStatus=checkForError(".*password.*incorrect.*|Prohibite.*","DIV")'prefixes "Failed:" to InnerText
' End If
fnLogin=strPageStatus
End Function

'________________________

Function checkForError(strErr,strTag)' returns 1 of 3 strings FULL LARGE INNERTEXT STRING IF ERR FOUND, ELSE "PASS"
Dim names,ele,innerText,outerText,temp,bFlag' used as string to debug
temp=""

bFlag=False' flag True if ERR FOUND, false if ERR NOT FOUND
Set names=objIE.Document.getElementsByTagName(strTag)

Foreacheleinnames
innerText=ele.innerText
If (boolRegExMatch(strErr,innerText)>0)Then
'If Instr(1, innerText, strErr) Then temp="Fail: "&innerText' innerText

exit For' only reports first error found!?
Else
temp="PASS"
End If
Next
checkForError=temp
End Function
'________________________