What is an Ignore list?
Start Process in ASP.Net
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What is interesting here?
• Duels
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Ñîîáùåñòâà
• Talxy Chat
• Horoscope
• Online
 
Register!

QAIX > .Net Development > Start Process in ASP.Net 16 July 2002 08:04:12

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Ìîäåðàòîð:

Start Process in ASP.Net

Prashanth G 15 July 2002 02:02:36
 Hi,
I have an ASP.Net Application. From this application I need to start
a process which will run a Visual Test File (Something like a Setup
File with some UI). When I run this, the processes are getting
created, but the UI does not appear. I am not sure if the UI will come
or not but the newly created process(processes are created, I can see
in Task Manager) looks like does nothing.

But if I start the same process with a Windows Application the Wizard
kicks off.
Since the process is created newly I assume whether Windows App or Web
App should not matter as it is a new process.

I also tried by putting the Create Process Class in COM+ and run as
server. It works fine with Win App but not with Web App.

Can somebody tell me if this is possible or if I am missing something.

I apologize for putting this in IIS group also. I just thought may be
some IIS funda is also there.

Any help, pointers.. will be highly appreciated.

Thanks
PrashanthG


___________________­____________________­___________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.­com

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.deve­lop.com.

Add comment
Hun Boon 16 July 2002 08:04:12 permanent link ]
 The reason that you don't see it in the desktop is because the process created under aspnet_wp.exe has its own Workstation and
Desktop under NT/W2K/XP.
In order to bring the process the current visible workstation and desktop, you have to open the current interative logon workstation
and desktop, and at the same time aspnet_wp.exe which is run under a/c ASPNET must have privilege to access the current interative
logon user desktop because you are trying to create in a different user desktop (from ASPNET --> the current logon user desktop).
I did not find an API in the current .NET classes ,(System.Diagnostic­s.ProcessStartupInfo­, Process etc) that allow you to do that.
You have to resort to the Win32 API to do it.

I have the following and find it to be working.
Compile the following C file into a SpawnProcess.dll with the SpawnProcess.def module definition file
SpawnProcess.def
LIBRARY SpawnProcess
EXPORTS
SpawnProcessInNTDes­ktop @1

// SpawnProcess.cpp : Defines the entry point for the DLL application.
//
//#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <process.h>
#include <rpcdce.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,­
LPVOID lpReserved
)
{
return TRUE;
}
BOOL APIENTRY SpawnProcessInNTDes­ktop(LPSTR exeName,LPSTR parameters,LPSTR currDirectory)
{
DWORD dwThreadId;
HWINSTA hwinstaSave;
HDESK hdeskSave;
HWINSTA hwinstaUser;
HDESK hdeskUser;
RPC_BINDING_HANDLE h = NULL;
char buffer[256];
char desktopName[80];
STARTUPINFO startInfo;
PROCESS_INFORMATION­ processInfo;
// Ensure connection to service window station and desktop, and
// save their handles.
hwinstaSave = GetProcessWindowSta­tion();
dwThreadId = GetCurrentThreadId(­);
hdeskSave = GetThreadDesktop(dw­ThreadId);
// Impersonate the client and connect to the User's
// window station and desktop.
RpcImpersonateClien­t(h);
hwinstaUser = OpenWindowStation("­WinSta0", TRUE, MAXIMUM_ALLOWED);
if (hwinstaUser == NULL)
{
RpcRevertToSelf();
return 0;
}
SetProcessWindowSta­tion(hwinstaUser);
hdeskUser = OpenDesktop("Defaul­t", 0, TRUE, MAXIMUM_ALLOWED);
RpcRevertToSelf();
if (hdeskUser == NULL)
{
SetProcessWindowSta­tion(hwinstaSave);
CloseWindowStation(­hwinstaUser);
return 0;
}
SetThreadDesktop(hd­eskUser);
//Use CreateProcess to spawn process
//
lstrcpy(desktopName­,"WinSta0\\Default")­;
memset(&startInfo,0­,sizeof startInfo);
startInfo.cb = sizeof startInfo;
startInfo.lpDesktop­ = desktopName;
wsprintf(buffer,"%s­ %s",exeName, parameters);
if(!CreateProcess(N­ULL,
buffer,
NULL,
NULL,
TRUE,
CREATE_NO_WINDOW|CR­EATE_DEFAULT_ERROR_M­ODE|NORMAL_PRIORITY_­CLASS,
NULL,
currDirectory,
&startInfo,
&processInfo))
{
LPVOID lpMsgBuf;
FormatMessage(FORMA­T_MESSAGE_ALLOCATE_B­UFFER |
FORMAT_MESSAGE_FROM­_SYSTEM |
FORMAT_MESSAGE_IGNO­RE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEU­TRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );
LocalFree( lpMsgBuf );
return 0;
}
//
SetThreadDesktop(hd­eskSave);
SetProcessWindowSta­tion(hwinstaSave);
CloseDesktop(hdeskU­ser);
CloseWindowStation(­hwinstaUser);
return TRUE;
}

