Hobbyist Posted April 15, 2023 Posted April 15, 2023 (edited) This is my feeble attempt at writing a script that will 1. look for a Microsoft file, 2. if found immediately delete it, 3. continue to poll my system in case Microsoft tries to install/update again. I want to add the app to task manager so it first checks at boot up time and then through out the day. I have notes (for myself ) in the script. Sorry if it looks messy. The code will find the file and delete it but it keeps looping the cmd window rather than closing it down after finding and deleting the file. And if I am in the wrong forum, I apologize and tell me where I should be. Thanks for any help or guidance. expandcollapse popup#RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=J:\UAC Admin EDGE STOP Rights Version 1.03.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <File.au3> #include <GUIConstants.au3> #include <String.au3> #include <MsgBoxConstants.au3> #include <Date.au3> $Form1 = GUICreate("UAC EDGE STOP Running", 322, 382, -1, -1) GUISetState(@SW_SHOWMINIMIZED) $counter = 0 Local $mycheck $mycheck2 = "23:00" While _NowTime(4) < $mycheck2 Local $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If FileExists("C:\ProgramData\Microsoft\EdgeUpdate\Log") Then FileChangeDir("C:\WINDOWS\system32") ShellExecute("cmd.exe") Sleep(300) ;////////// ;~ $CMD = 'sc.exe config wuauserv start= disabled && ' & _ ;~ 'sc.exe stop wuauserv' ;~ $CMD = 'sc.exe config wuauserv start= disabled && ' & _ ;~ 'sc.exe stop wuauserv && ' & _ ;~ 'del "C:\WINDOWS\softwaredistribution" ' $CMD = 'sc.exe config wuauserv start= disabled && ' & _ 'sc.exe stop wuauserv && ' & _ 'sc.exe config RasMan start= disabled && ' & _ 'sc.exe stop RasMan && ' & _ 'netsh int tcp set global autotuninglevel=disabled && ' & _ 'net stop bits' ; /k keeps the CMD window open. ; /c closes the CMD window once the command is complete. ; Reference: ; Type CMD /? in a command prompt window for help ; with CMD options. Run('"' & @ComSpec & '" /c ' & $CMD, @SystemDir) Sleep(500) $CMD = 'cd C:\ProgramData\Microsoft\EdgeUpdate\Log && ' & _ 'RMDIR /S/Q "C:\ProgramData\Microsoft\EdgeUpdate\Log" ' Run('"' & @ComSpec & '" /c ' & $CMD, @SystemDir) $counter = $counter + 1 Sleep(50) If $counter = 5 Then ;after 5 attempts shut down . this is not mandatory, could live without it Shutdown(1) EndIf ;EndIf Sleep(300) If _NowTime(4) > "22:10" Then Exit EndIf WEnd Edited April 15, 2023 by Jos Tidied and codebox
Developers Jos Posted April 15, 2023 Developers Posted April 15, 2023 (edited) 30 minutes ago, Hobbyist said: And if I am in the wrong forum, I apologize and tell me where I should be. Thanks for any help or guidance. mmm strange that after being a member for such a long time one forgets where support questions need to be posted and doesn't take the time to figure it out first... oh well guess we'll clean up your shit. ... and you also forgot to use codetags for posted code... So, having dumped how I feel about it, is there a question in your text as it feels like it, but there is no question mark anywhere? PS: Your code seems to be invalid as there is an EndIf commented which is required. So pretty sure this code never ran properly! Edited April 15, 2023 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Nine Posted April 15, 2023 Posted April 15, 2023 When you post code, please use the indicated method in the link. Also, tidy your code (Ctrl-t in Scite) so it will make it more readable. As your code is quite invasive, I will not run it, so I am not sure what the problem really is. I have 2 suggestions for you : 1- put some error checking and some logging (ConsoleWrite in Scite) so you know what is going on. 2- if 1 is not helpful, then try to make a replicable snippet of your code that we actually can run without risk “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Hobbyist Posted April 15, 2023 Author Posted April 15, 2023 @Nine Thanks for the decent reply. Since I'm the one asking for help it makes sense to follow your guidance. So I did insert #AutoIt3Wrapper_Run_Tidy=y into the code. I did run Ctrl-t in Scite, like you suggested. I am not sure what you mean by "try to make a replicable snippet". But if you tell me I will give it a try. Here is what I do know about what I have so far. The script does delete the targeted file, not a problem. What continues is the C:\WINDOWS\system32" window doesn't close but keeps looping over and over. I thought line 64 - Run('"' & @ComSpec & '" /c ' & $CMD, @SystemDir) would close the window since I have the /c in the line. I have commented out lines 70, 71, 72 so it avoids the shutdown. My objective is to take this script, compile it and add it my Task Scheduler so when booting up, it will look for the targeted file, if found, delete it and then poll throughout the day in case Microsoft tries to invade my space again. I was able to do this with the Software Distribution folder to keep from having automatic Window updates. Microsoft's Edge is separate. Thanks again for your productive reply. Hobbyist (and no, I haven't been around as long as it has been suggested - I have been out of the country for 5 years, not by choice and I'm starting from scratch all over again). expandcollapse popup#RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=J:\UAC Admin EDGE STOP Rights Version 1.03.exe #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <File.au3> #include <GUIConstants.au3> #include <String.au3> #include <MsgBoxConstants.au3> #include <Date.au3> $Form1 = GUICreate("UAC EDGE STOP Running", 322, 382, -1, -1) GUISetState(@SW_SHOWMINIMIZED) $counter = 0 Local $mycheck $mycheck2 = "23:00" While _NowTime(4) < $mycheck2 Local $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If FileExists("C:\ProgramData\Microsoft\EdgeUpdate\Log") Then FileChangeDir("C:\WINDOWS\system32") ShellExecute("cmd.exe") ElseIf FileExists = 0 Then EndIf Sleep(300) ;////////// ;~ $CMD = 'sc.exe config wuauserv start= disabled && ' & _ ;~ 'sc.exe stop wuauserv' ;~ $CMD = 'sc.exe config wuauserv start= disabled && ' & _ ;~ 'sc.exe stop wuauserv && ' & _ ;~ 'del "C:\WINDOWS\softwaredistribution" ' $CMD = 'sc.exe config wuauserv start= disabled && ' & _ 'sc.exe stop wuauserv && ' & _ 'sc.exe config RasMan start= disabled && ' & _ 'sc.exe stop RasMan && ' & _ 'netsh int tcp set global autotuninglevel=disabled && ' & _ 'net stop bits' ; /k keeps the CMD window open. ; /c closes the CMD window once the command is complete. ; Reference: ; Type CMD /? in a command prompt window for help ; with CMD options. Run('"' & @ComSpec & '" /c ' & $CMD, @SystemDir) Sleep(500) $CMD = 'cd C:\ProgramData\Microsoft\EdgeUpdate\Log && ' & _ 'RMDIR /S/Q "C:\ProgramData\Microsoft\EdgeUpdate\Log" ' Run('"' & @ComSpec & '" /c ' & $CMD, @SystemDir) $counter = $counter + 1 Sleep(50) ;If $counter = 5 Then ;Shutdown(1) ;EndIf ;EndIf Sleep(300) ;If _NowTime(4) > "22:10" Then ; Exit ;EndIf WEnd
Nine Posted April 15, 2023 Posted April 15, 2023 Well your code is highly suspicious. You have an If statement that doesn't do anything beside starting a new DOS console. Then you act as if there is a relationship with this useless If statement. Really, take time to put some ConsoleWrite to follow your code. And this line ElseIf FileExists = 0 Then is not syntax valid, but then also useless. You absolutely need to clean up your code. Make a copy and remove ALL useless code including those commented lines which only bring noise to your case. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Hobbyist Posted April 16, 2023 Author Posted April 16, 2023 @Nine I will delete all my notations. And do some Console write statements The syntax - so it is incorrect to check if the file does exist? If the return value is 0 it does not? That's what I thought it was doing. FileExists Checks if a file or directory exists. FileExists ( "path" ) Parameters Path The directory or file to check. Return Value Success: 1. Failure: 0 if path/file does not exist.
TimRude Posted April 16, 2023 Posted April 16, 2023 As the piece of the help file you posted shows, FileExists is a function that requires a parameter. Do you think that ElseIf FileExists = 0 Then follows that syntax? Keep reading in that help topic and see how the example script codes the If-Then-Else-EndIf conditional.
argumentum Posted April 17, 2023 Posted April 17, 2023 in https://www.autoitscript.com/forum/topic/199177-fork-udf-ish/ there is an example ( Example_Fork_FileMonitor.au3 ) that you can try. See if it serves your needs. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Hobbyist Posted April 17, 2023 Author Posted April 17, 2023 @Nine i removed all the garbage lines as you indicated and inserted ConsolWrite along the way. I ran the script and it finds the target file and deletes it. But the Command Window keeps repeating over and over again until i kill it. My attempt is to find the file, delete it and then continuously poll the system looking for the file if Microsoft tries to reinsert it into the directory. expandcollapse popup#RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=J:\UAC Admin EDGE STOP Rights Version 1.03.exe #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <File.au3> #include <GUIConstants.au3> #include <String.au3> #include <MsgBoxConstants.au3> #include <Date.au3> $Form1 = GUICreate("UAC Running EdgeUpdate", 322, 382, -1, -1) GUISetState(@SW_SHOWMINIMIZED) Local $mycheck $mycheck = "23:00" While _NowTime(4) < $mycheck Local $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit EndSwitch FileChangeDir("C:\WINDOWS\system32") ConsoleWrite ShellExecute("cmd.exe") Sleep(3000) $CMD = 'cd C:\ProgramData\Microsoft\EdgeUpdate\Log && ' & _ 'RMDIR /S/Q "C:\ProgramData\Microsoft\EdgeUpdate\Log" ' Run('"' & @ComSpec & '" /c ' & $CMD, @SystemDir) ConsoleWrite Sleep(300) If _NowTime(4) > "22:10" Then Exit EndIf ConsoleWrite WEnd
ioa747 Posted April 17, 2023 Posted April 17, 2023 (edited) 1 hour ago, Hobbyist said: But the Command Window keeps repeating over and over again until i kill it. for this is responsible the While _NowTime(4) < $mycheck and why you use the Command Window and not the DirRemove ( "path" [, recurse = 0] ) ? and somewhere I saw a ConsoleWrite alone ?? it doesn't give you @error ?? the proper syntax is ConsoleWrite ( "data" ) Edited April 17, 2023 by ioa747 I know that I know nothing
Nine Posted April 17, 2023 Posted April 17, 2023 (edited) I feel ambiguous about your thread (you do really need to (re)learn programming). But since I have tried to help you from the start here : ;#RequireAdmin #include <GUIConstants.au3> #include <Date.au3> Global Const $FOLDER_CHECK = "C:\Apps\Temp\Temp" ; "C:\ProgramData\Microsoft\EdgeUpdate\Log" Example() Func Example() Local $hGUI = GUICreate("UAC Running EdgeUpdate") GUISetState(@SW_SHOWMINIMIZED) While _NowTime(4) < "22:50" Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If FileExists($FOLDER_CHECK) Then ConsoleWrite("Detected at " & @HOUR & ":" & @MIN & @CRLF) DirRemove($FOLDER_CHECK, $DIR_REMOVE) EndIf WEnd EndFunc Edited April 17, 2023 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Hobbyist Posted April 19, 2023 Author Posted April 19, 2023 @ioa747 Thank you for your feedback. This is the helpful content that I need as a beginner.
Hobbyist Posted April 19, 2023 Author Posted April 19, 2023 @Nine Thank you for your help. I'm a beginner so there is yet a lot to be learned. Sorry for your frustrations. I have always been willing to attempt a solution myself and turn to those in the know when I just don't get it. My learning curve is not of those experts on the forum. Any way thanks.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now