Use WMI to get Script Host Error Content?

rated by 0 users
This post has 1 Reply | 1 Follower

Not Ranked
Posts 4
Jeremy Main Posted: 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"}

with

$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!

Not Ranked
Posts 4

I did some research, and it appears that the user32.dll has a GetWindowText function. The website pinvoke.net 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 PowerShell.com. All rights reserved.