Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Text line
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\test.exe -y -u
 
Above is the example of text that would be stored as a Dim test value, that I'm drawing from the registry. But the registry has -y /setup stuff like that on the end of these file paths. I want to be able take the Dim test value and read everything up to the .exe. Everything else after that I dont want there. I used LastIndexof for getting the name of the file in a separate column (Shown Below). So text.exe was the result of that. But I want to do file path without the extra -y -u in the string.
 
Code:
Dim ImagePath As String = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", RegKeyLogon.GetValueNames(i), Nothing)
 
Dim slashPosition As Integer = ImagePath.LastIndexOf("\")                          
Dim FileName As String = ImagePath.Substring(slashPosition + 1)
msg(FileName)
 
Result:
 
test.exe

 
What I want Now:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\test.exe
Posted 2-May-12 15:05pm
Comments
SAKryukov at 2-May-12 20:39pm
   
How about using the debugger? You already had the result and then destroyed it -- please see my answer.
--SA
Jefferson Daniel at 3-May-12 1:21am
   
I guess I did a bad job explaining what I was doing. Because you sort of pointed out the obvious to me. I appreciated you helping, but msg(ImagePath), yes is doing what I want already getting the file path, and I already had that part working. But
 
msg(ImagePath) would give me:
 
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\test.exe -y -u
 
which is sort of what I want, but without the -y -u. Which is why I'm trying to fine a way to pass it through a few more code stuff so that it will cut off all text after ".exe" and that way the new modified
 
msg(ImagePath) would give me:
 
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\test.exe
 
I want to be able to use the the modified ImagePath, for other features in my project. But I cant do it, if the file path has "-y -u " ... etc in it. Using the "SlashPosition" allowed me to delete code in the left direction of the text, but I want to delete anything on the right side of ".exe"
SAKryukov at 8-May-12 12:55pm
   
Then strip it out using
string[] terms = command.Split(' ');
string executableFileName = terms[0];

That's it.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What are you doing? Just don't do next lines; use ImagePath:
Dim ImagePath As String = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", RegKeyLogon.GetValueNames(i), Nothing)
 
Dim slashPosition As Integer = ImagePath.LastIndexOf("\")       'remove this line!
Dim FileName As String = ImagePath.Substring(slashPosition + 1) 'remove this line, too!
msg(FileName)                                                   'remove this line, too!
'do this:
msg(ImagePath)
 
—SA
  Permalink  
v2
Comments
VJ Reddy at 2-May-12 21:26pm
   
Nice answer. 5!
SAKryukov at 3-May-12 13:16pm
   
Thank you, VJ.
--SA
Jefferson Daniel at 5-May-12 21:38pm
   
Could you keep helping me Sakryukov? I still need help.
SAKryukov at 8-May-12 12:52pm
   
Maybe, if you ask a question I can answer.
Are you going to accept this answer formally (green button)? -- thanks?
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

      Dim Path As String = "C:\ProgramData\Microsoft\_
                           Windows\Start Menu\Programs\Startup\test.exe -y -u"
      Dim ImagePath = New Regex(".+\..{3}\s?").Match(Path).Value.Trim
                
      msg(ImagePath)
 
This is what I ended up doing. It worked best, and allowed me to do other things I needed too. I'm not entirely sure if your solution above worked or not, But i'm keeping to this. Thanks anyways.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 195
3 DamithSL 195
4 Richard MacCutchan 178
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 8 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100