By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,377 Members | 3,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,377 IT Pros & Developers. It's quick & easy.

Error message: Expected Line number . .

P: 8
Hi,

I am new to VB and have run into an error message and I am not sure what the problem is ... I am trying to use VB to open up an SSH tunnel ...

the error message is : "Expected Line number, label statement or end of statement


Here is the code ... any help would be appreciated .. cheers, Natasha



Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ()
ByVal hwnd As Long, _
ByVal lpszOp As String, _
ByVal lpszFile As String, _
ByVal lpszParams As String, _
ByVal lpszdir As String, _
ByVal FsShowCmd As Long)
As Long



Private Sub Form_Load()
ShellExecute Me.hWnd, "Open", "C:/plink.exe", "-ssh"
-l tunnel -pw Cyber4me -L -batch 192.168.10.25", "c:\",
0
MsgBox "Tunnel Open!"

End Sub
Apr 16 '07 #1
Share this Question
Share on Google+
12 Replies


iburyak
Expert 100+
P: 1,017
Try this:

Expand|Select|Wrap|Line Numbers
  1. Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
  2. ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  3.  
  4.  
  5.  
  6.  
  7. Private Sub Form_Load()
  8. ShellExecute Me.hwnd, "Open", "C:/plink.exe", "-ssh -l tunnel -pw Cyber4me -L -batch 192.168.10.25", "c:\", 0
  9. MsgBox "Tunnel Open!"
  10.  
  11. End Sub
Good Luck.
Apr 16 '07 #2

P: 8
Hi Thanks for the response .. I can get the code to compile now without any errors. When I run the script, I see the "tunnel open" message box ... I click okay and then see a blank forms page ?? IS there something that I am missing, as to why the tunnel would not be opening ?

I replaced the plink.exe with putty.exe just to see if putty would lanuch and it does ... so I am not sure why plink would not be opening the tunnel ... thanks again ..
Natasha



Try this:

Expand|Select|Wrap|Line Numbers
  1. Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
  2. ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  3.  
  4.  
  5.  
  6.  
  7. Private Sub Form_Load()
  8. ShellExecute Me.hwnd, "Open", "C:/plink.exe", "-ssh -l tunnel -pw Cyber4me -L -batch 192.168.10.25", "c:\", 0
  9. MsgBox "Tunnel Open!"
  10.  
  11. End Sub
Good Luck.
Apr 16 '07 #3

iburyak
Expert 100+
P: 1,017
Unfortunately I don't know those EXEs you have to try execute the same statement with all parameters from DOS prompt and see if any errors will show up.


Sorry, not sure how to help you here..... :)
Apr 16 '07 #4

iburyak
Expert 100+
P: 1,017
Don't you think you should change a backslash here?

From
C:/plink.exe
to
C:\plink.exe
Apr 16 '07 #5

P: 8
Hi ... I already changed the backslash ... I alredy went into DOS and ran the plink command .. this is just a command line version of putty .... it works from DOS ..

I think the error is something I am not doing in VB. I just started using VB, so that is probably the issue .. I simply went into VB and started writing the code ..

When I run the script I am just getting a blank form1 page ... Is there something that I need to create to get my output to show-up in VB ? thanks for your advise ... cheers,

N


Don't you think you should change a backslash here?

From
C:/plink.exe
to
C:\plink.exe
Apr 16 '07 #6

iburyak
Expert 100+
P: 1,017
In this line:

Expand|Select|Wrap|Line Numbers
  1. ShellExecute Me.hwnd, "Open", "C:\plink.exe", "-ssh -l tunnel -pw Cyber4me -L -batch 192.168.10.25", "c:\", 0
change 0 to 1

Expand|Select|Wrap|Line Numbers
  1. ShellExecute Me.hwnd, "Open", "C:\plink.exe", "-ssh -l tunnel -pw Cyber4me -L -batch 192.168.10.25", "c:\", 1
Try to execute this way.
Apr 16 '07 #7

P: 8
It worked ... thanks so much ....

Natasha


In this line:

Expand|Select|Wrap|Line Numbers
  1. ShellExecute Me.hwnd, "Open", "C:\plink.exe", "-ssh -l tunnel -pw Cyber4me -L -batch 192.168.10.25", "c:\", 0
