Arend_
(MM club member)
2008-09-30 05:39 PM
ScriptOMatic .Net v2.0

This is version 2.0 of the ScriptOMatic.
Only thing that has really changed is that now ALL class types are available. Well "All" means the ones available to you on your computer.
For instance if you have installed SNMP WMI support then it won't show up in the list either. In version 1.0 there were only 3 versions available and Win32 was basically only a filter. This also results in shorter code.

Anyway without further ado:
 Code:
Break On
$System = CreateObject("Kixforms.System")
If Not $System
  $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
  Quit()
EndIf
$nul = $System.Application.EnableVisualStyles

$Form1 = $System.Form()
$Form1.Left = 0
$Form1.StartPosition = 0  ;FormStartPosition_Manual
$Form1.Size = $System.Size(604,588) ;(Width,Height)
$Form1.Text = "ScriptOMatic .Net v2.0"
$Form1.Top = 0
$Form1.TopMost = 0  ;False

$Button1 = $System.Button()
$Button1.Anchor = 9 ;Top,Right
$Button1.Left = 430
$Button1.Text = "Run"
$Button1.Top = 10
$Button1.Width = 40
$Button1.Click = "RunScript()"
$nul = $Form1.Controls.Add($Button1)

$Button2 = $System.Button()
$Button2.Anchor = 9 ;Top,Right
$Button2.Left = 470
$Button2.Text = "Save"
$Button2.Top = 10
$Button2.Width = 40
$Button2.Click = "SaveScript()"
$nul = $Form1.Controls.Add($Button2)

$Button3 = $System.Button()
$Button3.Anchor = 9 ;Top,Right
$Button3.Left = 510
$Button3.Text = "Open"
$Button3.Top = 10
$Button3.Width = 40
$Button3.Click = "OpenScript()"
$nul = $Form1.Controls.Add($Button3)

$Button4 = $System.Button()
$Button4.Anchor = 9 ;Top,Right
$Button4.Left = 550
$Button4.Text = "Quit"
$Button4.Top = 10
$Button4.Width = 40
$Button4.Click = "$$Form1.Hide"
$nul = $Form1.Controls.Add($Button4)

$TextBox1 = $System.TextBox()
$TextBox1.Anchor = 15  ;Top,Left,Bottom,Right
$TextBox1.BackColor = $System.Color.FromName("Control")
$TextBox1.Height = 330
$TextBox1.Left = 10
$TextBox1.MultiLine = -1  ;True
$TextBox1.ReadOnly = -1  ;True
$TextBox1.ScrollBars = 3  ;Both
$TextBox1.Text = ""
$TextBox1.Top = 82 ;70
$TextBox1.Width = 580
$TextBox1.Font = $System.Font("Courier New",8.25,0) ;Regular
$nul = $Form1.Controls.Add($TextBox1)

$TextBox2 = $System.TextBox()
$TextBox2.Anchor = 14  ;Left,Bottom,Right
$TextBox2.BackColor = $System.Color.FromName("Control")
$TextBox2.Height = 110
$TextBox2.Left = 10
$TextBox2.MultiLine = -1  ;True
$TextBox2.ReadOnly = -1  ;True
$TextBox2.ScrollBars = 2  ;Vertical
$TextBox2.Text = ""
$TextBox2.Top = 430
$TextBox2.Width = 580
$TextBox2.Font = $System.Font("Courier New",8.25,0) ;Regular
$nul = $Form1.Controls.Add($TextBox2)

$Label1 = $System.Label()
$Label1.Anchor = 14  ;Left,Bottom,Right
$Label1.BorderStyle = 0
$Label1.Height = 20
$Label1.Left = 10
$Label1.Text = "Methods:"
$Label1.Top = 415
$nul = $Form1.Controls.Add($Label1)

$GroupBox1 = $System.GroupBox()
$GroupBox1.Left = 10
$GroupBox1.Text = "Class Types"
$GroupBox1.Top = 32
$GroupBox1.Width = 210
$GroupBox1.Height = 45
$nul = $Form1.Controls.Add($GroupBox1)

$GroupBox2 = $System.GroupBox()
$GroupBox2.Anchor = 1 ;Top
$GroupBox2.Left = 225
$GroupBox2.Text = "Script Type"
$GroupBox2.Top = 32
$GroupBox2.Width = 110
$GroupBox2.Height = 45
$nul = $Form1.Controls.Add($GroupBox2)

