0

I have a a VB Express 2010 application that allows users to select a Hotel we manage from a database. This is an access database. It then displays the all of the info for the hotel.

Everything works well. Except! the link to the RDP. All of the RDP's are stored in a public root folder on our shared network drive. The file path for each is Column in the database. I put a label in to test that the correct filepath was being pulled. Then I hid the label and use its text property to call the RDP session. Most connections just launch the RDP but some say

"INVALID CONNECTION FILE (lastpart of name.RDP) Specified."

Here's a bit of code:

RDPtext is a label that shows (when not hidden) the file path pulled from the database

 If RDPtext.Text = "" Then
        MessageBox.Show("This Property Uses A Different Connection Method" & vbCrLf & "Check SHAREPOINT DOCUMENTATION for more info.", "Site Does Not Use RDP")
 Else
        Shell("C:\Windows\System32\mstsc.exe " & RDPtext.Text, vbMaximizedFocus)
 End If

The filepath is all the same folder just different RDPs. The path may be

S:\shared\MyProgram\RDPs\NAMEofRDP.RDP

again some work and some cast an error.

Chris
  • 8,527
  • 10
  • 34
  • 51
DaveyLions
  • 73
  • 1
  • 10
  • I would throw in a check for the file: `IF system.io.file.exists(RDPtext.Text) then...`. Perhaps there is something wrong with the mapping or a slight difference that is not easy to detect visually. – Steve Sep 27 '13 at 21:20
  • Have you tried to manually use the RDP file? Maybe it is an older version that does not work with the current client. – Steve Sep 27 '13 at 21:22
  • Thanks for the responses. The RDP works fine when you click it outside of the program. and as for the path, I held SHIFT and clicked COPY AS PATH and pasted it right into the access database (removing the quotes of course). "S:\MyProgram\RDP's\Hanover TS.RDP" <---like that. Even changed the name of an RDP working with the program to the match the name of the non-working one (and renamed the non-working one something else) to check if it was the actual RDP and it didn't work. I feel like it's something to do with the path but I don't know what it could be besides maybe the length bya few chtrs – DaveyLions Sep 27 '13 at 21:39
  • Ah, the problem is the spaces. I bet it works on those without spaces in the name and not on the others. Let me know if this is true. – Steve Sep 27 '13 at 21:41
  • I now see you use shell, try using process.start instead. this should solve your issue. – Steve Sep 27 '13 at 21:43
  • Thanks Steve. It does work on some with spaces. I had the same thought and then I got even more confused! I have never used process.start, could I bother you for a quick example? And thanks so much for your time! – DaveyLions Sep 27 '13 at 21:46

1 Answers1

1

Try this instead of shell:

Process.Start("C:\Windows\System32\mstsc.exe", RDPtext.Text)

You can continue to use shell if you want but you have to do something like this to get it to work:

Shell("C:\Windows\System32\mstsc.exe """ & RDPtext.Text & """", vbMaximizedFocus)
Steve
  • 5,585
  • 2
  • 18
  • 32
  • Still throwing the same exception :( – DaveyLions Sep 27 '13 at 21:51
  • THE SHELL COMMAND with the extra """ WORKED!!! You ROCK! But now my final question is WHY? WHy does that work? BTW I'd love to give you an upvote. I'm almost at 15 reputation. I owe ya! – DaveyLions Sep 27 '13 at 21:53
  • 1
    You might need to do all the extra quotes with Process.Start too. This works because you are building a string to send to shell which just calls another exe. That exe then takes everything after it as an argument. Each space, starts another argument, unless you surrond it with qoutes. – Steve Sep 27 '13 at 21:56
  • 1
    IE, `Text.exe 1 c:\ 1/2/2013` gives test.exe 3 arguments. It would think `Text.exe 1 c:\Some Thing Else 1/2/2013` has 5 arguments. So to fix that, we do this `Text.exe 1 "c:\Some Thing Else" 1/2/2013` and it is back to 3 arguments – Steve Sep 27 '13 at 21:59