Sign in to follow this  
Followers 0
KongMD

Script to Toggle User's Startup Programs - Issues w/ ControlListView

2 posts in this topic

Hi, everyone. The purpose of my script is to disable all non-Microsoft services and startup programs so that my other installer script can run cleanly during it's required two reboots. The main program is an antivirus program that I'll be installing on a wide variety of student machines (not imaged). If the user has Selective Startup chosen already and has cherry-picked which services and startup programs he/she wants running, I want to save the list of those enabled programs to an .ini file (I'll write that part later) so that they can be re-enabled after the installation.

For now, I'm having issues with ControlListView. Specifically, I'm having difficulties accessing the actual list inside of MSConfig so that I can save the enabled entries. I've tried compiling the script as x86 and as x64, so I don't think that's the problem. When I try to put in the "SelectAll" command before using "GetSelect" and run the program, I get two of the following modal windows from MSConfig:

"The following startup items were turned off during the upgrade from your previous installation. To turn an item back on ..."

Navigating to the General tab reveals that it has selected Diagnostic Startup. Needless to say, I'm a bit perplexed by this strange behavior. AU3Check says all is well, except for 2 function calls "possibly used before declaration.", which isn't actually the case. I've implemented several solutions from other threads related to the issue with no success, and have also tried different types of the ControlIDs available. How do I get an array of the enabled entries?

Addendum: I will share the fully working script with the forum when it's complete!

Sidenote: I know the Sleep(50) is bad programming style, but I just want to get it working before I clean it up/optimize.

#RequireAdmin
#include <GuiTab.au3>
#include <GUIListView.au3>
#include <Array.au3>
;
Opt("WinTextMatchMode", 2)

;*******************DEBUGGING ONLY!!*****************************
DisableStartupProgs()
;**************************END***********************************
Func DisableStartupProgs()
MsconfigStart()
ControlCommand("System Configuration","","SysTabControl321","TabRight","")

;Check if user has Selective Startup enabled
_GUICtrlTab_ClickTab($hTab, 0)
Sleep(50)
$hasSelectStartup = ControlCommand($configWin, "", "Button2", "IsChecked")

If($hasSelectStartup = 1) Then

  ;Get indices of currently selected services
  _GUICtrlTab_ClickTab($hTab, 2)
  Sleep(50)

  ControlFocus($configWin, "", "List1")
  Sleep(50)

  ControlListView($configWin, "", "List1", "SelectAll")   ;VERY bizarre behavior when this is enabled
  $selected = ControlListView ($configWin, "", "List1", "GetSelected" , 1)
  If @error Then
   MsgBox(64, "error", "There was an error!" )
  Else
   MsgBox(64, "title", "selected string: " & $selected)
  
  EndIf

Else
  ;Click services
  _GUICtrlTab_ClickTab($hTab, 2)
  Sleep(50)
  ;Check the hide
  ControlCommand($configWin, "", "Button3", "Check")
  Sleep(50)
  ;Disable all
  ControlClick($configWin, "", "Button2")
  Sleep(50)
  ;Click startup
  _GUICtrlTab_ClickTab($hTab, 3)
  Sleep(50)
  ;Disable all
  ControlClick($configWin, "", "Button2")
  Sleep(50)
  ; Apply
  ControlClick($configWin, "", "Button13")
  Sleep(50)

  ControlClick($configWin, "", "Button11")
  Sleep(50)
  $configWin = WinGetHandle("System Configuration")
  ControlClick($configWin, "", "Button3")
  Sleep(50)

  ;Click Exit without restart
  WinWait("System Configuration", "You may need to restart", 3)
  ControlClick($configWin, "", "Button3")

EndIf
EndFunc
Func RevertToNormalStartup()
MsconfigStart()

;Click General tab
_GUICtrlTab_ClickTab($hTab, 0)

WinWait($configWin, "Startup selection")

;Click Normal startup
ControlClick($configWin, "", "Button2")
Sleep(100)

;Click Apply
ControlClick($configWin, "", "&Apply")
Sleep(500)

;Click OK
ControlClick($configWin, "", "OK")
Sleep(500)

;WinClose($configWin, "")

;Click Exit without restart
WinWait("System Configuration", "You may need to restart", 3)
ControlClick($configWin, "", "Button3")
EndFunc
Func MsconfigStart()
DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)
ShellExecute("C:\Windows\System32\msconfig.exe", -2)
WinWait("System Configuration")
Sleep(500)
Global $configWin = WinGetHandle("System Configuration")
Global $hTab = ControlGetHandle($configWin, "", "SysTabControl321")
EndFunc

Share this post


Link to post
Share on other sites



How do I get the state of a SysListView32 control? This is the incorrect syntax that I currently have:

$listview = "SysListView321"
$itemState = BitAnd(GUICtrlRead($listview[$i]),$GUI_CHECKED)

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  
Followers 0