Sign in to follow this  
Followers 0
anixon

AU3RECORDER

2 posts in this topic

#1 ·  Posted (edited)

I have been trying to record a script that will add a logoff script using GPEDIT.MSC but for some reason halts on the Logon, Logoff selection. If you Click on Logoff the script continues to run and completes the task. I would like it to complete the task without the halt. The following is the code:

CODE
#region --- ScriptWriter generated code Start ---

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

Send("{LWINDOWN}{LWINUP}")

WinWait("Start Menu","All &Programs")

If Not WinActive("Start Menu","All &Programs") Then WinActivate("Start Menu","All &Programs")

WinWaitActive("Start Menu","All &Programs")

Send("r")

WinWait("Run","Type the name of a p")

If Not WinActive("Run","Type the name of a p") Then WinActivate("Run","Type the name of a p")

WinWaitActive("Run","Type the name of a p")

Send("gpedit.msc{ENTER}")

WinWait("Group Policy","Local Computer Polic")

If Not WinActive("Group Policy","Local Computer Polic") Then WinActivate("Group Policy","Local Computer Polic")

WinWaitActive("Group Policy","Local Computer Polic")

Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}")

;************************** FAILS HERE **********************************************************

MouseClick("left",433,166,2)

WinWait("Logoff Properties","Logoff Scripts for L")

If Not WinActive("Logoff Properties","Logoff Scripts for L") Then WinActivate("Logoff Properties","Logoff Scripts for L")

WinWaitActive("Logoff Properties","Logoff Scripts for L")

Send("{TAB}{ENTER}")

WinWait("Add a Script","Script &Parameters:")

If Not WinActive("Add a Script","Script &Parameters:") Then WinActivate("Add a Script","Script &Parameters:")

WinWaitActive("Add a Script","Script &Parameters:")

Send("test.exe{ENTER}")

WinWait("Logoff Properties","Logoff Scripts for L")

If Not WinActive("Logoff Properties","Logoff Scripts for L") Then WinActivate("Logoff Properties","Logoff Scripts for L")

WinWaitActive("Logoff Properties","Logoff Scripts for L")

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}{ENTER}")

WinWait("Group Policy","Local Computer Polic")

If Not WinActive("Group Policy","Local Computer Polic") Then WinActivate("Group Policy","Local Computer Polic")

WinWaitActive("Group Policy","Local Computer Polic")

Send("{ALTDOWN}{F4}{ALTUP}")

#endregion --- ScriptWriter generated code End ---

Assistance is always appreciated

Ant..

Edit

This code works but I was trying to avoid the mouseclicks given that I have no control over where the Windows gpedit.msc screen will be positioned over different PC's

I have tried different combinations of TAB and F6 to replay the mouseclicks all to no avail.

Help would be appreciated

CODE
#region --- ScriptWriter generated code Start ---

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

Send("{LWINDOWN}{LWINUP}")

WinWait("Start Menu","")

If Not WinActive("Start Menu","") Then WinActivate("Start Menu","")

WinWaitActive("Start Menu","")

Send("r")

WinWait("Run","")

If Not WinActive("Run","") Then WinActivate("Run","")

WinWaitActive("Run","")

Send("gpedit.msc{ENTER}")

WinWait("Group Policy","")

If Not WinActive("Group Policy","") Then WinActivate("Group Policy","")

WinWaitActive("Group Policy","")

**********************

Replacement for this code:

**********************

Mouseclick("left",99,199,2)

Mouseclick("left",121,218,2)

Mouseclick("left",426,168,2)

**********************

WinWait("Logoff Properties","")

If Not WinActive("Logoff Properties","") Then WinActivate("Logoff Properties","")

WinWaitActive("Logoff Properties","")

Send("{TAB}{ENTER}")

WinWait("Add a Script","")

If Not WinActive("Add a Script","") Then WinActivate("Add a Script","")

WinWaitActive("Add a Script","")

Send("test3.exe{ENTER}")

WinWait("Logoff Properties","")

If Not WinActive("Logoff Properties","") Then WinActivate("Logoff Properties","")

WinWaitActive("Logoff Properties","")

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}{ENTER}")

WinWait("Group Policy","")

If Not WinActive("Group Policy","") Then WinActivate("Group Policy","")

WinWaitActive("Group Policy","")

Send("{ALTDOWN}{F4}{ALTUP}")

#endregion --- ScriptWriter generated code End ---

Spent a better part of today these routines which appear to do the job. Comments would be appreciated if there is a better way of achieve the same outcome

Cheers

Ant

Edit

I edited the code so that will process where an existing logoff script exists.

CODE
;Part of a software installation process:

;Disable Task Manager (Ctrl+Alt+Del)

;RegWrite("HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\POLICIES\SYSTEM", "DisableTaskMgr", "REG_DWORD", "1")

;Enable Task Manager (position this in your code when you want to give the user access to Ctrl+Alt+Del)

RegWrite("HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\POLICIES\SYSTEM", "DisableTaskMgr", "REG_DWORD", "0")