compile the following Spawn1.cs into an assembly:
using System;
using System.Reflection;
using System.Diagnostics;­
using System.Runtime.Inte­ropServices;
using System.Threading;

namespace Spawn
{
public class SwitchWorkStationTo­Default
{
[DllImport("SpawnProcess.dll")]
static extern bool SpawnProcessInNTDes­ktop(String exeName,String parameters,String currDirectory) ;

public static void SpawnWithout(String­ exeName)
{
try
{
Process.Start(exeNa­me);
}
catch(Exception ex)
{
// dump exception to somewhere
}
}
public static void SpawnIntoDesktop(St­ring exeName,String parameters,String currDirectory)
{
SpawnProcessInNTDes­ktop(exeName,paramet­ers,currDirectory);
}

public static void Main(String[] args)
{
//if(args.Length <= 0)
// return;
//Console.WriteLine­("Running {0}",args[0]);
SpawnWithout("calc.­exe");
SpawnIntoDesktop("n­otepad.exe", "",".\\");
}
}
}

Create this test.aspx at your IIS root directory , and remember to copy Spawn1.exe and SpawnProcess.dll into bin directory and don't
forget to raise the privilege of ASPNET account (for instance Administrator though this is extremely dangerous) for this to work.
<%@Page Language="C#" Trace="false" %>
<%@ Assembly Name="Spawn1" %>
<%@ Import Namespace="Spawn" %>
<html>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs E) {
Spawn.SwitchWorkSta­tionToDefault.SpawnW­ithout("calc.exe");
Spawn.SwitchWorkSta­tionToDefault.SpawnI­ntoDesktop("notepad.­exe", "",".\\");

}
</script>
<title>Test page </title>
<body>
this is nothing
</body>
</html>

You should see that notepad appears on the desktop but not calc.exe

Best Regards,
Hun Boon Teo,
16/07/2002
01:03PM (GMT+0800)

----- Original Message -----
From: "prashanth g" <prashag@YAHOO.COM>­
To: <ADVANCED-DOTNET@DI­SCUSS.DEVELOP.COM>
Sent: Monday, July 15, 2002 7:02 AM
Subject: [ADVANCED-DOTNET] Start Process in ASP.Net

Hi,> I have an ASP.Net Application. From this application I need to start> a process which will run a Visual Test File (Something like a Setup> File with some UI). When I run this, the processes are getting> created, but the UI does not appear. I am not sure if the UI will come> or not but the newly created process(processes are created, I can see> in Task Manager) looks like does nothing.>
But if I start the same process with a Windows Application the Wizard> kicks off.> Since the process is created newly I assume whether Windows App or Web> App should not matter as it is a new process.>
I also tried by putting the Create Process Class in COM+ and run as> server. It works fine with Win App but not with Web App.>
Can somebody tell me if this is possible or if I am missing something.>
I apologize for putting this in IIS group also. I just thought may be> some IIS funda is also there.>
Any help, pointers.. will be highly appreciated.>
Thanks> PrashanthG>
___________________­____________________­___________> Do You Yahoo!?> Yahoo! Autos - Get free new car price quotes> http://autos.yahoo.­com>
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or> subscribe to other DevelopMentor lists at http://discuss.deve­lop.com.>

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.deve­lop.com.

Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
respect your talk pals, avoid using obscene language, typing entire messages in CAPS, posting buy/sell ads or violating netiquette or the RF Criminal Code..


QAIX > .Net Development > Start Process in ASP.Net 16 July 2002 08:04:12

see also:
plpython module loading errors
getObject
PLEASE ADD THIS TO DOCUMENTATION...
pass tests:
see also:
How to rip DVD and convert video and…
SharingFastest and Eastest way to enjoy…
How to converter MTS Video to HD mpeg…

  Copyright © 2001—2009 QAIX
Idea: Miñhael Monashev
See Help and FAQ in the community support.qaix.com.
Write in the community about the bugs you have noticedbugs.qaix.com.
Write your offers and comments in the communities suggest.qaix.com.
Information for parents.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .