Author | Message | Time |
---|---|---|
FuzZ | Heh, I'm working on a project that will be released soon. I'm not going to say what. But I want to search for a certain file, if it finds it executes it. I was wondering how I would code this? Note: no it's not a trojan, backdoor, virus of any sort. | March 5, 2003, 5:20 PM |
Eibro | [quote]Heh, I'm working on a project that will be released soon. I'm not going to say what. But I want to search for a certain file, if it finds it executes it. I was wondering how I would code this? Note: no it's not a trojan, backdoor, virus of any sort.[/quote] Perhaps you could try a search. http://www.vb-faq.com/Articles/Martin/FindFirstFile.asp | March 5, 2003, 5:40 PM |
FuzZ | I'll check that, thanks bro. | March 5, 2003, 6:47 PM |
MesiaH | Open the file, input it into a string line for line, and search through that string using InStr(), this will return the position of the item withing the string your searching for, as well as act as a boolean if it is found. | March 7, 2003, 12:58 AM |
FuzZ | Err.. That's not what I meant, I should've been more specific. I want to find Winamp.exe in their H.D.D. then execute it. Checking the registry key for Winamp would work as well, though I'm unsure how to do this as well. :P | March 7, 2003, 9:57 AM |
Yoni | At least for Winamp 2.x, this seems to be stored in the Default value of the key HKEY_CURRENT_USER\Software\Winamp. You can use the advapi32 Reg.. functions to open and read the value in the registry. (VB has some registry functions of its own but they totally suck and you can't use them here.) | March 7, 2003, 12:21 PM |
Grok | FuZZ :) See how much better the answers get when the people here understand what you want to do? We can suggest alternatives that you hadn't thought of, and that your question's context does not allude to. | March 8, 2003, 12:25 AM |
Skywing | [quote]Err.. That's not what I meant, I should've been more specific. I want to find Winamp.exe in their H.D.D. then execute it. Checking the registry key for Winamp would work as well, though I'm unsure how to do this as well. :P[/quote] This isn't in VB, but it's what I use to find Winamp (and it works fine) ... hopefully you shouldn't have much trouble figuring out how it works. [code]bool GetWinampLocation(LPSTR lpszBuffer, LPDWORD lpdwBufferSize) { HKEY hKey; if(RegOpenKeyEx(HKEY_CLASSES_ROOT, "Winamp.File\\shell\\Play\\command", 0, KEY_READ, &hKey)) return false; if(RegQueryValueEx(hKey, 0, 0, 0, (LPBYTE)&lpszBuffer[0], lpdwBufferSize)) { RegCloseKey(hKey); return false; } lpszBuffer[*lpdwBufferSize] = '\0'; // In case it wasn't a string/null terminated (ick!) if(LPSTR lpsz = strstr(lpszBuffer, "\" \"%1\"")) *lpsz = '\0'; if(lpszBuffer[0] == '\"') { int Size = strlen(lpszBuffer+1); memmove(lpszBuffer, lpszBuffer+1, Size); lpszBuffer[Size] = '\0'; } RegCloseKey(hKey); return true; } [/code] This works great for Winamp 2.xx. Untested with Winamp 3.xx, since 3.xx sucks. | March 8, 2003, 11:48 AM |
MesiaH | amen to that. | March 8, 2003, 1:27 PM |
FuzZ | Unfortunately Yoni, my winamp isn't registered under HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE in the software sections. But I will check that advapi32 Reg function out. Lol, Grok yes I do see now :P Yes, I do see what you did there Skywing. Thanks for the idea. And I'll probably be using this 'type' of method. Thanks for the posts. | March 9, 2003, 10:52 PM |
MesiaH | Uhm, if your using windows of any kind, it is in the registry. On an NT system its under current_user\software\winamp Any other, same thing cept under local_machine. | March 9, 2003, 11:23 PM |
Eibro | [quote]Err.. That's not what I meant, I should've been more specific. I want to find Winamp.exe in their H.D.D. then execute it. Checking the registry key for Winamp would work as well, though I'm unsure how to do this as well. :P[/quote] Using FindFirstFile() ... FindNextFile() as described in that article will work for what you want to do. You can recursively search each directory, starting at root. If you find "winamp.exe", execute it. This should be a last resort method as it's probably very slow. You could check the registry first, and if an entry for winamp is not found then tell the user you're about to begin searching. That, or prompt the user to input Winamps location. Once you have the location, store it in a known place. That way you'll only have to search once for each installation. | March 9, 2003, 11:44 PM |
FuzZ | I think the reason for my Winamp registry key being not existent, was because I installed Winamp3 to try (Mistake!) then installed Winamp 281 then uninstalled Winamp3, removing the registry key :\ | March 10, 2003, 3:11 PM |