How to write registry after log in windows with mfc?
-
Dear all: I implement a application, when I log in windows, the application will auto start, and write registry in HKEY_CURRENT_USER, SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run. The context of registry is a wav file path. I put the wav file and the application in the same folder. My code show as below:
HKEY hKey = HKEY_CURRENT_USER;
TCHAR filePath[MAX_PATH];
TCHAR dirPath[MAX_PATH];GetCurrentDirectory(MAX_PATH, dirPath);
StringTruncate(filePath, dirPath, "\\Default.wav");
//For ex: filePath may equal C:\abc\123\Default.wav, if my folder path
//is C:\abc\123.WriteReg(hKey, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"), _T("Sound"), filePath);
My question is: when I log in windows, the registry value always equal to C:\Windows\system32\Default.wav, Not my folder path. How can I write the right wav file path after windows log in? Thanks for your help, Victor.
-
Dear all: I implement a application, when I log in windows, the application will auto start, and write registry in HKEY_CURRENT_USER, SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run. The context of registry is a wav file path. I put the wav file and the application in the same folder. My code show as below:
HKEY hKey = HKEY_CURRENT_USER;
TCHAR filePath[MAX_PATH];
TCHAR dirPath[MAX_PATH];GetCurrentDirectory(MAX_PATH, dirPath);
StringTruncate(filePath, dirPath, "\\Default.wav");
//For ex: filePath may equal C:\abc\123\Default.wav, if my folder path
//is C:\abc\123.WriteReg(hKey, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"), _T("Sound"), filePath);
My question is: when I log in windows, the registry value always equal to C:\Windows\system32\Default.wav, Not my folder path. How can I write the right wav file path after windows log in? Thanks for your help, Victor.
Did you check that writing to the registry was successful?
-
Did you check that writing to the registry was successful?
Dear Jochen: I use the same code, but different condition. condition 1: windows run stable, it write the registry success with my folder. condition 2: after log in windows, it write the C:\Windows\system32 path. Thanks for your help, Victor.
-
Dear all: I implement a application, when I log in windows, the application will auto start, and write registry in HKEY_CURRENT_USER, SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run. The context of registry is a wav file path. I put the wav file and the application in the same folder. My code show as below:
HKEY hKey = HKEY_CURRENT_USER;
TCHAR filePath[MAX_PATH];
TCHAR dirPath[MAX_PATH];GetCurrentDirectory(MAX_PATH, dirPath);
StringTruncate(filePath, dirPath, "\\Default.wav");
//For ex: filePath may equal C:\abc\123\Default.wav, if my folder path
//is C:\abc\123.WriteReg(hKey, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"), _T("Sound"), filePath);
My question is: when I log in windows, the registry value always equal to C:\Windows\system32\Default.wav, Not my folder path. How can I write the right wav file path after windows log in? Thanks for your help, Victor.
What is the value of
filePath
at the time of writing? Hint: it's not what you think it is."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
What is the value of
filePath
at the time of writing? Hint: it's not what you think it is."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Dear David: I know the filePath equal to C:\Windows\system32. The value of registry which I write is different between log in windows and run windows stable. How can I write the same value in log in windows?
-
Dear David: I know the filePath equal to C:\Windows\system32. The value of registry which I write is different between log in windows and run windows stable. How can I write the same value in log in windows?
cedricvictor wrote:
I know the filePath equal to C:\Windows\system32.
So then why continue to use it?
cedricvictor wrote:
The value of registry which I write is different between log in windows and run windows stable.
Which has nothing to do with anything.
cedricvictor wrote:
How can I write the same value in log in windows?
Why not just use:
TCHAR filePath[MAX_PATH] = _T("C:\\abc\\123\\Default.wav");
WriteReg(hKey, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), _T("Sound"), filePath);All that said, I suspect you are wanting to use
::GetModuleFileName(NULL, ...)
instead."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
cedricvictor wrote:
I know the filePath equal to C:\Windows\system32.
So then why continue to use it?
cedricvictor wrote:
The value of registry which I write is different between log in windows and run windows stable.
Which has nothing to do with anything.
cedricvictor wrote:
How can I write the same value in log in windows?
Why not just use:
TCHAR filePath[MAX_PATH] = _T("C:\\abc\\123\\Default.wav");
WriteReg(hKey, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), _T("Sound"), filePath);All that said, I suspect you are wanting to use
::GetModuleFileName(NULL, ...)
instead."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
It is right, Firstly, you should use ::GetModuleFileName(NULL, ...) to get the path of your application image, and then, get what you want by this path. If you set the path as const value, it's not convenient!
-
It is right, Firstly, you should use ::GetModuleFileName(NULL, ...) to get the path of your application image, and then, get what you want by this path. If you set the path as const value, it's not convenient!
I'm not sure why you replied to me with this (as opposed to cedricvictor), but thanks for the affirmation.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
I'm not sure why you replied to me with this (as opposed to cedricvictor), but thanks for the affirmation.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Sorry, I just agree with your opinions, so I can't help myself to reply you. :laugh: