Modify

Opened 17 years ago

Closed 17 years ago

#947 closed Bug (No Bug)

RegRead fails for the first try reading a key

Reported by: funkey Owned by: Valik
Milestone: Component: AutoIt
Version: 3.3.0.0 Severity: None
Keywords: RegRead Cc:

Description

When I change the key for example from 'DeviceConnect' to 'DeviceFail' then I get an error from RegRead (only) for the first time. You can see it at the Console. I use Windows XP SP2 and Autoit V3.3.0.0

_PlayDefaultSystemSound('DeviceConnect', 1)

; #FUNCTION# ====================================================================================================================
; Name...........:    _PlayDefaultSystemSound()
; Description ...:    Plays a Default System Sound
; Syntax.........:    _PlayDefaultSystemSound($sSoundName, $iWait = 0)
; Parameters ....:    $sSoundName                - Name des SystemSound's
;                    | Default                   - Standardton Warnsignal / Default Beep
;                    | CriticalBatteryAlarm      - Alarm bei kritischem Batteriestand / when battery is critical
;                    | DeviceConnect            - Geräteanschluß / when a device is connect
;                    | DeviceDisconnect          - Gerätetrennung / when a device is disconnect
;                    | DeviceFail                - Geräteanschluß fehlgeschlagen / when a deviceconnect is fail
;                    | LowBatteryAlarm           - Alarm bei niedrigem Batteriestand / when battery is low
;                    | MailBeep                  - Posteingangsbenachrichtigung / when email is received
;                    | SystemAsterisk            - Stern / Asterisk
;                    | SystemExclamation         - Hinweis / when windows shows a warning
;                    | SystemExit                - Windows beenden / when Windows shuts down
;                    | SystemHand                - Kritischer Abbruch / when a critical stop occurs
;                    | SystemNotification        - Sprechblase / when a critical stop occurs
;                    | SystemStart               - Windows starten / when Windows starts up
;                    | WindowsLogoff             - beim Windows abmelden / when logging off Windows
;                    | WindowsLogon              - beim Windows anmelden / when logging on Windows
;                    | EmptyRecycleBin           - Löschen des Papierkorbs / when recycle bin is emptied
;                    | Navigating                - Browser Klick / navigating in browser

;                     $iWait                     - Wait until SoundPlay ends? (0 = no / 1 = yes)
; Return values .:    -----
; Author ........:    funkey (AutoIt.de)
; ===============================================================================================================================

Func _PlayDefaultSystemSound($sSoundName, $iWait = 0)
    ; funkey
    Local $sKey = 'HKEY_USERS\.Default\AppEvents\Schemes\Apps\.Default'
    If $sSoundName = 'EmptyRecycleBin' Or $sSoundName = 'Navigating' Then $sKey = 'HKEY_USERS\.Default\AppEvents\Schemes\Apps\Explorer'
    ConsoleWrite(RegRead($sKey &'\' & $sSoundName & '\' & '\.Default', '')&@CRLF&@error&@CRLF)    ;Output to Console
    Local $sFile = StringReplace(RegRead($sKey &'\' & $sSoundName & '\' & '\.Default', ''), '%SystemRoot%', @WindowsDir)
    If $sFile = "" Then
        SoundPlay(StringReplace(RegRead($sKey &'\.Default\.Default', ''), '%SystemRoot%', @WindowsDir), $iWait)
    Else
        SoundPlay($sFile, $iWait)
    EndIf
EndFunc   ;==>_PlaySystemSound

Attachments (0)

Change History (7)

comment:1 by anonymous, 17 years ago

check your registry, it worked for me on the first try (and other tries after that).

comment:2 by funkey, 17 years ago

The registry is fine, the keys exist. I checked it on several computer and other users from Autoit.de have the same problem.
For the first time RegRead fails for each key it reads, then it works fine until you logoff Windows or restart your PC.

Another example for testing:

Local $aSounds[15] = ['.Default', _
			'CriticalBatteryAlarm', _
			'DeviceConnect', _
			'DeviceDisconnect', _
			'DeviceFail', _
			'LowBatteryAlarm', _
			'MailBeep', _
			'SystemAsterisk', _
			'SystemExclamation', _
			'SystemExit', _
			'SystemHand', _
			'SystemNotification', _
			'SystemStart', _
			'WindowsLogoff', _
			'WindowsLogon']

For $i = 0 To UBound($aSounds) -1
	ConsoleWrite(RegRead('HKEY_USERS\.Default\AppEvents\Schemes\Apps\.Default\' & $aSounds[$i] & '\' & '\.Default', '')&@CRLF&@error&@CRLF)
Next

comment:3 by Valik, 17 years ago

Very strange. I tried the script and the first run returned empty strings with @error set to 1. All subsequent attempts worked. In short, I can reproduce the issue on Windows XP SP3.

comment:4 by J-Paul Mesnage, 17 years ago

Resolution: No Bug
Status: newclosed

I don"t know why XP behave this way but you get an extra '\'
If you remove it everything is OK

	ConsoleWrite(RegRead('HKEY_USERS\.Default\AppEvents\Schemes\Apps\.Default\' & $aSounds[$i] & '\.Default', '')&@CRLF&@error&@CRLF)

comment:5 by Valik, 17 years ago

Resolution: No Bug
Status: closedreopened

I said that I could reproduce this bug so you do not need to be closing it.

If the extra \ actually mattered, it would always fail. It doesn't always fail, it fails in a very strange manner. Give me some time to look into this further, please.

comment:6 by J-Paul Mesnage, 17 years ago

Owner: set to Valik
Status: reopenedassigned

comment:7 by Valik, 17 years ago

Resolution: No Bug
Status: assignedclosed

I'm closing this as no bug. The error returned is ERROR_INVALID_PARAMETER (The parameter is incorrect). The error is accurate because of the extra "\" in the key name. I have a theory as to why it works sometimes and doesn't work other times but it's rather technical and pretty much irrelevant since it's not a bug we can fix. If there is a bug here, it's in the Windows API for not rejecting the key every time.

Modify Ticket

Action
as closed The owner will remain Valik.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.