.net - Is it possible to have a windows service call a VBScript that removes the service and installs a new version? -


i have vbscript that, when called manually or code being debugged, removes , reinstalls service. script works.

the problem when calling same script within service needs removed, script runs service not removed.

i have made script write log few minutes , while executing manually remove service , script keeps writing log until time expires not service in control.

i have attempted use process class call cmd.exe , call cscript.exe path script , have tried same using shell().

so question is. possible have service call script updates service newer version? mention again when script called stemware else works.

this how call scripts withing service. calling same code debugger works.

private sub callscript(pathtoscript string)     dim start new processstartinfo     start.filename = "c:\windows\system32\cscript.exe"     start.arguments = pathtoscript     start.useshellexecute = false     start.redirectstandardoutput = true     start.redirectstandarderror = true     dim myproc new process     myproc.startinfo = start     myproc.start() end sub 

or

private sub callscript(pathtoscript string)          shell(string.format("c:\windows\system32\cscript.exe {0}", pathtoscript))    end sub 

this part of script fails when call script called withing service:

public sub unistallservice()     set oshell = wscript.createobject ("wscript.shell")     oshell.run "cmd.exe /c ""c:\program files\mysoftware\services\workflowservices\autoupdate\autoupdateservice.exe"" -u", 0 ,true     wscript.sleep 10000 end sub 

when called visual studio or if call script console works.

this code inside service .exe performs installation:

      protected sub installservice()         using installer assemblyinstaller = getinstaller()             dim state idictionary = new hashtable()             try                 me.writetolog(string.format("installing {0}", me.servicename))                 installer.install(state)                 installer.commit(state)                if me.isinstalled()                   me.writetolog("installation complete")                end if                          catch ex exception                 try                     installer.rollback(state)                 catch                 end try                 me.writetolog(string.format("{0}", ex.message), ex)                 throw             end try         end using 

end sub

 protected sub uninstallservice()     if not me.isinstalled()         return     end if      if me.isrunning()         me.stopservice()     end if     try         using installer assemblyinstaller = getinstaller()             dim state idictionary = new hashtable()             try                 me.writetolog(string.format("removing service {0}", me.servicename))                 installer.uninstall(state)                 if me.isinstalled                     throw new exception(string.format("unable remove service: {0}", me.servicename))                 else                     me.writetolog(string.format("service removed"))                 end if             catch                 throw             end try         end using     catch ex exception         me.writetolog(string.format("{0}", ex.message), ex)         throw     end try end sub 

this service main looks like:

shared sub main(args string())    dim svc new autoupdateservice()      if environment.userinteractive         if args.length = 1             select case args(0)                 case "-install", "-i"                     svc.installservice()                     exit select                 case "-uninstall", "-u"                     svc.uninstallservice()                     exit select                 case else                     throw new notimplementedexception()             end select         end if     else         dim servicestorun servicebase()         servicestorun = new servicebase() {new autoupdateservice()}         servicebase.run(servicestorun)     end if 

end sub


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -