Let the process invoke the permission problem go to hell.

Source: Internet
Author: User

Recently you need to invoke a C + + component on the server side because the component will modify a target file, so in. NET uses the process object anyway to report a read-only error.

Search for data everywhere, most people say it involves invoking component modification files. NET is not allowed to do so. I almost blacked out. But I remember using the Wscript.Shell object when I used to write an ASP. So I started experimenting with ASP, without any errors, a rapture.

Then I found a useful message to convert Wscript.Shell to a DLL and call the method directly using. Net. Methods are as follows:

• Convert COM components to. NET components

Microsoft has provided us with the Type Library Importer (importer), through which we can use COM components. After the conversion, there will be a DLL file that needs to be placed in the bin directory of the Web directory in order for the component to be used.

Although this is more than one DLL, but this DLL does not need to register can be used directly, very convenient, which is asp.net and ASP, one of the differences. Haha, some BT administrators have nothing to remove the "harmful" components, now he has no way to ^_^

Wscript.Shell object is%windir%\system32\wshom.ocx, let's get it copy out, open the Visual Studio 2005 command prompt, use the type Library Importer conversion: Tlbimp.exe Wshom.ocx/ Out:WSHomx.dll

Then put the WSHomx.dll under the bin of the Web directory. Then write the code slightly different from the previous code.

The problem was finally solved and found to be more convenient than using ASP.

All the code is as follows:

Program code

public void Receive ()
{
String request = Requesthelper.requestgetvalue ("FileName");
WshShell CMD = new WshShell ();
String result = Cmd.exec (Voicetestpath + "" + Voiceoutputpath + request + ". WAV 2"). Stdout.readall ();
Httphelper.responsewrite (Result);
//The method of calling the process is invalid
//if (!string. IsNullOrEmpty (Request))
//{
//Httphelper.responsewrite (Executebyprocess (Voicetestpath, Voiceoutput Path + request + ". WAV 2");
//}
}
///<summary>
///to perform a process transformation
///</summary>
private static Str        ing executebyprocess (string commandpath, String Arguments)
{
Process P = new process ();
 P.startinfo.useshellexecute = false; Do not use the System external shell program to activate a process
P.startinfo.createnowindow = true;//Do not create a window
P.startinfo.redirectstandardinput = False ; Do not redirect input
P.startinfo.redirectstandardoutput = true;//redirect Output,Instead of being implicitly displayed in the DOS console
p.StartInfo.FileName = Commandpath;//converter path
p.startinfo.arguments = Arguments;
Return StartProcess (P, 500);
}
///<summary>
///activation process
///</summary>
private static string St Artprocess (Process p, int milliseconds)
{
String output = ""; Output string
Try
{
if (P.start ())//START process
{
if (milliseconds = 0)
p.WaitForExit ();//This is infinite waiting for the process to end
Else
p.WaitForExit (milliseconds);//This is waiting for the process End, wait time for the specified millisecond
output = P.standardoutput.readtoend ();//Read the output of the process
}
}
Catch       
{
}
finally
{
if (P!= null)
P.close ();

return output;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.