VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,327 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,926 people online right now. Registration is fast and FREE... Join Now!




Windows Service in VB

 

Windows Service in VB, Tyring to use Plink from a bat file executed from a windows service

bhall652

10 Dec, 2008 - 06:03 AM
Post #1

New D.I.C Head
*

Joined: 19 Sep, 2008
Posts: 9


My Contributions
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
CODE

        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
CODE

        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.

User is offlineProfile CardPM
+Quote Post


bhall652

RE: Windows Service In VB

30 Dec, 2008 - 07:15 AM
Post #2

New D.I.C Head
*

Joined: 19 Sep, 2008
Posts: 9


My Contributions
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.
User is offlineProfile CardPM
+Quote Post

dklingman

RE: Windows Service In VB

31 Dec, 2008 - 07:24 AM
Post #3

D.I.C Regular
Group Icon

Joined: 23 Dec, 2008
Posts: 254



Thanked: 31 times
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

bhall652

RE: Windows Service In VB

31 Dec, 2008 - 05:42 PM
Post #4

New D.I.C Head
*

Joined: 19 Sep, 2008
Posts: 9


My Contributions
Thanks, I would appreciate an example very much.

This post has been edited by bhall652: 31 Dec, 2008 - 05:43 PM
User is offlineProfile CardPM
+Quote Post

dklingman

RE: Windows Service In VB

1 Jan, 2009 - 06:24 AM
Post #5

D.I.C Regular
Group Icon

Joined: 23 Dec, 2008
Posts: 254



Thanked: 31 times
My Contributions
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)
Attached File  ExampleService.zip ( 31.5k ) Number of downloads: 97
User is offlineProfile CardPM
+Quote Post

bhall652

RE: Windows Service In VB

19 Jan, 2009 - 12:59 PM
Post #6

New D.I.C Head
*

Joined: 19 Sep, 2008
Posts: 9


My Contributions
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
User is offlineProfile CardPM
+Quote Post

bhall652

RE: Windows Service In VB

4 Feb, 2009 - 07:51 AM
Post #7

New D.I.C Head
*

Joined: 19 Sep, 2008
Posts: 9


My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 03:23PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month