pqf1 Posted September 27, 2023 Share Posted September 27, 2023 I've been attempting to make a script that automatically runs Disk Cleanup (cleanmgr.exe) via the command line as part of an automatic cleanup suite, and I've been encountering some annoying irregularities when running the code in autoit versus running the same command directly in the command prompt. This isn't the first time I've had something function differently through autoit that works fine when I run it directly in the command prompt, actually, and I'm hoping the solution will help me resolve those as well. #RequireAdmin ;cleanmgr has been set via cleanmgr /SAGESET:1 with all boxes checked, and I confirmed this in the registry ;These all launch cleanmgr automatically but it only handles the Downloaded Program Files and Temporary Internet Files, instead of all that have been set RunWait("cleanmgr /SAGERUN:1") RunWait(@comspec " /c cleanmgr /SAGERUN:1312") RunWait("test.bat") ;batch file in the same directory as the script which runs it correctly when launched directly, but not through autoit When I run the exact same commands directly in the command prompt, or via the batch file I made, it works correctly, handling all the checked fields in cleanmgr. What can I do to resolve this? Link to comment Share on other sites More sharing options...
pqf1 Posted September 27, 2023 Author Share Posted September 27, 2023 39 minutes ago, pqf1 said: I've been attempting to make a script that automatically runs Disk Cleanup (cleanmgr.exe) via the command line as part of an automatic cleanup suite, and I've been encountering some annoying irregularities when running the code in autoit versus running the same command directly in the command prompt. This isn't the first time I've had something function differently through autoit that works fine when I run it directly in the command prompt, actually, and I'm hoping the solution will help me resolve those as well. #RequireAdmin ;cleanmgr has been set via cleanmgr /SAGESET:1 with all boxes checked, and I confirmed this in the registry ;These all launch cleanmgr automatically but it only handles the Downloaded Program Files and Temporary Internet Files, instead of all that have been set RunWait("cleanmgr /SAGERUN:1") RunWait(@comspec " /c cleanmgr /SAGERUN:1312") RunWait("test.bat") ;batch file in the same directory as the script which runs it correctly when launched directly, but not through autoit When I run the exact same commands directly in the command prompt, or via the batch file I made, it works correctly, handling all the checked fields in cleanmgr. What can I do to resolve this? Adding to this, I tried running test.bat through SciTE instead of directly from file explorer, and it encountered the same issue there. Starting to think the issue is with some kind of setting in SciTE? Link to comment Share on other sites More sharing options...
pqf1 Posted September 27, 2023 Author Share Posted September 27, 2023 After some more testing, I was able to get things working with a python script that calls disk cleanup. This is obviously not ideal, as it means there's an entire extra file I have to keep track of, but it works for now, until I can resolve the issue. Link to comment Share on other sites More sharing options...
Solution abberration Posted September 27, 2023 Solution Share Posted September 27, 2023 I think this has to do with #RequireAdmin, which will run the script as an administrator. Try creating the Sageset configuration the exact same way that you run the command. I have created a small example where you can create the command and run it exactly the same way. Maybe it will help? (oh, I prefer shellexecute over run). expandcollapse popup#RequireAdmin #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 270, 179) $Label1 = GUICtrlCreateLabel("Pick a task:", 16, 16, 60, 17) $Radio1 = GUICtrlCreateRadio("Set Sageset task", 16, 40, 113, 17) $Label2 = GUICtrlCreateLabel("Task #", 48, 64, 38, 17) GUICtrlSetState($Label2, $GUI_DISABLE) $Input1 = GUICtrlCreateInput("", 96, 64, 49, 21) GUICtrlSetState($Input1, $GUI_DISABLE) $Radio2 = GUICtrlCreateRadio("Run Sagetask:", 16, 104, 113, 17) GUICtrlSetState($Radio2, $GUI_CHECKED) $Label3 = GUICtrlCreateLabel("Task # ", 48, 128, 41, 17) $Input2 = GUICtrlCreateInput("", 96, 128, 49, 21) GUICtrlSetState($Input2, $GUI_FOCUS) $Button1 = GUICtrlCreateButton("Go!", 176, 104, 75, 49, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Radio1 GUICtrlSetState($Label2, $GUI_ENABLE) GUICtrlSetState($Input1, $GUI_ENABLE) GUICtrlSetState($Label3, $GUI_DISABLE) GUICtrlSetState($Input2, $GUI_DISABLE) GUICtrlSetState($Input1, $GUI_FOCUS) Case $Radio2 GUICtrlSetState($Label3, $GUI_ENABLE) GUICtrlSetState($Input2, $GUI_ENABLE) GUICtrlSetState($Label2, $GUI_DISABLE) GUICtrlSetState($Input1, $GUI_DISABLE) GUICtrlSetState($Input2, $GUI_FOCUS) Case $Button1 $iRun = GUICtrlRead($Radio1) If $iRun = 4 Then ShellExecute("cleanmgr", "/SAGERUN:1") Else ShellExecute("cleanmgr", "/sageset:1") EndIf Exit EndSwitch WEnd Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
pqf1 Posted September 28, 2023 Author Share Posted September 28, 2023 16 hours ago, abberration said: I think this has to do with #RequireAdmin, which will run the script as an administrator. Try creating the Sageset configuration the exact same way that you run the command. I have created a small example where you can create the command and run it exactly the same way. Maybe it will help? (oh, I prefer shellexecute over run). expandcollapse popup#RequireAdmin #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 270, 179) $Label1 = GUICtrlCreateLabel("Pick a task:", 16, 16, 60, 17) $Radio1 = GUICtrlCreateRadio("Set Sageset task", 16, 40, 113, 17) $Label2 = GUICtrlCreateLabel("Task #", 48, 64, 38, 17) GUICtrlSetState($Label2, $GUI_DISABLE) $Input1 = GUICtrlCreateInput("", 96, 64, 49, 21) GUICtrlSetState($Input1, $GUI_DISABLE) $Radio2 = GUICtrlCreateRadio("Run Sagetask:", 16, 104, 113, 17) GUICtrlSetState($Radio2, $GUI_CHECKED) $Label3 = GUICtrlCreateLabel("Task # ", 48, 128, 41, 17) $Input2 = GUICtrlCreateInput("", 96, 128, 49, 21) GUICtrlSetState($Input2, $GUI_FOCUS) $Button1 = GUICtrlCreateButton("Go!", 176, 104, 75, 49, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Radio1 GUICtrlSetState($Label2, $GUI_ENABLE) GUICtrlSetState($Input1, $GUI_ENABLE) GUICtrlSetState($Label3, $GUI_DISABLE) GUICtrlSetState($Input2, $GUI_DISABLE) GUICtrlSetState($Input1, $GUI_FOCUS) Case $Radio2 GUICtrlSetState($Label3, $GUI_ENABLE) GUICtrlSetState($Input2, $GUI_ENABLE) GUICtrlSetState($Label2, $GUI_DISABLE) GUICtrlSetState($Input1, $GUI_DISABLE) GUICtrlSetState($Input2, $GUI_FOCUS) Case $Button1 $iRun = GUICtrlRead($Radio1) If $iRun = 4 Then ShellExecute("cleanmgr", "/SAGERUN:1") Else ShellExecute("cleanmgr", "/sageset:1") EndIf Exit EndSwitch WEnd Interesting... I wonder if the issue is that the way I went about setting the values was different. Originally, I ran w/ sageset directly from an admin command prompt and set everything enabled, and then checked the registry for which keys were set and directly wrote them to the registry with RegWrite for easier automation (I have a lot of machines I have to run this on) When I ran sageset through the code like this, however, future sageruns through autoit DO seem to work. I already had a functional UI Automation script for selecting all the buttons, perhaps I'll make that into a standalone script and just run it once on each machine I set this up on. Link to comment Share on other sites More sharing options...
pqf1 Posted September 28, 2023 Author Share Posted September 28, 2023 (edited) 53 minutes ago, pqf1 said: When I ran sageset through the code like this, however, future sageruns through autoit DO seem to work. I already had a functional UI Automation script for selecting all the buttons, perhaps I'll make that into a standalone script and just run it once on each machine I set this up on. *I had stopped using the GUI automation as I needed the script to run while the system is locked, but I can run sageset ahead of time. I would've just edited the previous post but I don't seem to have that option yet. Edit: Thanks, M23! I can edit my previous posts now! =D Edited September 28, 2023 by pqf1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 28, 2023 Moderators Share Posted September 28, 2023 pqf1, Quote I don't seem to have that option yet You should have it now. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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