Use WMI to get Script Host Error Content?

rated by 0 users
Not Answered This post has 0 verified answers | 1 Reply | 1 Follower

Not Ranked
4 Posts
Jeremy Main posted on 05-07-2012 8:21 PM

I work at a company that has many VBScripts that regularly have error messages. Until recently we had to go into the server and look for these errors. I have put together a script using:

Get-Process| Where-Object {$_.ProcessName -eq "wscript" -and $_.mainwindowtitle -eq "Windows Script Host"}


$NewErrorScript = Get-WmiObject win32_process -Filter "name='wscript.exe'" | Select-Object Commandline

This is working well to determine if a specific script has a error message open, however I would like to know if there is any way to tell the error reason. Is there any way to get more information or the complete error message? In addition,  a way to read any open message box content would also be very helpful. Thanks!

All Replies

Not Ranked
4 Posts

I did some research, and it appears that the user32.dll has a GetWindowText function. The website showed the use of C# code and I listed it below. I am fairly new to powershell and am very new to C#. Is anyone familiar with this? I might be on the wrong forum with this. Thanks.

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

Page 1 of 1 (2 items) | RSS
Copyright 2012 All rights reserved.