;Load your program to run on startup

If Not(RegRead("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "mystartup.exe")) Then

RegWrite("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "mystartup.exe", "REG_SZ", @Scriptdir & "\mystartup.exe")

EndIF

FileCopy(@ScriptDir & "\mylogofscript.exe", "C:\WINDOWS\System32\GroupPolicy\User\Scripts\Logoff\", 1)

;Load Logoff Script

global $mls = 0

Global $file[12] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]

For $i = 0 To UBound($file) - 1

$mls = $mls + 1

_runLogonScriptCHK($file[$i])

Next

Func _runLogonScriptCHK($filename)

$read = (regread("hkcu\software\policies\microsoft\windows\system\scripts\logoff\" & $filename & "\", "script"))

If $read = "" Then

mylogoffscript()

Exit

ElseIf $read = "mylogofscript.exe" Then

myexit()

Elseif $read <> "mylogofscript.exe" Then

return(0)

EndIf

EndFunc ;==>_runPROG

Func mylogoffscript()

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

Send("{LWINDOWN}{LWINUP}")

WinWait("Start Menu","")

If Not WinActive("Start Menu","") Then WinActivate("Start Menu","")

WinWaitActive("Start Menu","")

Send("r")

WinWait("Run","")

If Not WinActive("Run","") Then WinActivate("Run","")

WinWaitActive("Run","")

Send("gpedit.msc{ENTER}")

WinMove("Group Policy", "", 0, 0, 200, 200)

WinWait("Group Policy","")

If Not WinActive("Group Policy","") Then WinActivate("Group Policy","")

WinWaitActive("Group Policy","")

WinMove("Group Policy", "", 150, 150,800,600)

Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}")

WinWaitActive("Group Policy","Scripts (Logon/Logoff)")

Send("{TAB}{DOWN}{ENTER}")

WinWait("Logoff Properties","")

If Not WinActive("Logoff Properties","") Then WinActivate("Logoff Properties","")

WinWaitActive("Logoff Properties","")

If $mls < 3 Then

Send("{TAB}{ENTER}")

Else

Send("{TAB}{TAB}{ENTER}")

EndIf

WinWait("Add a Script","")

If Not WinActive("Add a Script","") Then WinActivate("Add a Script","")

WinWaitActive("Add a Script","")

Send("mylogofscript.exe{ENTER}")

WinWait("Logoff Properties","")

If Not WinActive("Logoff Properties","") Then WinActivate("Logoff Properties","")

WinWaitActive("Logoff Properties","")

If $mls = 1 Then

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}")

Sleep(100)

Send("{ENTER}")

Else

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}")

Sleep(100)

Send("{ENTER}")

EndIf

WinWait("Group Policy","Scripts (Logon/Logoff)")

If Not WinActive("Group Policy","Scripts (Logon/Logoff)") Then WinActivate("Group Policy","Scripts (Logon/Logoff)")

WinWaitActive("Group Policy","Scripts (Logon/Logoff)")

Send("{ALTDOWN}{F4}{ALTUP}")

myexit()

EndFunc

Func myexit()

Exit

EndFunc

Edited by anixon

Share this post


Link to post
Share on other sites



Instead Send() use commands for direct manipulation with controls ControlSend() ControlClick(), something like this:

See:

http://www.autoitscript.com/forum/index.ph...st&p=298946

#include <A3LListView.au3>
#include <A3LTreeView.au3>

Opt("MustDeclareVars", 1)

Global $hTree, $hNode, $hList, $iIndex

; Open "Local Security Settings"
ShellExecute("secpol.msc")
_Lib_WinWaitActive("Local Security Settings")

; Find the TreeView control
$hTree = ControlGetHandle("Local Security Settings", "", "SysTreeView321")
if @Error then _Lib_ShowError("Unable to find TreeView")

; Find "User Rights Assignment" node
$hNode = _TreeView_FindNodeEx($hTree, "Security Settings|Local Policies|User Rights Assignment")
if $hNode = 0 then _Lib_ShowError("Unable to find User Rights Assignment")
_TreeView_Click($hTree, $hNode)
Sleep(1000)

; Find the ListView control
$hList = ControlGetHandle("Local Security Settings", "", "SysListView321")
if @Error then _Lib_ShowError("Unable to find ListView")

; Select "Act as part of the operating system"
$iIndex = _ListView_FindInText($hList, "Act as part of the operating system")
if $iIndex = -1 then _Lib_ShowError("Unable to find ListView item")

; Open up item
_ListView_ClickItem($hList, $iIndex, "left", False, 2)
_Lib_WinWaitActive("Act as part of the operating system")

; Click on "Add User or Group"
ControlClick("Act as part of the operating system", "", "Add &User or Group...")
_Lib_WinWaitActive("Select Users or Groups")

; Add a user
ControlSend("Select Users or Groups", "", "RichEdit20W1", "YourUserName")
ControlClick("Select Users or Groups", "", "OK")

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