Jump to content

REGEDIT - SEND("{ENTER}") Expression


Recommended Posts

Hey Girls & Guys

I tried to create an scipt part (like the fist part) that includes RegWrite commands and Send Commands to write a registry key (just one).

After part 1 would come part 2/3/4/5 (all just install-parts with RUN that i already wrote)

Can someone help me, what is wrong in my Part1 script?

Here the script:

; Folder: 01. Enable\Optimierung.reg    -    Registry key add part

#RequireAdmin        ; Admin priviledge
$regFile = @TempDir & '\01. Enable\Optimierung.reg'
RunWait("Regedit " & $regFile)

; Key check
RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLinkedConnections")
; Key write
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLinkedConnections", "REG_DWORD", "00000001")

Sleep(4000)

If WinActive("Registrierungs-Editor", "") Then
    Send("{ENTER}")
EndIf

Link to comment
Share on other sites

I think your problem comes from the RunWait, although you did not say what is your problem.

RunWait will wait until the program you are running (in your case regedit) is completed before continuing the script.  What you really want is to use Run or ShellExecute (in your case I would use ShellExecute).

Something like this should work :

#RequireAdmin
#include <Constants.au3>

$regFile = "Test.reg " ; @TempDir & '\01. Enable\Optimierung.reg'
ShellExecute ($regFile)
Local $hWnd = WinWait ("[CLASS:#32770]")
ControlSend ($hWnd, "", "", "{ENTER}")
Sleep (300)
$hWnd = WinWait ("[CLASS:#32770]")
ControlSend ($hWnd, "", "", "{ENTER}")

; Key check
Local $sReg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLinkedConnections")
MsgBox ($MB_SYSTEMMODAL,"",$sReg)
; Key write
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLinkedConnections", "REG_DWORD", 1)
If @error Then MsgBox ($MB_SYSTEMMODAL,"Error",@error)

Only thing left for you is to add more error handling.  I only add one at the end.

I do not fully understand why you are mixing the execution of .reg file with RegWrite function.  My advice is to use only RegWrite and drop the .reg files.

And when you post code, please use this tool.

Edited by Nine
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...