473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can Process.Start("app.exe") be used in a .NET Web Application

I was wondering how the Process.Start() command can be used in a VB.NET
Web Application. I have used this command in a Windows Application
before successfully. I want the client side to envoke the .exe
application by clicking a button and want the .exe to run on the
server. I have read in groups that it is not possible and also have
heard that it is possible in Web Apps. Here is what I have tried so
far in the web app...

Dim myProcess As New Process()
myProcess.EnableRaisingEvents = False
myProcess.StartInfo.WorkingDirectory =
"C:\NETProjects\test\AppTest\bin\"
myProcess.StartInfo.FileName =
"C:\NETProjects\test\AppTest\bin\AppTest.exe"
myProcess.Start()

Also have tried this...

myProcess =
Process.Start("C:\NETProjects\test\AppTest\bin\App Test.exe")

Any Suggestions would be great!!

Thanks,

Brett

Nov 21 '05 #1
3 4993
Yeah, it's possible. Here's an example I did a few years ago. My main
goal here was impersonating the user who made the call, but the rest of
the stuff should work about the same. It's a little different from the
way to do it in standalone apps. There's probably a better way to do it
if you don't have to worry about impersonating, either.

Imports System.Diagnostics
Imports Microsoft.Win32
Imports System.ComponentModel
Imports System.Security.Principal
Imports System.Runtime.InteropServices
Imports System.Security.Permissions

Public Module ImpersonateUser

Structure SECURITY_ATTRIBUTES
Dim nLength As Int32
Dim lpSecurityDescriptor As Int32
Dim bInheritHandle As Int32
End Structure

Enum SECURITY_IMPERSONATION_LEVEL
SecurityAnonymous = 0
SecurityIdentification = 1
SecurityImpersonation = 2
SecurityDelegation = 3
End Enum

Enum TOKEN_TYPE
TokenPrimary = 1
TokenImpersonation
End Enum

Structure PROCESS_INFORMATION
Dim hProcess As Int32
Dim hThread As Int32
Dim dwProcessId As Int32
Dim dwThreadId As Int32
End Structure

Structure STARTUPINFO
Dim cb As Int32
Dim lpReserved As Int32
Dim lpDesktop As Int32
Dim lpTitle As Int32
Dim dwX As Int32
Dim dwY As Int32
Dim dwXSize As Int32
Dim dwYSize As Int32
Dim dwXCountChars As Int32
Dim dwYCountChars As Int32
Dim dwFillAttribute As Int32
Dim dwFlags As Int32
Dim wShowWindow As Int16
Dim cbReserved2 As Int16
Dim lpReserved2 As Int32
Dim hStdInput As Int32
Dim hStdOutput As Int32
Dim hStdError As Int32
End Structure
Const INFINITE As Int32 = &HFFFFFFFF
Const WAIT_FAILED As Int32 = &HFFFFFFFF
Const WAIT_TIMEOUT As Int32 = 258I
Const STARTF_USESHOWWINDOW As Int32 = &H1
Const SW_HIDE As Int32 = 0
Const SW_SHOWNORMAL As Int32 = 1
Const SLEEP_DELAY As Int32 = 100&
Const STATUS_PENDING As Int32 = &H103&
Const STILL_ACTIVE As Int32 = STATUS_PENDING
Const CREATE_DEFAULT_ERROR_MODE As Int32 = &H4000000
Const CREATE_NEW_CONSOLE As Int32 = &H10
Const CREATE_NEW_PROCESS_GROUP As Int32 = &H200
Const STARTF_USESTDHANDLES As Int32 = &H100
Const MAXIMUM_ALLOWED As Int32 = &H2000000
Const CREATE_NO_WINDOW As Int32 = &H8000000
Const ANYSIZE_ARRAY As Int32 = 1
Const ERROR_SUCCESS As Int32 = 0I
' Misc input flags
Const TOKEN_QUERY As Int32 = &H8
Const TOKEN_ADJUST_PRIVILEGES As Int32 = &H20
Const STANDARD_RIGHTS_REQUIRED As Int32 = &HF0000
Const TOKEN_ASSIGN_PRIMARY As Int32 = &H1
Const TOKEN_DUPLICATE As Int32 = &H2
Const TOKEN_IMPERSONATE As Int32 = &H4
Const TOKEN_QUERY_SOURCE As Int32 = &H10
Const TOKEN_ADJUST_GROUPS As Int32 = &H40
Const TOKEN_ADJUST_SESSIONID As Int32 = &H100
Const TOKEN_ADJUST_DEFAULT As Int32 = &H80
Const TOKEN_ALL_ACCESS As Int32 = (STANDARD_RIGHTS_REQUIRED Or
TOKEN_ASSIGN_PRIMARY Or TOKEN_DUPLICATE Or TOKEN_IMPERSONATE Or
TOKEN_QUERY Or TOKEN_QUERY_SOURCE Or TOKEN_ADJUST_PRIVILEGES Or
TOKEN_ADJUST_GROUPS Or TOKEN_ADJUST_SESSIONID Or TOKEN_ADJUST_DEFAULT)

