Thread: RE: [Dev-C++] Flush or set valeu from a key of Registry.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Santiago P. C. <San...@yd...> - 2002-07-24 16:32:26
|
Hi,
To manage registry keys and values, you must first open a key and then
manage its values, SO...
You must have in mind that registry _KEYS_ and registry _VALUES_ are
different things!!!
(Take a look at the code bellow and check variables named: szKey and
szValueName)
Here you have a little C program that reads a DWORD value, increases it and
stores it again in the registry. Values are printed on the screen.
To handle a string you should modify a few values:
dwDataType must macht with REG_STRING,
dwDataSize must be high enough to store the retrieved value,
and few more...
Hope this helps!
Regards ,Santy
<CODE>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#define MAX_VALUE 256
// FUNTIONs DEFINITIONs
void OutputString(char* szInfoStr);
void OutputValue(DWORD dwValue, char* lpStr = NULL);
// FUNCTIONs IMPLEMENTATION
void OutputString(char* lpStr)
{
if (lpStr != NULL)
printf("%s\n",lpStr);
}
void OutputValue(DWORD dwValue, char* lpStr)
{
char szStr[256];
if (lpStr != NULL)
sprintf(szStr,"[%s] Value: %d",lpStr,(int)dwValue);
else
sprintf(szStr,"Value: %d",(int)dwValue);
OutputString(lpStr);
}
void ShowSystemErrorMsg(DWORD dwError)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM,
NULL, dwError,
(DWORD)MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, (DWORD) 0,
NULL);
OutputString((char*)lpMsgBuf);
LocalFree(lpMsgBuf);
}
int main(int argc, char *argv[])
{
char szKey[] = "Whatever\\Your\\Key\\Path\\Looks\\Like";
char szValueName[] = "MyValue";
UINT uValue = 0;
HKEY hRegKey = NULL;
DWORD dwError = 0;
DWORD dwDataType = 0; // type buffer
DWORD dwDataSize = sizeof(DWORD); // size of data buffer
LPBYTE lpByteData = NULL; // data buffer
// Try to open key
dwError = (DWORD) RegOpenKeyEx(HKEY_CURRENT_USER, (LPCTSTR)szKey, 0,
KEY_ALL_ACCESS, &hRegKey );
if (dwError == ERROR_SUCCESS)
{
lpByteData = (LPBYTE) LocalAlloc(LPTR,(UINT)dwDataSize);
if (lpByteData != NULL)
{
// Get current value
dwError = (DWORD)
RegQueryValueEx(hRegKey,(LPCTSTR)szValueName,NULL,
(LPDWORD)&dwDataType,lpByteData,(LPDWORD)&dwDataSize);
if ( (dwError == ERROR_SUCCESS)&&(dwDataType == REG_DWORD) )
{
// Output retrieved data
uValue = (UINT) (*lpByteData);
OutputValue(uValue,"Previous Value");
// Increase current cycle
uValue = (++uValue%MAX_VALUE);
OutputValue(uValue,"Increased Value");
// Store new value for MyValue at registry
dwError = RegSetValueEx(hRegKey,(LPCTSTR)szValueName, 0,
REG_DWORD, (BYTE*)&uValue, dwDataSize);
if ( (dwError != ERROR_SUCCESS))
{
OutputValue(dwError,"RegSetValueEx - dwError");
ShowSystemErrorMsg(dwError);
}
// Flush Data anyway
RegFlushKey(hRegKey);
}
// Free dynamic memory
LocalFree(lpByteData);
}
// Close RegistryKey
RegCloseKey(hRegKey);
}
else
ShowSystemErrorMsg(dwError);
return 0;
}
</CODE>
-----Original Message-----
From: we...@ha... [mailto:we...@ha...]
Sent: Saturday, February 23, 2002 10:01 PM
To: dev...@li...
Subject: [Dev-C++] Flush or set valeu from a key of Registry.
Hi,
I want to flush (delete) a string value from registry.
I tryed to set it to 0 of this mode:
#include <windows.h>
int main(int argc, char *argv[])
{
HKEY hKey;
DWORD dwDisposition;
unsigned char *szBuf = (unsigned char *)strdup("0");
if (RegSetValueEx(HKEY_CURRENT_USER,
"\\Software\\Microsoft\\Security\\say\\", 0, REG_SZ, szBuf,
strlen((char*)szBuf)) != ERROR_SUCCESS)
return 1;
RegCloseKey(hKey);
return 0;
}
But it didn't set the value of:
\\HKEY_CURRENT_USER\\Software\\Microsoft\\Security\\say to "0". It crate a
key \\Software\\Microsoft\\Security\\say in \\HKEY_CURRENT_USER . :P
How to do to is set this value ??
And how to for example delete a key \\Software\\Microsoft\\Security\\say\\
??
Can someone gave examples ?? :)
Thkz and Best Regards.
[ ]'s
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf _______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
--------------------------------------------------------------------------------------
This message and any files transmitted with it are confidential and intended solely
for the use of the individual or entity to whom they are addressed. No confidentiality
or privilege is waived or lost by any wrong transmission.
If you have received this message in error, please immediately destroy it and kindly
notify the sender by reply email.
You must not, directly or indirectly, use, disclose, distribute, print, or copy any
part of this message if you are not the intended recipient. Opinions, conclusions and
other information in this message that do not relate to the official business of
Ydilo Advanced Voice Solutions, S.A. shall be understood as neither given nor endorsed by it.
--------------------------------------------------------------------------------------
|
|
From: <we...@ha...> - 2002-07-24 19:46:51
|
Hi, I have 3 distinct doubts... and will write here... maybe someone can help me. ;) 1) Where can i get the list of API's of Windows with prototypes and examples of how to use or explication of each paramter of prototypes ?? :) (if possible to download it.:)) 2) I done a little code in C (for dos) that read a file binary and change a offset. The code compile and run perfectily. But when i create it under win32 application project project (C or C++) it gave me the error: The instruction at "0x004014b7" referenced memory at "0x026ec5bd". The memory could not be "written". Click on OK to terminate the program. And the some program (with the some code) work properly in a project od C (for 16 bits). Why this problem ?? A Bug in Dev-C++ ?? How to fix it ?? :) 3) How to use "format strings" with MessageBox ?? For example in normal i do: MessageBox(NULL, "File not found!!", "ERROR", MB_OK); Suppose that i want print "File name_of_file not found" suppose that the name_of_file is a vector. Example: char File[]="ProgTest"; I tryed of several ways like: MessageBox(NULL, "File %s not found!!", "ERROR", MB_OK,File); Or: MessageBox(NULL, "File %s not found!!",File, "ERROR", MB_OK); But it didn't work. It say that have much arguments to MessageBox. Then how to do it ?? Thkz... and Best Regards. [ ]'s |
|
From: Hongl L. <h....@ch...> - 2002-07-24 20:18:47
|
we...@ha... wrote: > Hi, > > I have 3 distinct doubts... and will write here... maybe someone can help > me. ;) > > 1) Where can i get the list of API's of Windows with prototypes and examples > of how to use or explication of each paramter of prototypes ?? :) (if > possible to download it.:)) > http://msdn.microsoft.com/ > 2) I done a little code in C (for dos) that read a file binary and change a > offset. The code compile and run perfectily. > But when i create it under win32 application project project (C or C++) it > gave me the error: > > The instruction at "0x004014b7" referenced memory at "0x026ec5bd". The > memory could not be "written". > > Click on OK to terminate the program. > > And the some program (with the some code) work properly in a project od C > (for 16 bits). Why this problem ?? A Bug in Dev-C++ ?? How to fix it ?? :) I can't give you any information without looking at your source code... > 3) How to use "format strings" with MessageBox ?? > > For example in normal i do: > > MessageBox(NULL, "File not found!!", "ERROR", MB_OK); Add -liberty to compiler options. #include <libiberty.h> char *msg; asprintf (&msg, "File %s not found!!", filename); MessageBox (0, msg, "ERROR", MB_OK); free (msg); |
|
From: Abhijit S. <mu...@gm...> - 2002-07-25 17:59:53
|
> I have 3 distinct doubts... and will write here... maybe someone can help > me. ;) > > 1) Where can i get the list of API's of Windows with prototypes and examples > of how to use or explication of each paramter of prototypes ?? :) (if > possible to download it.:)) Hongli mentioned MSDN, which is very good, but is online... this is an offline reference: http://www.borland.com/devsupport/borlandcpp/patches/BC52HLP1.ZIP > 3) How to use "format strings" with MessageBox ?? > > For example in normal i do: > > MessageBox(NULL, "File not found!!", "ERROR", MB_OK); > > Suppose that i want print "File name_of_file not found" suppose that the > name_of_file is a vector. Try this: char buf[appropriate_size]; wsprintf(buf, "This is my cool-dude message with args and stuff: %s %d", msg, some_num); MessageBox(NULL, buf, "Title", MB_OK); |
|
From: <we...@ha...> - 2002-10-03 13:46:40
|
Hi Guys, I'm with a big problem. I taked a virus that my antivirus didn't remove in all my network. :/ I discovered how to remove it. Basicly i will remove some keys from registry and files from windows. I'm thinking in write a remove programm in C. :) The problem is that when i try remove the program it gave a error saying: "This programm is in use" or something like it! :/ How to delete it ?? I think in unload the file and then delete it. It will work sure ?? How to do it ?? Someone have ideas ?? Or examples ?? Thkz a lot. Best Regards. [ ]'s |
|
From: Elizabeth B. <sog...@ya...> - 2002-10-03 14:10:47
|
<we...@ha...> writes: > Hi Guys, > > I'm with a big problem. I taked a virus that my antivirus didn't remove in > all my network. :/ > > I discovered how to remove it. Basicly i will remove some keys from > registry and files from windows. I'm thinking in write a remove programm in > C. :) > > The problem is that when i try remove the program it gave a error saying: > "This programm is in use" or something like it! :/ > > How to delete it ?? > > I think in unload the file and then delete it. It will work sure ?? How to > do it ?? Someone have ideas ?? Or examples ?? > > Thkz a lot. If the program is being run from win.ini or anything similar (such as on boot), you could remove the entry and install your own program to delete the virus-one. There is some kind of "Run Once" entry IIRC. Elizabeth |
|
From: <we...@ha...> - 2002-10-03 14:55:22
|
Hi, > If the program is being run from win.ini or anything similar (such as > on boot), you could remove the entry and install your own program to > delete the virus-one. There is some kind of "Run Once" entry > IIRC. Ok. it it's runned by RUN key. The problem is that if i unload i will need to restart the computer to delete de file! :/ Nobody know a way to unload a programm from memory and delete a file ? Thkz a lot. Best Regards. [ ]'s > > Elizabeth > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: <hj...@hj...> - 2002-10-03 16:37:01
|
> Nobody know a way to unload a programm from memory and delete a file ? If you boot Windows to [Safe Mode] by pressing F8 during Boot (depends on Windows OS you use) the program should not be loaded to memory. You can then delete the program. Also, you could boot to DOS Mode instead of Windows if you use Win 95 or 98 and delete it there via Command Prompt. You could also create a Bootdisk/Recovery Disk and boot with it instead of booting windows. You have to instruct bios to boot from your Floppy though. Again, from the Command Prompt you could then delete the File. Hope this helps. Best Wishes, Hans-Jörg |
|
From: Abhijit S. <mu...@gm...> - 2002-10-03 17:51:18
|
> Ok. it it's runned by RUN key. The problem is that if i unload i will need > to restart the computer to delete de file! :/ > > Nobody know a way to unload a programm from memory and delete a file ? How about Ctrl-Alt-Del, and then `END TASK'? One more thing, if it's a virus that messes with registry keys, there's a good chance that it infects EXEs when you run them directly by changing the `commandline' string for `exefile', so that the virus executable is called with the program name as an argument. ___________________________________________________________ Abhijit Shylanath E-mail: mu...@gm... || ibr...@bi... Web-site: http://mudeth.tripod.com/ |
|
From: <we...@ha...> - 2002-10-03 18:53:47
|
Hi Guys. Thkz for help. :) The programm can't be seen in CTRL+ALT+DEL. :) I use a programm to see hide programms and kill and it worked. Thkz a lot. Best Regards. [ ]'s |
|
From: <we...@ha...> - 2002-10-09 16:11:11
|
Hi Guys, I have two doubts. If someone can help me... or give-me a example in C. :) 1) I want to check for example if the directory c:\windows exist. How to do it ? 2) I want list all files that exist in directory c:\windows. How to do it ?? Thkz a lot. Best Regards. [ ]'s |
|
From: Carlos d. M. <cg...@wo...> - 2002-10-09 17:29:36
|
I haven't learned about it yet, but the solution is in dirent.h, do a sea= rch about it, there is a couple of pages I have not read yet which seems have= a good information about its use. we...@ha... escribi=F3: > Hi Guys, > > I have two doubts. If someone can help me... or give-me a example in C.= :) > > 1) I want to check for example if the directory c:\windows exist. How t= o do > it ? > > 2) I want list all files that exist in directory c:\windows. How to do = it ?? > > Thkz a lot. > > Best Regards. > > [ ]'s > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |
|
From: <we...@ha...> - 2002-10-09 20:30:11
|
Hi Guys,
Thkz a lot Carlos.
>I haven't learned about it yet, but the solution is in >dirent.h, do a
search ...
Ok, i searched. But all examples that i found didn't compile.
See the example:
#include <stdio.h>
#include <dirent.h>
int main (){
DIR *dirh;
struct dirent *dirp;
static char mydir[20] = "/etc";
if ((dirh = opendir(mydir)) == NULL){
perror("opendir");
return(0);
}
for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh)){
printf("Got dir entry: %s\n",dirp->d_name);
}
closedir(dirh);
}
When i compile i received this error:
[Linker error] undefined reference to `opendir'
[Linker error] undefined reference to `readdir'
[Linker error] undefined reference to `closedir'
What is wrong ?? How to solve it ??
Ahhh, the lib dirent.h appear that haven't a funciont to check if a
directory exist. Someone knwo other way to check ??
Thkz a lot.
Best Regards.
[ ]'s
> Hi Guys,
>
> I have two doubts. If someone can help me... or give-me a example in C. :)
>
> 1) I want to check for example if the directory c:\windows exist. How to
do
> it ?
>
> 2) I want list all files that exist in directory c:\windows. How to do it
??
>
> Thkz a lot.
>
> Best Regards.
>
> [ ]'s
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Matthias <mm...@ma...> - 2002-10-09 20:50:00
|
>>I haven't learned about it yet, but the solution is in >dirent.h, do a
> search ...
>
> Ok, i searched. But all examples that i found didn't compile.
Read up un 'stat', 'lstat' for information about files and directories
make sure that you link with libc.
Then read the paragraph about 'scandir' if you use Unix or
'FindFirstFile'/'FindNextFile' on Windows
----
int fl_filename_isdir(const char* n) {
struct stat s;
#ifdef WIN32
char fn[1024];
int length;
// This workaround brought to you by the fine folks at Microsoft!
// (read lots of sarcasm in that...)
length = strlen(n);
if (length < (int)(sizeof(fn) - 1)) {
if (length < 4 && isalpha(n[0]) && n[1] == ':' &&
(isdirsep(n[2]) || !n[2])) {
// Always use D:/ for drive letters
fn[0] = n[0];
strcpy(fn + 1, ":/");
n = fn;
} else if (length > 0 && isdirsep(n[length - 1])) {
// Strip trailing slash from name...
length --;
memcpy(fn, n, length);
fn[length] = '\0';
n = fn;
}
}
#endif
return !stat(n, &s) && (s.st_mode&0170000)==0040000;
}
|
|
From: <we...@ha...> - 2002-10-10 12:11:50
|
Hi Guys,
Thkz Matthias.
I had test the code that u sent:
#include <stdio.h>
#include <dirent.h>
int fl_filename_isdir(const char* n);
int main(){
fl_filename_isdir("c:\\winnt");
return(0);
}
int fl_filename_isdir(const char* n) {
struct stat s;
#ifdef WIN32
char fn[1024];
int length;
// This workaround brought to you by the fine folks at Microsoft!
// (read lots of sarcasm in that...)
length = strlen(n);
if (length < (int)(sizeof(fn) - 1)) {
if (length < 4 && isalpha(n[0]) && n[1] == ':' &&
(isdirsep(n[2]) || !n[2])) {
// Always use D:/ for drive letters
fn[0] = n[0];
strcpy(fn + 1, ":/");
n = fn;
} else if (length > 0 && isdirsep(n[length - 1])) {
// Strip trailing slash from name...
length --;
memcpy(fn, n, length);
fn[length] = '\0';
n = fn;
}
}
#endif
return !stat(n, &s) && (s.st_mode&0170000)==0040000;
}
But it gave-me errors:
Executing g++.exe...
g++.exe "C:\tmp\test.cpp" -o
C:\tmp\test.exe" -s -I"E:\dev-c++\Dev-Cpp\include" -I"E:\dev-c++\Dev-Cpp
\include\g++-3" -I"E:\dev-c++\Dev-Cpp\include" -L"E:\dev-c++\Dev-Cpp\lib"
C:\tmp\test.cpp: In function `int fl_filename_isdir(const char *)':
C:\tmp\test.cpp:15: aggregate `struct stat s' has incomplete type and cannot
be initialized
C:\tmp\test.cpp:24: implicit declaration of function `int isalpha(...)'
C:\tmp\test.cpp:25: implicit declaration of function `int isdirsep(...)'
C:\tmp\test.cpp:40: type `stat' is not yet defined
Execution terminated
This stat and this code work under windows ??
I'm under windows. :)
Thkz a lot.
Best Regards.
[ ]'s
|
|
From: matthias <mm...@ma...> - 2002-10-10 16:36:09
|
we...@ha... wrote: > Hi Guys, > > Thkz Matthias. > > I had test the code that u sent: > > This stat and this code work under windows ?? Yes it should - at least it does here. You must also include <sys/types.h>, <sys/stat.h> and <ctype.h> Or just use FLTK for you whole project ;-) |