'Windows Script Host Object Model'.WshShell .NET

AlexPWSAlexPWS Member Posts: 14
Does anybody know if there is a .NET assembly equivalent to the 'Windows Script Host Object Model'.WshShell. component?
I'd appreciate any suggestion. Thanks.

Answers

  • RockWithNAVRockWithNAV Member Posts: 1,139
    I also tried long back but couldn't find something similar.
  • ftorneroftornero Member Posts: 524
    Hello @AlexPWS

    Here are the variables:
    Name	DataType	Subtype	Length
    WShell	DotNet	System.Diagnostics.Process.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    ProcInfo	DotNet	System.Diagnostics.ProcessStartInfo.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    StreamReader	DotNet	System.IO.StreamReader.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    TextReader	DotNet	System.IO.TextReader.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    Lin	Text		
    

    And this is the code to the equivalent Shell in .NET:
    dotNetShell(Program2Call : Text[1024];Parameters : Text[1024];Mode : 'Silence,Text,Stream')
    ProcInfo := ProcInfo.ProcessStartInfo;
    ProcInfo.FileName := Program2Call;
    ProcInfo.Arguments := Parameters;
    ProcInfo.UseShellExecute := FALSE;
    ProcInfo.RedirectStandardOutput := TRUE;
    ProcInfo.WindowStyle := 1; // Hidden, 
    ProcInfo.CreateNoWindow := TRUE; 
    
    WShell:= WShell.Start(ProcInfo);
    
    IF Mode <> Mode::Silence THEN BEGIN
      IF (Mode = Mode::Texto) THEN BEGIN
        TextReader := WShell.StandardOutput;
        Lin := TextReader.ReadToEnd;
        MESSAGE(Lin);
      END ELSE BEGIN
        StreamReader := WShell.StandardOutput;
        WHILE NOT StreamReader.EndOfStream DO BEGIN
          Lin := StreamReader.ReadLine;
          MESSAGE(Lin);
        END;
      END;
    END;
    WShell.WaitForExit;
    

    Regards
  • RockWithNAVRockWithNAV Member Posts: 1,139
    @ftornero - This solution could come up as a work around, with Automation Windows Host Object it's merely a 2 3 lines of code which does the job. :smile:
Sign In or Register to comment.