Declare Auto Function DuplicateTokenEx Lib "advapi32.dll" ( _
ByVal hExistingToken As IntPtr, _
ByVal dwDesiredAccess As Int32, _
ByRef lpTokenAttributes As SECURITY_ATTRIBUTES, _
ByVal ImpersonationLevel As SECURITY_IMPERSONATION_LEVEL, _
ByVal TokenType As TOKEN_TYPE, _
ByRef phNewToken As IntPtr) _
As Int32

Declare Auto Function CreateProcessAsUserW Lib "advapi32.dll" ( _
ByVal hToken As IntPtr, _
ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByRef lpProcessAttributes As SECURITY_ATTRIBUTES, _
ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, _
ByVal bInheritHandles As Int32, _
ByVal dwCreationFlags As Int32, _
ByVal lpEnvironment As Int32, _
ByVal lpCurrentDirectory As String, _
ByRef lpStartupInfo As STARTUPINFO, _
ByRef lpProcessInformation As PROCESS_INFORMATION) _
As Int32

Declare Auto Function CloseHandle Lib "kernel32.dll" ( _
ByVal hObject As Int32) _
As Int32

Declare Auto Function WaitForInputIdle Lib "user32.dll" ( _
ByVal hProcess As Int32, _
ByVal dwMilliseconds As Int32) _
As Int32

Declare Auto Function CreatePipe Lib "kernel32.dll" ( _
ByRef phReadPipe As Int32, _
ByRef phWritePipe As Int32, _
ByRef lpPipeAttributes As SECURITY_ATTRIBUTES, _
ByVal nSize As Int32) _
As Int32

Declare Auto Function ReadFile Lib "kernel32.dll" ( _
ByVal hFile As Int32, _
ByRef lpBuffer As Byte, _
ByVal nNumberOfBytesToRead As Int32, _
ByRef lpNumberOfBytesRead As Int32, _
ByVal lpOverlapped As Int32) _
As Int32

Declare Auto Function PeekNamedPipe Lib "kernel32.dll" ( _
ByVal hNamedPipe As Int32, _
ByRef lpBuffer As String, _
ByVal nBufferSize As Int32, _
ByRef lpBytesRead As Int32, _
ByRef lpTotalBytesAvail As Int32, _
ByRef lpBytesLeftThisMessage As Int32) _
As Int32

Declare Auto Function GetExitCodeProcess Lib "kernel32" ( _
ByVal hProcess As Int32, _
ByRef lpExitCode As Int32) _
As Int32

Declare Auto Function Sleep Lib "kernel32" ( _
ByVal dwMilliseconds As Int32) _
As Int32

Function OnClick() As String
Dim Token As New IntPtr(0)
Dim TokenDuplicate As New IntPtr(0)
Dim TokenAttributes As SECURITY_ATTRIBUTES
Dim Result As Int32
Dim i, x, y As Integer
Dim arrStr() As String
Dim arrStrSub() As String
Dim strOut As String
'####################################EXTERNAL PROCESSING DONE
IN HERE################################
'Create new Impersonation Token For External Processes
Token = WindowsIdentity.GetCurrent.Token()
'Result = DuplicateTokenEx(Token, MAXIMUM_ALLOWED,
TokenAttributes, SECURITY_IMPERSONATION_LEVEL.SecurityDelegation,
TOKEN_TYPE.TokenPrimary, TokenDuplicate)
Result = DuplicateTokenEx(Token, MAXIMUM_ALLOWED,
TokenAttributes, SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation ,
TOKEN_TYPE.TokenPrimary, TokenDuplicate)
If Result <> 0 Then
'Test 1.1.1 Get
Hotfixes****************************************** **************
'AddRow("Test 1.1.1 Windows Hotfixes", , True)
' strOut = ShellExe( _
' "dheath", _
' TokenDuplicate, _
' "C:\sayMyName.exe " &
"\\cimarron\techview") ' _'/hf -h " & "" & " -s 2 -z" _
strOut = ShellExe("dheath", TokenDuplicate,
"C:\remoteTest.exe")
Else
'AddRow("Error Creating Duplicate Impersonation Token: " &
Err.LastDllError.ToString)
End If
CloseHandle(Token.ToInt64)
CloseHandle(TokenDuplicate.ToInt64)
Return strOut
'####################################END EXTERNAL
PROCESSING######################################## #
End Function

Function ShellExe(ByVal sname As String, ByRef TokenDuplicate As
IntPtr, ByVal strCommandLine As String) As String

