Valhalla Legends Archive

Programming => General Programming => Topic started by: FuzZ on March 05, 2003, 11:20 AM

Title: Searching for keyword (VB)
Post by: FuzZ on March 05, 2003, 11:20 AM
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.
Title: Re: Searching for keyword (VB)
Post by: Eibro on March 05, 2003, 11:40 AM
QuoteHeh, 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.
Perhaps you could try a search.
http://www.vb-faq.com/Articles/Martin/FindFirstFile.asp
Title: Re: Searching for keyword (VB)
Post by: FuzZ on March 05, 2003, 12:47 PM
I'll check that, thanks bro.
Title: Re: Searching for keyword (VB)
Post by: Mesiah / haiseM on March 06, 2003, 06:58 PM
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.
Title: Re: Searching for keyword (VB)
Post by: FuzZ on March 07, 2003, 03:57 AM
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
Title: Re: Searching for keyword (VB)
Post by: Yoni on March 07, 2003, 06:21 AM
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.)
Title: Re: Searching for keyword (VB)
Post by: Grok on March 07, 2003, 06:25 PM
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.
Title: Re: Searching for keyword (VB)
Post by: Skywing on March 08, 2003, 05:48 AM
QuoteErr.. 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
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.

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;
}

This works great for Winamp 2.xx.  Untested with Winamp 3.xx, since 3.xx sucks.
Title: Re: Searching for keyword (VB)
Post by: Mesiah / haiseM on March 08, 2003, 07:27 AM
amen to that.
Title: Re: Searching for keyword (VB)
Post by: FuzZ on March 09, 2003, 04:52 PM
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.
Title: Re: Searching for keyword (VB)
Post by: Mesiah / haiseM on March 09, 2003, 05:23 PM
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.
Title: Re: Searching for keyword (VB)
Post by: Eibro on March 09, 2003, 05:44 PM
QuoteErr.. 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
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.
Title: Re: Searching for keyword (VB)
Post by: FuzZ on March 10, 2003, 09:11 AM
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 :\