Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Executing Shell Command

Executing Shell Command

Scheduled Pinned Locked Moved Visual Basic
windows-adminlinux
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi, I have trouble in executing shell commands within windows service. Below is my code in Timers Elapsed event. Timers interval is 5 sec. Other than this code everything else is working. I am not sure why I am unable to execute this code. I am running my windows service as a User, which has administrator rights. I also tried to run this windows service as LocalSystem but nothing happens. Have a nice day. Naqsh Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process() proc.StartInfo.FileName = "cmd.exe" proc.StartInfo.Arguments = "/C net start ""IIS Admin""" proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden proc.StartInfo.CreateNoWindow = True proc.Start() End Sub Justice and Peace for everyone.

    D 1 Reply Last reply
    0
    • L Lost User

      Hi, I have trouble in executing shell commands within windows service. Below is my code in Timers Elapsed event. Timers interval is 5 sec. Other than this code everything else is working. I am not sure why I am unable to execute this code. I am running my windows service as a User, which has administrator rights. I also tried to run this windows service as LocalSystem but nothing happens. Have a nice day. Naqsh Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process() proc.StartInfo.FileName = "cmd.exe" proc.StartInfo.Arguments = "/C net start ""IIS Admin""" proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden proc.StartInfo.CreateNoWindow = True proc.Start() End Sub Justice and Peace for everyone.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      That's because (I THINK!!) CMD will only launch on Desktop 0, what the user sees. You can't launch CMD from a service because the service has no visible desktop and has no access to interactive inputs (keyboard and mouse), which CMD requires. What you should be doing is using the ServiceController class to start the IIS Admin Service. This is done something like this: Dim myController As New System.ServiceProcess.ServiceController("IISAdmin") If myController.Status.Equals(ServiceControllerStatus.Stopped) Then myController.Start() End If RageInTheMachine9532

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups