Jump to content

copyleft

Active Members
  • Posts

    120
  • Joined

1 Follower

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

copyleft's Achievements

  1. @seadoggie01. Wow. Thanks so much for the annotated code; it's been a while since I've run into a post so helpful. Back it 2004 there were a lot more like you around this forum; but now it's a lot of negative energy.
  2. I am marking this as solved, even though it isn't. As my knowledge of AutoIt is evidently not as extensive as yours, we seem to be talking past each other.
  3. Well, with your second script running and the Wndows screen display set to timeout after 1 minute. Nothing happens after several minutes.
  4. Yes, I meant when the screen goes blank after a set period of minutes. However, I tried your second script and nothing happens. Does this script need to be running all the time to detect the console display state? I'm beginning to think that Microsoft just doesn't want any automatic disconnection of network connections, especially on Windows 11. I created a script that initially worked when triggered by Windows Task manager. But it would not run a second time and I basically ended up having the same problem these guys had. And even manually invoking "netsh interface set interface ""Local Area Connection"" admin=disabled" my PC somehow turns networking back on overnight. Not sure what's going on. Definitely not a virus. This is a clean install. I'll mark tthis issue as closed. Thanks again for trying to help me.
  5. I appreciate your effort to help me. But I am trying to write an Autoit script that disables all network connections and logs off a user after the Windows display times out. Executing your code, above, does not do that.
  6. Sorry. I'm lost. Where do I put: Run("netsh interface set interface ""Local Area Connection"" admin=disable", "", @SW_HIDE) Run("shutdown -l -f", "", @SW_HIDE) Should I replace "While True" with that run code?
  7. I'm still learning AutoIt and don't quit understand how to invoke Windows api's correctly. But I am trying to write an Autoit script that disables all network connections and logs off a user after the Windows display times out or (better yet after the screen saver come on). However, my script, below complains there is no defined function for " _WinAPI_GetMonitorPowerStatus" and no declaration for "$PowerDeviceD0". Is there some file missing in my AutoIt "include" directory? #RequireAdmin #include <WinAPI.au3> #include <Constants.au3> Global $hWnd = WinWait("[CLASS:Progman]", "", 10) Global $iLastState = _WinAPI_GetMonitorPowerStatus() While 1 $iCurrentState = _WinAPI_GetMonitorPowerStatus() If $iCurrentState <> $iLastState Then If $iCurrentState = $PowerDeviceD0 Then Run("netsh interface set interface ""Local Area Connection"" admin=disable", "", @SW_HIDE) Run("shutdown -l -f", "", @SW_HIDE) EndIf $iLastState = $iCurrentState EndIf Sleep(1000) WEnd
  8. Thanks. I think there's a conflict with a pre-assigned hotkey within the application because it won't go to the title bar now when the escape key is pressed. I just settled on an old-fashioned time out to get me to the title bar upon timeout expiration.
  9. Trying to write autoit script that opens app search prompt upon app execution then sends cursor to the app title bar if the escape key is pressed. #RequireAdmin #include <MsgBoxConstants.au3> Global $g_bEscPressed = False HotKeySet("{ESC}", "OnEscPressed") ShellExecute("C:\Windows\PowerRun.exe", "Myapp.exe") WinWait("Myapp", "") send ("^f") ;open app search prompt If $g_bEscPressed Then send ("!d"); goto app titlebar EndIf Exit Func OnEscPressed()     $g_bEscPressed = True EndFunc ; end Exit
  10. REMOVED/SOLVED. Plain old batch script seems to work more reliably and faster.  
  11. Added network path check and console write; script completes with no errors but still no files deleted, like I said, must be some other Windows issue. I'll move along unless someone has other ideas. #RequireAdmin #include <File.au3> #include <Date.au3> Global $sNetworkPath = "\\SHARE\home\Logs" If FileExists($sNetworkPath) Then ConsoleWrite("Network path is accessible." & @CRLF) Global $sCurrentDate = _NowCalc() Global $sOldDate = _DateAdd('d', -6, $sCurrentDate) Global $aFileList = _FileListToArray($sNetworkPath, "*.htm", 1) For $i = 1 To $aFileList Global $sFileDate = FileGetTime($sNetworkPath & "\" & $aFileList[$i], 1, 1) If $sFileDate <> -1 And $sFileDate < $sOldDate Then FileDelete($sNetworkPath & "\" & $aFileList[$i]) ConsoleWrite("Deleted file: " & $aFileList[$i] & @CRLF) EndIf Next Else ConsoleWrite("Network path is not accessible." & @CRLF) EndIf If $CmdLine > 0 And $CmdLine = "/console" Then ConsoleWrite("Running script in console mode..." & @CRLF) Else ConsoleWrite("Running script in normal mode..." & @CRLF) EndIf
  12. @Danp2 I have searched the forums. I think something else is broke because trying do delete files older than X doesn't even work with a batch script, which is what brought me here in the first place.
  13. @Danp2 I'm lost here. Do you mean supply a path value for $sFilePath like below? #RequireAdmin #include <File.au3> #include <Date.au3> Global $sFolderPath = "\\SHARE\home\Logs" Global $sfilepath = "\\SHARE\home\Logs\*.htm" Global $iDaysToKeep = 21 Global $sDate = _DateAdd('d', -$iDaysToKeep, _NowCalcDate()) For $sFile In _FileListToArray($sFolderPath) $sFilePath = $sFolderPath & "\" & $sFile $sFileDate = FileGetTime($sFilePath, 1, 1) ; $FT_CREATED, $FT_STRING If $sFileDate <> -1 And $sFileDate < $sDate Then FileDelete($sFilePath) EndIf Next
  14. Tryin to delete files older than 21 days in a network folder. The user has admin access to the folder, but the script, below doesn't delete any files. #RequireAdmin #include <File.au3> #include <Date.au3> Global $sFolderPath = "\\SHARE\home\Logs" Global $iDaysToKeep = 21 Global $sDate = _DateAdd('d', -$iDaysToKeep, _NowCalcDate()) For $sFile In _FileListToArray($sFolderPath) $sFilePath = $sFolderPath & "\" & $sFile $sFileDate = FileGetTime($sFilePath, 1) If $sFileDate <> -1 And $sFileDate < $sDate Then FileDelete($sFilePath) EndIf Next
  15. I cobbled this script from the "WinExists" example in the AutoIt help file. It works fine except if I dismiss the "Window exists" msgbox or leave that "Window exists" command in line 10 out of my script altogether, the browser window closes. I want to perform several file and directory commands and run a program after I manually close the browser normally, without having to dismiss the small Autoit message box. $SetupDir= "D:\Chrome\data" $webfile = "file:///C:/Bin/0HOME.HTM" Chrome() Func Chrome() ; Run Chrome ShellExecute("D:\Chrome\chromium-portable.exe", $webfile) ; Wait 3 seconds for Chrome. WinWait("[CLASS:Chrome_WidgetWin_1]", "", 3) ; Test if Chrome opens and display the results. If WinExists("[CLASS:Chrome_WidgetWin_1]") Then MsgBox($MB_SYSTEMMODAL, "", "Chrome exists") Else Sleep(300); to lower CPU usage less FileDelete($SetupDir & "\Default\Preferences") EndIf EndFunc Exit
×
×
  • Create New...