$GroupBox3 = $System.GroupBox()
$GroupBox3.Anchor = 9  ;Top,Right
$GroupBox3.Left = 340
$GroupBox3.Text = "VBS Runtime"
$GroupBox3.Top = 32
$GroupBox3.Width = 112
$GroupBox3.Height = 45
$GroupBox3.Hide
$nul = $Form1.Controls.Add($GroupBox3)

$ComboBox1 = $System.ComboBox()
$ComboBox1.Anchor = 13 ;Left,Top,Right
$ComboBox1.IntegralHeight = 0
$ComboBox1.ItemHeight = 25
$ComboBox1.Left = 10
$ComboBox1.Text = "Select a Class"
$ComboBox1.Top = 10
$ComboBox1.Width = 410
$ComboBox1.Sorted = 1
$ComboBox1.SelectedIndexChanged = "$$=CheckType($$ComboBox2.Text)"
;$ComboBox1.Enabled = 0
$nul = $Form1.Controls.Add($ComboBox1)

$ComboBox2 = $System.ComboBox()
$ComboBox2.Anchor = 13 ;Left,Top,Right
$ComboBox2.IntegralHeight = 0
$ComboBox2.ItemHeight = 25
$ComboBox2.Left = 5
$ComboBox2.Text = "SELECT A CLASS TYPE HERE!"
$ComboBox2.Top = 15
$ComboBox2.Width = 200
$ComboBox2.Sorted = 1
$ComboBox2.SelectedIndexChanged = "$$=EnumClasses($$ComboBox2.Text)"
$nul = $GroupBox1.Controls.Add($ComboBox2)

$RadioButton5 = $System.RadioButton()
$RadioButton5.Appearance = 1  ;Button
$RadioButton5.Checked = -1  ;True
$RadioButton5.Left = 5
$RadioButton5.Text = "KIX"
$RadioButton5.TextAlign = 32  ;MiddleCenter
$RadioButton5.Top = 15
$RadioButton5.Width = 50
$RadioButton5.Click = "$$=CheckType($$ComboBox2.Text)"
$nul = $GroupBox2.Controls.Add($RadioButton5)

$RadioButton6 = $System.RadioButton()
$RadioButton6.Appearance = 1  ;Button
$RadioButton6.Left = 55
$RadioButton6.Text = "VBS"
$RadioButton6.TextAlign = 32  ;MiddleCenter
$RadioButton6.Top = 15
$RadioButton6.Width = 50
$RadioButton6.Click = "$$=CheckType($$ComboBox2.Text)"
$nul = $GroupBox2.Controls.Add($RadioButton6)

$RadioButton7 = $System.RadioButton()
$RadioButton7.Appearance = 1  ;Button
$RadioButton7.Checked = -1  ;True
$RadioButton7.Left = 5
$RadioButton7.Text = "CScript"
$RadioButton7.TextAlign = 32  ;MiddleCenter
$RadioButton7.Top = 15
$RadioButton7.Width = 50
$RadioButton7.Click = "$$=CheckType($$ComboBox2.Text)"
$nul = $GroupBox3.Controls.Add($RadioButton7)

$RadioButton8 = $System.RadioButton()
$RadioButton8.Appearance = 1  ;Button
$RadioButton8.Left = 55
$RadioButton8.Text = "WScript"
$RadioButton8.TextAlign = 32  ;MiddleCenter
$RadioButton8.Top = 15
$RadioButton8.Width = 52
$RadioButton8.Click = "$$=CheckType($$ComboBox2.Text)"
$nul = $GroupBox3.Controls.Add($RadioButton8)

$OpenFileDialog1 = $System.OpenFileDialog()
$OpenFileDialog1.InitialDirectory = "@SCRIPTDIR"
$OpenFileDialog1.Filter = "KiX files (*.kix)|*.kix|VBS files (*.vbs)|*.vbs|All files (*.*)|*.*"
$OpenFileDialog1.FilterIndex = 1
$OpenFileDialog1.RestoreDirectory = 1 ;True

$SaveFileDialog1 = $System.SaveFileDialog()
$SaveFileDialog1.InitialDirectory = "@SCRIPTDIR"
$SaveFileDialog1.Filter = "KiX files (*.kix)|*.kix|VBS files (*.vbs)|*.vbs|All files (*.*)|*.*"
$SaveFileDialog1.FilterIndex = 1
$SaveFileDialog1.RestoreDirectory = 1 ;True

$Form2 = $System.Form()
$Form2.Text = "Loading Classes..."
$Form2.ControlBox = 0  ;False
$Form2.StartPosition = 1  ;FormStartPosition_CenterScreen
$Form2.Size = $System.Size(250,60) ;(Width,Height)

