I have a website where my projects DLL has maximum trust and the website
runs under an admin account!
I get this error:
Error: You have to be a machine admin to perform this operation.
I've seen this code working with ASP and
Server.CreateOb ject("WScript.S hell")
Why doesn't it work with C#?
This is my code:
public class FrontPageWeb
{
System.Diagnost ics.ProcessStar tInfo startinfo;
System.Diagnost ics.Process process = null;
string stdoutline;
System.IO.Strea mReader stdoutreader;
private string username,websit e,fp,exe;
public string Username
{
set{username=va lue;}
}
public string WebSiteNumber
{
set{website=val ue;}
}
public string Activate()
{
exe = @"C:\Program Files\Common Files\Microsoft Shared\web server
extensions\50\b in\owsadm.exe";
fp = " -o install -u "+username+ " -t msiis -m "+website+" -p 80";
try
{
startinfo = new System.Diagnost ics.ProcessStar tInfo();
startinfo.FileN ame = exe;
startinfo.Argum ents = fp;
startinfo.UseSh ellExecute = false;
startinfo.Redir ectStandardOutp ut = true;
startinfo.Creat eNoWindow = true;
process = System.Diagnost ics.Process.Sta rt(startinfo);
stdoutreader = process.Standar dOutput;
System.Text.Str ingBuilder stdoudtotal = new System.Text.Str ingBuilder("");
while((stdoutli ne=stdoutreader .ReadLine())!= null)
{
stdoudtotal.App end( "> " + stdoutline.ToSt ring() + "\n" );
}
stdoutreader.Cl ose();
stdoutreader = null;
if ( process.ExitCod e == 0 )
{
return stdoudtotal.ToS tring();
}
else
{
return stdoudtotal.ToS tring();
}
}
catch(System.Ex ception exc)
{
return exc.ToString();
}
finally
{
if (process != null)
{
process.Close() ;
}
process = null;
startinfo = null;
}
}
}
Regards
Anders
runs under an admin account!
I get this error:
Error: You have to be a machine admin to perform this operation.
I've seen this code working with ASP and
Server.CreateOb ject("WScript.S hell")
Why doesn't it work with C#?
This is my code:
public class FrontPageWeb
{
System.Diagnost ics.ProcessStar tInfo startinfo;
System.Diagnost ics.Process process = null;
string stdoutline;
System.IO.Strea mReader stdoutreader;
private string username,websit e,fp,exe;
public string Username
{
set{username=va lue;}
}
public string WebSiteNumber
{
set{website=val ue;}
}
public string Activate()
{
exe = @"C:\Program Files\Common Files\Microsoft Shared\web server
extensions\50\b in\owsadm.exe";
fp = " -o install -u "+username+ " -t msiis -m "+website+" -p 80";
try
{
startinfo = new System.Diagnost ics.ProcessStar tInfo();
startinfo.FileN ame = exe;
startinfo.Argum ents = fp;
startinfo.UseSh ellExecute = false;
startinfo.Redir ectStandardOutp ut = true;
startinfo.Creat eNoWindow = true;
process = System.Diagnost ics.Process.Sta rt(startinfo);
stdoutreader = process.Standar dOutput;
System.Text.Str ingBuilder stdoudtotal = new System.Text.Str ingBuilder("");
while((stdoutli ne=stdoutreader .ReadLine())!= null)
{
stdoudtotal.App end( "> " + stdoutline.ToSt ring() + "\n" );
}
stdoutreader.Cl ose();
stdoutreader = null;
if ( process.ExitCod e == 0 )
{
return stdoudtotal.ToS tring();
}
else
{
return stdoudtotal.ToS tring();
}
}
catch(System.Ex ception exc)
{
return exc.ToString();
}
finally
{
if (process != null)
{
process.Close() ;
}
process = null;
startinfo = null;
}
}
}
Regards
Anders
Comment