change 0 to 1

Expand|Select|Wrap|Line Numbers
  1. ShellExecute Me.hwnd, "Open", "C:\plink.exe", "-ssh -l tunnel -pw Cyber4me -L -batch 192.168.10.25", "c:\", 1
Try to execute this way.
Apr 16 '07 #8

iburyak
Expert 100+
P: 1,017
I think it worked before too. You just didn't see it.
Now by changing parameter 0 to 1 you were able to see that it does work.
0 - makes application run on a background.


I am glad it is working now.
Good Luck.

Irina.
Apr 16 '07 #9

P: 8
Hi Irina,

Thanks again for your help yesteray. I am now trying to include the option to close the SSH tunnel. I can get the following code to compile with no errors, but I get no output .... Could you have a look at this to see if I am missing something .. maybe an API declaration or something ... Yesterday I was at least getting the "open tunnel" box to display before I made the changes you suggested ... but now ... I can complile the code and then nothing ...

thanks,

Natasha

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Dim si As SHELLEXECUTEINFO
  4.  
  5. Private Declare Function ShellExecuteEx Lib "shell32.dll" Alias "ShellExecuteExA" _
  6.   (si As SHELLEXECUTEINFO) As Long
  7.  
  8.  
  9. Private Declare Function TerminateProcess Lib "kernel32" (ByVal _
  10.    hProcess As Long, ByVal uExitCode As Long) As Long
  11.  
  12.  
  13. Private Type SHELLEXECUTEINFO
  14.   cbSize As Long
  15.   fMask As Long
  16.   hwnd As Long
  17.   lpVerb As String
  18.   lpFile As String
  19.   lpParameters As String
  20.   lpDirectory As String
  21.   nShow As Long
  22.   hInstApp As Long
  23.   lpIDList As Long
  24.   lpClass As String
  25.   hkeyClass As Long
  26.   dwHotKey As Long
  27.   hIcon As Long
  28.   hProcess As Long
  29. End Type
  30.  
  31.  
  32.  
  33.  
  34.  
  35. Private Sub cmdClose_Click()
  36.     Dim exitCode As Long
  37.     If TerminateProcess(si.hProcess, exitCode) <> 0 Then
  38.         CloseHandle (si.hProcess)
  39.         MsgBox "Tunnel Closed!"
  40.     End If
  41. End Sub
  42.  
  43. Private Sub cmdOpen_Click()
  44.     si.cbSize = Len(si)
  45.     si.fMask = SEE_MASK_NOCLOSEPROCESS
  46.     si.hwnd = frmMain.hwnd
  47.     si.lpVerb = "open"
  48.     si.lpFile = "c:\plink.exe"
  49.     si.lpParameters = "-ssh -l tunnel -pw Cyber4me 192.168.10.25", "c:\", 1
  50.     si.lpDirectory = "c:\"
  51.     si.nShow = SW_HIDE
  52.  
  53.  
  54.  
  55.     If ShellExecuteEx(si) Then
  56.         MsgBox "Tunnel Open!"
  57.     Else
  58.         MsgBox "Opening Failed!"
  59.     End If
  60. End Sub
Apr 17 '07 #10

iburyak
Expert 100+
P: 1,017
Look at this line:

si.lpParameters = "-ssh -l tunnel -pw Cyber4me 192.168.10.25", "c:\", 1

, 1 - is not a part of parameters passed to exe.
It is the last parameter in ShellExecute Function which is nShowCmd = 1 the same as SW_SHOWNORMAL
See
http://msdn2.microsoft.com/en-us/library/ms647732.aspx

Good Luck.
Apr 17 '07 #11

Expert 5K+
P: 8,434
si.lpParameters = "-ssh -l tunnel -pw Cyber4me 192.168.10.25", "c:\", 1
That raises an interesting question. What do you get when you assign two or three values like this, separated by commas, to a string? I would have expected a compile error.

I'll have to try it sometime.
Apr 17 '07 #12

iburyak
Expert 100+
P: 1,017
That raises an interesting question. What do you get when you assign two or three values like this, separated by commas, to a string? I would have expected a compile error.

I'll have to try it sometime.
I have to stop putting my 5 cents everywhere...
It gets people confused... :)
Apr 17 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.