Modify

Opened 16 years ago

Closed 16 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 Changed 16 years ago by anonymous

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

comment:2 Changed 16 years ago by funkey

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 Changed 16 years ago by Valik

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 Changed 16 years ago by Jpm

  • Resolution set to No Bug
  • Status changed from new to closed

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 Changed 16 years ago by Valik

  • Resolution No Bug deleted
  • Status changed from closed to reopened

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 Changed 16 years ago by Jpm

  • Owner set to Valik
  • Status changed from reopened to assigned

comment:7 Changed 16 years ago by Valik

  • Resolution set to No Bug
  • Status changed from assigned to closed

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.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Valik.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.