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.