Skip to content

Shell program not executing via web when using server name

Scott Pate

Asked Nov 6, 2015, 7:18 AM EST1 answer
Share
LinkedInX
 

I have a VB.Net 2012 web application where we are trying to execute a process which starts a vbs script located on a Remote VM.

The code works properly when I run it directly within the Visual Studio debugger, which spawns via the following URL:

http://localhost:63579/DDFE/MultiRun.aspx?&Sort=

However when we publish the application to the production folder and run the web app the cmd process does not seem to be executed properly. Below is the published URL:

http://ne1dwgtqa301/DDFE/MultiRun.aspx?&Sort=

You can see that the difference is in the machine name of "ne1dwgtqa301" vs "localhost:63579".

I assume this is a permissions issue but have been unable to determine the root cause of the Shell command not executing properly when run via the published URL. This does not run even when executed on the host server, but the command works properly when run manually or via "localhost:63579" on the same server.

Any help is much appreciated!

 
Protected Sub btnRun_Click(sender As Object, e As EventArgs) Handles btnRun.Click
Dim shellCommand As String
 
For Each item As ListItem In lstVMs.Items
      If item.Selected = True Then
          shellCommand = "C:\websites\prod\DDFE\Log\psexec.exe \\NE1-VDI-" & item.Text & ".us.ad.xxx.com -e -h -u W2KXXX\user -p pswd C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe /c C:\windows\SysWoW64\cscript.exe C:\Scripts\Driver.vbs"
        Shell(shellCommand, AppWinStyle.Hide)
    End If
Next
 
End Sub 'btnRun_Click 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    When published in IIS, a website runs under the purview of the account with which the website is hosted in IIS. It will either be hosted using ApplicationIdentity or Network Service. So, in this case whenever you want to execute the process which needs Admin privileges over some other system, better run use impersonation. The account which will be used to impersonate should have Admin rights on the for executing the powershell command.
    Also sometimes while running powershell commands, if they are stored in a file with .ps1, .bat or .vbs extension we need  to bypass the local execution policy.
    So try out the below command with your existing command -
    powershell -ExecutionPolicy ByPass -File  
    0