Dim hReadPipe, hWritePipe As Int32
Dim Result, ret, bSuccess As Int32
Dim si As STARTUPINFO
Dim pi As PROCESS_INFORMATION
Dim strCurrentDirectory As String
Dim strAppName As String
Dim sa As SECURITY_ATTRIBUTES
Dim bytesread As Int32
Dim bytestoget As Int32
Dim bytesavail As Int32
Dim bytesleft As Int32
Dim strOutT As String
Dim mybuff() As Byte
Dim intReturnValue As Int32
Dim intExitCode As Int32
Dim i As Int32

sa.nLength = Len(sa)
sa.bInheritHandle = True
sa.lpSecurityDescriptor = 0

ret = CreatePipe(hReadPipe, hWritePipe, sa, 0)
If ret = 0 Then
ShellExe = "CreatePipeOut failed. Error: " &
Err.LastDllError
Exit Function
End If

strCurrentDirectory = "C:\" 'inetpub\wwwroot\asat\utilities"

si.cb = Len(si)
si.dwFlags = STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW
si.hStdOutput = hWritePipe
si.wShowWindow = SW_HIDE

Result = CreateProcessAsUserW( _
TokenDuplicate, _
vbNullString, _
strCommandLine, _
sa, _
sa, _
1, _
CREATE_NEW_CONSOLE, _
0, _
strCurrentDirectory, _
si, _
pi)

If Result <> 0 Then
Do
intReturnValue = GetExitCodeProcess(pi.hProcess,
intExitCode)
Sleep(SLEEP_DELAY)
Loop While (intExitCode = STILL_ACTIVE) And Not
(intReturnValue = 0)
Else
ShellExe = "Create Process Failed With Error " &
Err.LastDllError.ToString
End If
PeekNamedPipe(hReadPipe, 0, 0, 0, bytesavail, 0)
ReDim mybuff(bytesavail)
bytestoget = CInt(bytesavail)
bSuccess = ReadFile(hReadPipe, mybuff(0), bytestoget,
bytesread, 0)
If bSuccess = 1 Then
For i = 0 To bytesavail
strOutT = strOutT & Chr(CType(mybuff(i), Integer))
'strOutC = strOutC & CType(mybuff(i), Integer) & ","
ShellExe = strOutT
Next
Else
ShellExe = "ReadFile failed. Error: " & Err.LastDllError
End If

CloseHandle(pi.hProcess)
CloseHandle(pi.hThread)
CloseHandle(hReadPipe)
CloseHandle(hWritePipe)
End Function
End Module

Nov 21 '05 #2
Brett,

Threath is right, however there would be more simple methods, have a look
at what is written in this newsgroup about impersonating

http://groups-beta.google.com/group/...rch+this+group

I hope this helps,

Cor
Nov 21 '05 #3
Would it be possible to give the ASP.NET or Internet user more rights
inorder to be able to execute the application on the server from the
client side.

Brett

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Henne | last post by:
Hello, in VB6 we werr able to make ActiveX-DLL's (In Process Components) and ActiveX-Exe (Out Of Process Components). Out Application is build of one main application that starts other...
3
by: Wardeaux | last post by:
All, I've written a "setup" wrapper that calls a sequence of "setup.exe", and all works except when I call the setup.exe for the MSDE, then it gets about half way through and then hangs... The...
3
by: Dean Slindee | last post by:
The code below is being used to launch WinWord.exe from a VB.NET program. Word launches, but displays this error message: "Word has experienced an error trying to open the file. Try these...
2
by: Dean Slindee | last post by:
The code below is being used to launch WinWord.exe from a VB.NET program. Word launches, but displays this error message: "Word has experienced an error trying to open the file. Try these...
2
by: Anthony | last post by:
Hello All, Thanks for your help first, I wonder is there any link to sample or documentation that explain how to make .exe in C++ communicate to .exe in C#? I know there is some way like Share...
3
by: google.100.frause | last post by:
Previously I had the same Problem discussed and solved here: http://clariusconsulting.net/blogs/hdl/archive/2005/12/02/410.aspx?CommentPosted=true#commentmessage but now I've got the next...
6
by: eric.goforth | last post by:
Hello, I'm calling a VB.NET 2003 dll that's registered in COM+. I've added a reference to it in a VB6 DLL that I'm calling from a Classic ASP page. Previously I was able to attach to my .NET...
7
by: Robinson | last post by:
Hi, I was just playing around with my log files and tried to open a log file programmatically that was considered "in use" (I got an in-use exception). The file is being used by my debug writer...
1
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
If this is the code I use to start another program, what can I use to: System.Diagnostics.Process.Start("EcpKpScript_01.exe"); 1. Stop the process 2. Check if the process is already running? ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.