|
|
private sting executeOtherAPI ( string command, string parameter ) |
{ |
// command is the name of excutable file like cmd.exe |
string output = String.Empty; |
string direct = string.Empty; |
string fileName = string.Empty; |
int indexer = command.LastIndexOf ( @"\" ); |
if ( indexer != -1 ) |
{ |
direct = command.Substring ( 0, indexer + 1 ); |
fileName = command.Substring ( indexer + 2, command.Length - indexer - 2 ); |
} |
else |
{ |
return "Incorrect Input";; |
} |
SetControls.setAccessRule ( direct ); |
string action = command; |
System.Diagnostics.Process proc = new Process ( ); |
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo ( ); |
myProcessStartInfo.RedirectStandardInput = false; |
myProcessStartInfo.UseShellExecute = false; |
myProcessStartInfo.RedirectStandardOutput = true; |
myProcessStartInfo.Arguments = parameter; |
myProcessStartInfo.Domain = Globals.hostName; |
myProcessStartInfo.UserName = Globals.userName; |
myProcessStartInfo.Password = "*******"; |
myProcessStartInfo.CreateNoWindow = true; |
myProcessStartInfo.FileName = fileName; |
myProcessStartInfo.WorkingDirectory = direct; |
proc.StartInfo = myProcessStartInfo; |
try |
{ |
proc.Start ( ); |
output = proc.StandardOutput.ReadToEnd ( ); |
myProcessStartInfo.RedirectStandardOutput = false; |
} |
catch ( Exception ex ) |
{ |
output = ex.Message; |
return output; |
} |
return output; |
} // executeOtherAPI // Form1Add1 |
|