News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Cannot create file that already exists.

Started by Magnum, December 04, 2011, 08:07:45 PM

Previous topic - Next topic

Magnum

This says, "Cannot create file that already exists."


.386
.model flat, stdcall
option casemap :none   

include     \masm32\include\windows.inc
include     \masm32\include\user32.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\advapi32.inc
include     \masm32\include\shlwapi.inc

includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\advapi32.lib
includelib  \masm32\lib\shlwapi.lib

.data

Icon_streams  db  "\Software\Microsoft\Windows\CurrentVersion\Explorer\TrayNotify\IconStreams",0
Past_stream   db  "\Software\Microsoft\Windows\CurrentVersion\Explorer\TrayNotify\PastIconsStream",0

.data?

ErrorString DB 256 DUP (?)

.code

start:

invoke SHDeleteKey,HKEY_CURRENT_USER,ADDR Icon_streams
invoke SHDeleteKey,HKEY_CURRENT_USER,ADDR Past_stream

invoke GetLastError

invoke FormatMessage,FORMAT_MESSAGE_FROM_SYSTEM, 0, eax, 0, offset ErrorString, SIZEOF ErrorString-1, 0
invoke MessageBox, 0, offset ErrorString, 0, 0

invoke ExitProcess,NULL

end start

Have a great day,
                         Andy

bomz

Quote.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
include \MASM32\INCLUDE\advapi32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib
includelib \MASM32\LIB\advapi32.lib

.data
szREGSZ db "REG_SZ",0
szTestKey db "Test Key",0
szOK db "Success.",0
szError db "Key not exist.",0

.data?
hKey dd ?
lpdwDisp dd ?

.code
start:

invoke RegOpenKeyEx,HKEY_CURRENT_USER,ADDR szTestKey,0,KEY_WRITE or KEY_READ,ADDR hKey
.if eax==ERROR_SUCCESS
invoke RegDeleteKey,HKEY_CURRENT_USER,ADDR szTestKey
.if eax==ERROR_SUCCESS
invoke MessageBox,0,ADDR szOK,ADDR szTestKey,MB_OK + MB_ICONASTERISK
.else
invoke MessageBox,0,0,0,0
.endif
invoke RegCloseKey,hKey
.else
invoke MessageBox,0,ADDR szError,0,0
.endif
exit:
invoke ExitProcess,0 ;
end start

Quote.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
include \MASM32\INCLUDE\advapi32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib
includelib \MASM32\LIB\advapi32.lib

.data
szREGSZ db "REG_SZ",0
szTestKey db "Test Key",0
szOK db "Key create or already exist.",0

.data?
hKey dd ?
lpdwDisp dd ?

.code
start:

invoke RegCreateKeyEx,HKEY_CURRENT_USER,ADDR szTestKey,0,ADDR szREGSZ,0,KEY_WRITE or KEY_READ,0,ADDR hKey,lpdwDisp

.if eax==ERROR_SUCCESS
invoke MessageBox,0,ADDR szOK,ADDR szTestKey,MB_OK + MB_ICONASTERISK
invoke RegCloseKey,hKey
.else
invoke MessageBox,0,0,ADDR szTestKey,0
.endif

invoke ExitProcess,0
end start

MichaelW

Andy,

Since not all functions will clear the last-error code value on success, you need to check the return value from SHDeleteKey to know if an error occurred (a return value of 0 = ERROR_SUCCESS).

eschew obfuscation

Magnum

Have a great day,
                         Andy

dedndave

QuoteERROR_BAD_PATHNAME
161 (0xA1)

i assume the key you are trying to delete is empty
at any rate - the error indicates that the key does not exist
check your strings   :U

another possibility - if you are running 64-bit OS
is that the key is virualized under wow64

Magnum

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\TrayNotify]
"BalloonTip"=dword:00000005
"PastIconsStream"

Past_stream   db  "Software\Microsoft\Windows\CurrentVersion\Explorer\TrayNotify\PastIconsStream",0

I have a VB script that deletes the key and then it stops and restarts explorer.

Maybe that is the problem.
Have a great day,
                         Andy

Gunner

remove the first backslash from the paths and it should work!  They should be:
Icon_streams  db  "Software\Microsoft\Windows\CurrentVersion\Explorer\TrayNotify\IconStreams",0
Past_stream   db  "Software\Microsoft\Windows\CurrentVersion\Explorer\TrayNotify\PastIconsStream",0

~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Magnum

Have a great day,
                         Andy