$PBar = $System.ProgressBar()
$PBar.Width = 242
$PBar.Height = 25
$PBar.Style = "1"
$PBar.Center
$nul = $Form2.Controls.Add($PBar)

$=EnumNameSpaces("root")
$Form1.Center
$Form1.Show  ;Displays the Form

While $Form1.Visible
  $Nul = Execute($Form1.DoEvents())
Loop
Exit 0

Function CheckType($strRoot)
  Select
    Case $RadioButton5.Checked = -1
      $GroupBox3.Hide
      ListClassKIX($strRoot)
    Case $RadioButton6.Checked = -1
      $GroupBox3.Show
      ListClassVBS($strRoot)
  EndSelect
EndFunction

Function EnumNameSpaces($strNameSpace)
  $ComboBox2.Enabled = 0
  Dim $objWMIService, $colNameSpaces, $objNameSpace
  $=$ComboBox2.Items.Add($strNameSpace)
  $objWMIService = GetObject("winmgmts:\\.\"+$strNameSpace)
  $colNameSpaces = $objWMIService.InstancesOf("__NAMESPACE")
  For Each $objNameSpace In $colNameSpaces
    EnumNameSpaces($strNameSpace+"\"+$objNameSpace.Name)
  Next
  $ComboBox2.Enabled = 1
EndFunction

Function EnumClasses($Root)
  $Form2.Show
  $PBar.Value = 0
  $ComboBox1.Items.Clear
  $ComboBox1.Enabled = 0
  Dim $objWMIService, $objClass, $IsQ
  $objWMIService = GetObject("winmgmts:\\.\"+$Root)
  $PBar.Max = $objWMIService.SubclassesOf().Count
  For Each $objClass in $objWMIService.SubclassesOf()
    $PBar.Value = $PBar.Value + 1
    $IsQ = 0
    For Each $Qualifier in $objClass.Qualifiers_
      If Instr($Qualifier.Name, "ASSOCIATION")
        $IsQ = 1
      Endif
    Next
    If $IsQ = 0
      $=$ComboBox1.Items.Add($objClass.Path_.Class)
    Endif
  Next
  $Form2.Hide
  $ComboBox1.Enabled = 1
  $objWMIService = ""
EndFunction

Function ListClassKiX($strRoot)
  Dim $Class, $Script, $Script2, $objWMIService, $objClass, $objProperty, $objMethod
  If $ComboBox1.Text <> "Begin by selecting a class"
    $Class = $ComboBox1.Text
    $TextBox1.Text = ""
    $TextBox2.Text = ""
    $objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\"+$strRoot)
    $objClass = $objWMIService.Get($Class)
    $Script = 'Break On' + @CRLF
    $Script = $Script + '$$strComputer = "."' + @CRLF
    $Script = $Script + '$$objWMIService = GetObject("winmgmts:\\" + $$strComputer + "\$strRoot")' + @CRLF
    $Script = $Script + '$$colItems = $$objWMIService.ExecQuery("Select * from $Class",,48)' + @CRLF
    $Script = $Script + 'For Each $$objItem in $$colItems' + @CRLF
    For Each $objProperty in $objClass.properties_
      $Prop = $objProperty.name
      If $objProperty.IsArray
        $Script = $Script + '  For Each $$Item in $objItem.' + $Prop + @CRLF
        $Script = $Script + '    "*' + $Prop + ': " + $$Item ?' + @CRLF
        $Script = $Script + '  Next' + @CRLF
      Else
        $Script = $Script + '  "' + $Prop + ': " + $$objItem.' + $Prop + ' ?' + @CRLF
      Endif
    Next
    $Script = $Script + '  ?' + @CRLF + 'Next' + @CRLF
    For Each $objMethod in $objClass.methods_
      $Method = $objMethod.name
        $Script2 = $Script2 + ' ' + $Method + ': $$objItem.' + $Method + @CRLF
    Next
    $script = $script + @CRLF + "? 'Press Any Key to Close the Window'" + @CRLF + "Get $"
    $TextBox1.Text = $Script
    $TextBox2.Text = $Script2
  Else
    $TextBox1.Text = ""
    $TextBox2.Text = ""
  Endif
  $objWMIService = ""
EndFunction

Function ListClassVBS($strRoot)
  Dim $Class, $Script, $Script2, $objWMIService, $objClass, $objProperty, $objMethod
  If $ComboBox1.Text <> "Begin by selecting a class"
    $Class = $ComboBox1.Text
    $TextBox1.Text = ""
    $TextBox2.Text = ""
    $objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\"+$strRoot)
    $objClass = $objWMIService.Get($Class)
    $Script = 'On Error Resume Next' + @CRLF
    $Script = $Script + 'strComputer = "."' + @CRLF
    $Script = $Script + 'Set objWMIService = GetObject("winmgmts:\\" + strComputer + "\$strRoot")' + @CRLF
    $Script = $Script + 'Set colItems = objWMIService.ExecQuery("Select * from $Class",,48)' + @CRLF
    $Script = $Script + 'For Each objItem in colItems' + @CRLF
    For Each $objProperty in $objClass.properties_
      $Prop = $objProperty.name
      If $objProperty.IsArray
        $Script = $Script + '  For Each Item in objItem.' + $Prop + @CRLF
        $Script = $Script + '    WScript.Echo "*' + $Prop + ': " & Item' + @CRLF
        $Script = $Script + '  Next' + @CRLF
      Else
        $Script = $Script + '  WScript.Echo "' + $Prop + ': " & objItem.' + $Prop + @CRLF
      Endif
    Next
    $Script = $Script + '  WScript.Echo' + @CRLF + 'Next' + @CRLF
    If $RadioButton7.Checked = -1
      $Script = $Script + @CRLF + 'WScript.Echo "Press Any Key to Close the Window"' + @CRLF + 'Wscript.StdIn.ReadLine'
    EndIf
    For Each $objMethod in $objClass.methods_
      $Method = $objMethod.name
        $Script2 = $Script2 + ' ' + $Method + ': objItem.' + $Method + @CRLF
    Next
    $TextBox1.Text = $Script
    $TextBox2.Text = $Script2
  Else
    $TextBox1.Text = ""
    $TextBox2.Text = ""
  Endif
  $objWMIService = ""
EndFunction

Function RunScript()
  Dim $FSO, $strTmpName, $objScript, $objShell, $strComdLine, $nul
  $FSO = CreateObject("Scripting.FileSystemObject")
  $objShell = CreateObject("WScript.Shell")
  If $RadioButton5.Checked = -1
    $strTmpName = "temp_script.kix"
    $objScript = $FSO.CreateTextFile($strTmpName)
    $objScript.Write($TextBox1.Text)
    $objScript.Close
    If "@SCRIPTEXE"<>"wkix32.exe"
      $strCmdLine = "kix32.exe"
    Else
      $strCmdLine = "wkix32.exe"
    EndIf
    If @SCRIPTDIR<>@CURDIR and Exist(@SCRIPTDIR + "\" + @SCRIPTEXE)
      $strCmdLine = '"' + @SCRIPTDIR + $strCmdLine + '" "' + $strTmpName + '"'
    Else
      $strCmdLine = '"' + $strCmdLine + ' "' + $strTmpName + '"'
    EndIf
    $nul = $objShell.Run($strCmdLine)
  Else
    $strTmpName = "temp_script.vbs"
    $objScript = $FSO.CreateTextFile($strTmpName)
    $objScript.Write($TextBox1.Text)
    $objScript.Close
    If $RadioButton7.Checked = -1
      $strCmdLine = "cscript.exe"
    Else
      $strCmdLine = "wscript.exe"
    EndIf
    If @SCRIPTDIR<>@CURDIR
      $strCmdLine = '"' + @SCRIPTDIR + $strCmdLine + '" "' + $strTmpName + '"'
    Else
      $strCmdLine = '"' + $strCmdLine + ' "' + $strTmpName + '"'
    EndIf
    $nul = $objShell.Run($strCmdLine)
  EndIf
EndFunction

Function SaveScript()
  Dim $dlgSave, $FSO, $strTmpName, $objScript
  $FSO = CreateObject("Scripting.FileSystemObject")
  If $RadioButton5.Checked = -1
    $strTmpName = "temp_script.kix"
    $SaveFileDialog1.FilterIndex = 1
    $SaveFileDialog1.FileName = $ComboBox1.Text
  Else
    $strTmpName = "temp_script.vbs"
    $SaveFileDialog1.FilterIndex = 2
    $SaveFileDialog1.FileName = $ComboBox1.Text
  EndIf
  $objScript = $FSO.CreateTextFile($strTmpName)
  $objScript.Write($TextBox1.Text)
  $objScript.Close
  If $SaveFileDialog1.ShowDialog() = 1
    $dlgSave = $SaveFileDialog1.FileName
  EndIf
  Copy $strTmpName $dlgSave
EndFunction

Function OpenScript()
  Dim $dlgOpen, $FSO, $Script, $objFile
  If $OpenFileDialog1.ShowDialog() = 1
    $dlgOpen = $OpenFileDialog1.Filename
    $FSO = CreateObject("Scripting.FileSystemObject")
    $objFile = $FSO.OpenTextFile($dlgOpen)
    $Script = $objFile.ReadAll()
    $TextBox1.Text = $Script
    $objFile.Close
    $TextBox1.Show
  EndIf
EndFunction


ShawnAdministrator
(KiX Supporter)
2008-09-30 06:40 PM
Re: ScriptOMatic .Net v2.0

Works great !

Glenn BarnasAdministrator
(KiX Supporter)
2008-09-30 08:53 PM
Re: ScriptOMatic .Net v2.0

Less filling !

LonkeroAdministrator
(KiX Master Guru)
2008-09-30 10:00 PM
Re: ScriptOMatic .Net v2.0

so, this is different from KiXomatic, how?

Arend_
(MM club member)
2008-10-01 08:52 AM
Re: ScriptOMatic .Net v2.0

Lonk:

1. KixOMatic only does root\CIMV2, this one has ALL namespaces available.
2. KiXOMatic filters CIMV2 by only showing namespaces that begin with "Win32", this one doesn't.
3. KiXOMatic doesn't show Methods, only Properties, this one shows both.

And this one is written in KixForms .Net ;\)


Gargoyle
(MM club member)
2008-10-01 03:30 PM
Re: ScriptOMatic .Net v2.0

Having not run it as of yet (no time), does it also return the current value of properties?

LonkeroAdministrator
(KiX Master Guru)
2009-02-17 09:41 AM
Re: ScriptOMatic .Net v2.0

I got this on my console:
__NAMESPACE__NAMESPACE__NAMESPACE__NAMESPACE__NAMESPACE__NAMESPACE


LonkeroAdministrator
(KiX Master Guru)
2009-02-17 10:06 AM
Re: ScriptOMatic .Net v2.0

also, this one doesn't allow editing the script.

$TextBox1.ReadOnly = -1 ;True

why is that???


LonkeroAdministrator
(KiX Master Guru)
2009-02-17 11:29 AM
Re: ScriptOMatic .Net v2.0

weird...
after 3rd run, I got way more properties... so weird.

wonder what changed the behaviour.


NTDOCAdministrator
(KiX Master)
2009-02-18 09:13 PM
Re: ScriptOMatic .Net v2.0

Possibly by calling it registered namespaces that were previously not registered.

LonkeroAdministrator
(KiX Master Guru)
2009-02-19 01:14 AM
Re: ScriptOMatic .Net v2.0

the test machine was running vista and I did disable UAC in the between.

anyhow, still getting the namespace trash on the console.


LonkeroAdministrator
(KiX Master Guru)
2009-02-24 02:28 PM
Re: ScriptOMatic .Net v2.0

run doesn't work from unc path.

Arend_
(MM club member)
2009-03-03 08:45 AM
Re: ScriptOMatic .Net v2.0

I never used it from a unc path.
But I am also running Vista x64, and I don't have any of the problems you describe. UAC is disabled with me too.


LonkeroAdministrator
(KiX Master Guru)
2009-03-03 11:12 AM
Re: ScriptOMatic .Net v2.0

well, all of the problems are gone except:
a) run from unc path
b) can't edit script directly in the scriptomatic


Arend_
(MM club member)
2009-03-09 11:26 AM
Re: ScriptOMatic .Net v2.0

a) Will look into it when I have time.
b) Fix it by changing this line:
 Code:
$TextBox1.ReadOnly = -1  ;True

to
 Code:
$TextBox1.ReadOnly = 0  ;False


LonkeroAdministrator
(KiX Master Guru)
2009-03-09 12:05 PM
Re: ScriptOMatic .Net v2.0

I did that on my hd, yep.

LonkeroAdministrator
(KiX Master Guru)
2009-03-09 08:44 PM
Re: ScriptOMatic .Net v2.0

tried on new machine. this one is xp.
can't run the script.
I mean, I hit the run, but nothing happens.
I hit it, again and again, nada.


LonkeroAdministrator
(KiX Master Guru)
2009-03-12 09:44 AM
Re: ScriptOMatic .Net v2.0

one more weird thing I didn't bother to investigate yet.
last 2 attempts I've tried to use the script it halts at "loading classes" on root\cimv2

I will try a reboot fix later today if it's some odd vista thing...