Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
VB
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:

VB
test.exe


What I want Now:
VB
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\test.exe
Posted
Comments
Sergey Alexandrovich Kryukov 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 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"
Sergey Alexandrovich Kryukov 8-May-12 12:55pm    
Then strip it out using
string[] terms = command.Split(' ');
string executableFileName = terms[0];

That's it.
--SA

What are you doing? Just don't do next lines; use ImagePath:
VB
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
 
Share this answer
 
v2
Comments
VJ Reddy 2-May-12 21:26pm    
Nice answer. 5!
Sergey Alexandrovich Kryukov 3-May-12 13:16pm    
Thank you, VJ.
--SA
Jefferson Daniel 5-May-12 21:38pm    
Could you keep helping me Sakryukov? I still need help.
Sergey Alexandrovich Kryukov 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
VB
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900