Что нового

[Элементы GUI] Скрытые кнопки - GUICtrlCreateButton

Blaze

Новичок
Сообщения
2
Репутация
0
Добрый вечер.

Написал программу для активации и дезактивации UAC (контроля учетных записей пользователей), для одного англоязычного проекта.

Проблема заключается в скрытых кнопках - видно, только при наведении курсора в нужные области формы GUICreate.
Как сделать так, чтобы кнопки GUICtrlCreateButton были не скрыты и выполняли свои назначенные функции?

Исходный код программы:
Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("TrayIconHide", 1)

GUICreate("Deactivate/Activate UAC", 400, 370, -1, -1)
GUISetBkColor(0xC8C8C8)
$Button1 = GUICtrlCreateButton("Deactivate UAC", 80, 300, 105, 57)
$Button2 = GUICtrlCreateButton("Activate UAC", 230, 300, 105, 57)
GUICtrlCreateLabel("This program will temporarily disable Windows User Account Control (UAC).",  0, 10, 400, 200, 0x01)
GUICtrlCreateLabel("This is necessary in order to modify the Master Boot Record of your flash drive, and it will temporarily put your computer at risk.",  0, 60, 400, 200, 0x01)
GUICtrlCreateLabel("Note!",  0, 120, 400, 200, 0x01)
GUICtrlCreateLabel("If you are running the installer from Windows Vista or Windows 7, you must disable the UAC. To do this, click on the “Deactivate UAC” button, and UAC will be deactivated and your computer will reboot to apply these changes.",  0, 150, 400, 200, 0x01)
GUICtrlCreateLabel("When you are done installing Porteus on your flash drive, you can reactive UAC by running this program again, pressing the “Activate UAC” button, and your computer will reboot.",  0, 230, 400, 200, 0x01)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
		Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button1
		Run (@SystemDir & "\cmd.exe")
		Sleep(1000)
		Send (@SystemDir & "\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f{Enter}")
		Sleep(1000)
		Send (@SystemDir & "\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f{Enter}")
		Sleep(1000)
		Send (@SystemDir & "\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v PromptOnSecureDesktop /t REG_DWORD /d 0 /f{Enter}")
		Case $Button2
		Run (@SystemDir & "\cmd.exe")
		Sleep(1000)
		Send (@SystemDir & "\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 1 /f{Enter}")
		Sleep(1000)
		Send (@SystemDir & "\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 2 /f{Enter}")
		Sleep(1000)
		Send (@SystemDir & "\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v PromptOnSecureDesktop /t REG_DWORD /d 1 /f{Enter}")
    EndSwitch
WEnd


Например, если кнопки
Код:
$Button1 = GUICtrlCreateButton("Deactivate UAC", 80, 300, 105, 57)
$Button2 = GUICtrlCreateButton("Activate UAC", 230, 300, 105, 57)
поместить перед
Код:
GUISetState(@SW_SHOW)
то они не скрыты, но выполнить заложенные в них функции нельзя, так как они не активны.
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Код:
...

GUICreate("Deactivate/Activate UAC", 400, 370, -1, -1)
GUISetBkColor(0xC8C8C8)
$Button1 = GUICtrlCreateButton("Deactivate UAC", 80, 300, 105, 57)
$Button2 = GUICtrlCreateButton("Activate UAC", 230, 300, 105, 57)
GUICtrlCreateLabel("This program will temporarily disable Windows User Account Control (UAC).",  0, 10, 400, 50, 0x01)
GUICtrlCreateLabel("This is necessary in order to modify the Master Boot Record of your flash drive, and it will temporarily put your computer at risk.",  0, 60, 400, 50, 0x01)
GUICtrlCreateLabel("Note!",  0, 120, 400, 50, 0x01)
GUICtrlCreateLabel("If you are running the installer from Windows Vista or Windows 7, you must disable the UAC. To do this, click on the “Deactivate UAC” button, and UAC will be deactivated and your computer will reboot to apply these changes.",  0, 150, 400, 50, 0x01)
GUICtrlCreateLabel("When you are done installing Porteus on your flash drive, you can reactive UAC by running this program again, pressing the “Activate UAC” button, and your computer will reboot.",  0, 230, 400, 50, 0x01)
GUISetState(@SW_SHOW)

....



Добавлено:
Сообщение автоматически объединено:

Высота Label'ов перекрывала кнопки, я только поправил 200 на 50.


Добавлено:
Сообщение автоматически объединено:

P.S
А зачем вызывать Cmd.exe и отсылать в него команды добавления в реестр, проще запустить сразу эти команды через @ComSpec, ну или ещё проще использовать RegWrite.


Добавлено:
Сообщение автоматически объединено:

Вот так:

Код:
While 1
    $nMsg = GUIGetMsg()
	
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button1, $Button2
			$iValue = 0
			If $nMsg = $Button2 Then $iValue = 1
			
			RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLUA", "REG_DWORD", $iValue)
			RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "ConsentPromptBehaviorAdmin", "REG_DWORD", $iValue)
			RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "PromptOnSecureDesktop", "REG_DWORD", $iValue)
    EndSwitch
WEnd
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
{TopicSolvedInfo}
 
Верх