• Welcome to Valhalla Legends Archive.
 

Searching for keyword (VB)

Started by FuzZ, March 05, 2003, 11:20 AM

Previous topic - Next topic

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.

Eibro

#1
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
Eibro of Yeti Lovers.

FuzZ

#2
I'll check that, thanks bro.

Mesiah / haiseM

#3
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.
]HighBrow Innovations
Coming soon...

AIM Online Status: 

FuzZ

#4
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

Yoni

#5
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.)

Grok

#6
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.

Skywing

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.

Mesiah / haiseM

#8
amen to that.
]HighBrow Innovations
Coming soon...

AIM Online Status: 

FuzZ

#9
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.

Mesiah / haiseM

#10
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.
]HighBrow Innovations
Coming soon...

AIM Online Status: 

Eibro

#11
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.
Eibro of Yeti Lovers.

FuzZ

#12
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 :\