Windows Service in VB

Tyring to use Plink from a bat file executed from a windows service

Page 1 of 1

6 Replies - 4463 Views - Last Post: 04 February 2009 - 08:51 AM Rate Topic: -----

#1 bhall652  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-September 08

Windows Service in VB

Posted 10 December 2008 - 07:03 AM

I am trying to execute Plink from a Windows Service. I have tried creating a bat file and executing directly as a command and neither works. I the bat file it acutally initiated the command but it didn't execute, just sat there till I killed it. Any ideas?

in a bat file
		Dim objwriter4 As New StreamWriter(w_wrkcommand)
		wLine = "ftp -n -s:" & w_wrkftpcommands1 & " " & m_pgp_machine & " >>cegttrans1.log"
		objwriter4.WriteLine(wLine)
		wLine = "plink " & m_pgp_machine & " -ssh -batch -v -l " & m_pgp_loginid & " -pw " & w_wrk_pass
		wLine = wLine & " chmod 700 " & w_wrkFileTrName & " >>cegtplink1.log"
		objwriter4.WriteLine(wLine)
		wLine = "plink " & m_pgp_machine & " -ssh -batch -v -l " & m_pgp_loginid & " -pw " & w_wrk_pass
		wLine = wLine & " ./" & w_wrkFileTrName & " >>cegtplink2.log"
		objwriter4.WriteLine(wLine)
		wLine = "ftp -n -s:" & w_wrkftpcommands2 & " " & m_pgp_machine & " >>cegttrans2.log"
		objwriter4.WriteLine(wLine)
		objwriter4.Close()
		retvalue = Shell(w_wrkcommand, AppWinStyle.MinimizedFocus, waitvalue)


in this attempt the 2 ftps work fine and the 2 plinks hang

as separate commands
		Dim wcommand1 As String = "ftp -n -s:" & w_wrkftpcommands1 & " " & m_pgp_machine & " >>cegttrans1.log"
		Dim wcommand2 As String = "plink " & m_pgp_machine & " -ssh -batch -v -l " & m_pgp_loginid & " -pw " & w_wrk_pass
		wcommand2 = wcommand2 & " chmod 700 " & w_wrkFileTrName & " >>cegtplink1.log"
		Dim wcommand3 As String = "plink " & m_pgp_machine & " -ssh -batch -v -l " & m_pgp_loginid & " -pw " & w_wrk_pass
		wcommand3 = wcommand3 & " ./" & w_wrkFileTrName & " >>cegtplink2.log"
		Dim wcommand4 As String = "ftp -n -s:" & w_wrkftpcommands2 & " " & m_pgp_machine & " >>cegttrans2.log"
		retvalue = Shell(wcommand1, AppWinStyle.MinimizedFocus, waitvalue)
		retvalue = Shell(wcommand2, AppWinStyle.MinimizedFocus, waitvalue)
		retvalue = Shell(wcommand3, AppWinStyle.MinimizedFocus, waitvalue)
		retvalue = Shell(wcommand4, AppWinStyle.MinimizedFocus, waitvalue)


in this case neither the ftps nor the plinks work - all get zero return codes but nothing happens
Help.

Is This A Good Question/Topic? 0
  • +

Replies To: Windows Service in VB

#2 bhall652  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-September 08

Re: Windows Service in VB

Posted 30 December 2008 - 08:15 AM

The problem here is not the code. It works exactly as it should. the problem here was that services are very difficult to debug. The service was logging into a secure server and when PLINK tried to execute in secure move, it genaerated a verification challenge for the fingerprint of the remote machine. Since noone could respond to the challenge, the service "appeared" to hang. This was corrected by logging into the machine as the service account running the service, running the *.bat file in interactive mode one time and acknowledging the fingerprint. Once the site was flagged as being trustworthy, the service would execute as a service with no problems.

The hardest code problems are the ones that are environmental or data related.
Was This Post Helpful? 0
  • +
  • -

#3 dklingman  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 33
  • View blog
  • Posts: 263
  • Joined: 23-December 08

Re: Windows Service in VB

Posted 31 December 2008 - 08:24 AM

since i've written a few services i will give you a little bit of advance services can be hard to debug if you actually try and debug the service itself. i know you maybe asking yourself that what i want to do. the best way to debug a service is to actually not debug the service but to write whatever the service is suppose to do into a dll project and debug the dll project from a console project.

for example one of the services i wrote i create a windows service project. i then create a dll project and a console project in the same solution. i set the console project as the start up project. in the dll project i usually create a class called Engine with a Start and Stop methods. i do all my coding that the service is suppose to do in the dll project. in the console app i create a instance of the dll project and then call the Start or stop method and start debugging. think of the console like that of the service. once you're read to actually deploy your service do the same code in the service class, create a new instance of the dll project in the service and in the onstart method call the Start method of the dll and on the onstop method call the Stop method of the dll.

if you'd like an example of what i'm talking about i'll be glad to upload a simple example.
Was This Post Helpful? 1
  • +
  • -

#4 bhall652  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-September 08

Re: Windows Service in VB

Posted 31 December 2008 - 06:42 PM

Thanks, I would appreciate an example very much.

This post has been edited by bhall652: 31 December 2008 - 06:43 PM

Was This Post Helpful? 0
  • +
  • -

#5 dklingman  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 33
  • View blog
  • Posts: 263
  • Joined: 23-December 08

Re: Windows Service in VB

Posted 01 January 2009 - 07:24 AM

here's an example as promised. keep in mind that this is only an example to show how to test a service by placing the code in a dll project

Attached File(s)


Was This Post Helpful? 1

#6 bhall652  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-September 08

Re: Windows Service in VB

Posted 19 January 2009 - 01:59 PM

Thanks for the example. I got the service working on my machine and then I tried to move it to the machine it is supposed to run on. When I got there, I installed the service (which appeared to work fine according to the log). When I try to start it though I get this message:

Error 14001: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.

Of course reinstalling did not help. When I googled the error message, it appeared to be some type of missing dll. I only have the executable (.exe) which invokes PLINK and java from shell command calls. Both these work outside my code from the directories I should be executing in.

Any ideas?
TIA
Was This Post Helpful? 0
  • +
  • -

#7 bhall652  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-September 08

Re: Windows Service in VB

Posted 04 February 2009 - 08:51 AM

Once again I over analyze and over look the obvious. It told me configuration error and that's what it was - a missing quote in a name value pair in the exe.config file.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1