1

I have a vbs script, which runs fine by itself or running via a batch file. However when I trigger the same script in my console demo app, I get a vbs script error about not being able to create "the ActiveX Component can't be created".

Code in Console:

{
        Console.WriteLine("Triggering VBS Script");
        var cmd = @"C:\Users\ehubba\Desktop\ClientHealth\SCCMClientActionCount.vbs";

        var process = new Process
        {
            StartInfo = new ProcessStartInfo
            {
                Arguments = cmd,
                FileName = @"cscript",
                CreateNoWindow = true,
                UseShellExecute = false,
                Verb = "runas",
                WindowStyle = ProcessWindowStyle.Normal
            }
        };

        try
        {
            process.Start();
            process.WaitForExit();
            System.Console.WriteLine(process.ExitCode);
            process.Close();
        }
        catch (Exception ex)
        {
            System.Console.WriteLine(ex.ToString());
        }

        Console.ReadKey();}

Note: I've tried different variations of the StartInfo (Working Directory, Filename, arguments, etc all resulting in the same error).

The main goal I'm trying to do here is run a vbs script which will tally SCCM Client actions and return the value in the Exit Code.

**UPDATE VBS Code

    Dim ArrayAction
Dim cpApplet
Dim actions
Dim countAction
Dim action

Set cpApplet = CreateObject("CPAPPLET.CPAppletMgr")
Set actions = cpApplet.GetClientActions
If Err.Number = 0 Then
    countAction = 0 
    For Each action In actions      
        countAction = countAction + 1
    Next
End If
WScript.QUIT(countAction)

*UPDATE 2: In my c# app in the Process.Start if I add a username and password to the StartInfo it will work. I'm running the Console as myself, however it will fail if I don't enter my credentials into the Process.Start. Can someone explain as this is not a viable option for me.

Edmound
  • 19
  • 3
  • 1
    You need to run it with cscript.exe not the default wscript if it writes or reads StdIn/Out. –  Dec 13 '16 at 23:12
  • yep tried that. The difference only is wscript I get a popup with the error whereas the cscript the error displays on the console. – Edmound Dec 14 '16 at 14:37
  • @Edmound You need to show the code for the VBS file the error is there. It's likely permissions though if it works via another method. – user692942 Dec 14 '16 at 19:10
  • 1
    Are you launching it from a 64-bit executable? That is, your "demo console app" may be a 64-bit executable trying to invoke a 32-bit COM DLL in process. – David W Dec 14 '16 at 19:33
  • @Lankymart I've updated my question with the code. – Edmound Dec 14 '16 at 19:33
  • tried both, the issue looks to be permission. So question when running Process.Start, what default permissions is it using? I would have figured it would have used my own since I launched the application. – Edmound Dec 14 '16 at 19:34
  • Think @DavidW probably right if your running that 64 bit and the DLL is 32 bit it won't find the progid in the registry hence the error. – user692942 Dec 14 '16 at 19:39
  • While this answer was for Classic ASP it also applies for VBScript - [A: Error ASP 0177: 8007007e Server.CreateObject fails for COM DLL](http://stackoverflow.com/a/35985827/692942), gives a comprehensive breakdown. – user692942 Dec 14 '16 at 19:46
  • This wasn't answered. The VBS isn't in question. For some reason the c# Process.Start doesn't work, unless you enter credentials. Not sure why this is. I figured since I launched the Console app, it was using my credentials. – Edmound Dec 14 '16 at 20:32

0 Answers0