#127622 - 2004-10-08 06:02 PM
Problem publishing SW list using WMI Win32_Product
|
1984
Starting to like KiXtart
Registered: 2003-08-14
Posts: 150
|
Hi.
Env: Win 2000 SP4 Kixart 4.22 KixForms 2.3
Trying to adapt Inquisitor for my use, found some problems which I need some guide ness:
$pc = $Windows.Items.Add("Apps") $pc.SubItems(1).text = WMIQuery("","Win32_Product",$TextBox4.Text)[0] $WindowsPBar.value = $WindowsPBar.value + 1 Want to use WMI Win32_Product to publish a list of installed softwares, Name, Version, identifynignumber and installed date, in a TabControl form.
And also the Printer part is not working:
$printers = WMIQuery("DriverName","Win32_Printer",$TextBox4.Text,"SystemName",$TextBox4.Text) For Each $p In $printer $pc = $Hardware.Items.Add("Printer") $pc.SubItems(1).text = $p Next
My last wonder is if its possible to edit a readed value listed in a TabControl form:
$pc = $IntExp.Items.Add("ProxyServer") $pc.SubItems(1).text = ReadValue('\\'+$TextBox4.Text+'\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings','ProxyServer') $IntExpPBar.Value = $IntExpPBar.Value + 1
Now when the "Proxy Server" value is readed from target registry and listded i Tab Control form, I want to change the "Proxy Server" value to something esle and make it write the new value on target registry.
Is it possible to put this functionality into the TabControl?
Grateful for any feedback!
Not a scripter
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"
|
Top
|
|
|
|
#127626 - 2004-10-09 10:19 PM
Re: Problem publishing SW list using WMI Win32_Product
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Looking at the part for "Win32_Product".
I think your WMI_Query call is not correct. You have a null first parameter. I think you should have something there. Also I think you need to process all products found, not just the first as signified by the [0]
Code:
$stuff = WMIQuery("Caption","Win32_Product") for each $thing in $stuff ? $thing next
|
Top
|
|
|
|
#127629 - 2004-10-10 12:03 AM
Re: Problem publishing SW list using WMI Win32_Pro
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
This is the code to get the data you want. I sadly have never written a Kixforms script so I can help you load the Tab control.
I have provided you the KiXtart variables that you can feed into the Kixform control. You may know how to do that or someone else may be able to assist you. Code:
$objWMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" + @WKSTA) $Products = $objWMI.ExecQuery("select Name, Version, InstallDate, IdentifyingNumber from Win32_Product") For Each $item In $Products
$Name = $item.Name $Version = $item.Version $InstallDate = $item.InstallDate $IdentifyingNumber = $item.IdentifyingNumber
? $Name ? $Version ? $InstallDate ? $IdentifyingNumber ? Next $objWMI = 0
|
Top
|
|
|
|
#127631 - 2004-10-10 01:10 AM
Re: Problem publishing SW list using WMI Win32_Pro
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Ok, using Howard's code as a base, here it is "wrapped-up" in a ListView, inside a TabControl, in a Form ... in the FILE menu, select "Load Products" to load the products into the ListView ... we can talk about updating the listview later, after you study this code ...
Code:
Break On
$System = CreateObject("Kixtart.System")
$Form = $System.Form() $Form.ClientSize = 400,400
$MainMenu = $System.MainMenu
$FileMenu = $MainMenu.MenuItems.Add("File") $LoadMenu = $FileMenu.MenuItems.Add("Load Products") $LoadMenu.OnClick = "LoadClick()"
$ExitMenu = $FileMenu.MenuItems.Add("Exit") $ExitMenu.OnClick = "quit"
$Form.Menu = $MainMenu
$TabControl = $Form.TabControl() $TabControl.Dock = "Fill"
$TabPage = $TabControl.TabPages.Add("Products")
$ListView = $TabPage.ListView() $ListView.Dock = "Fill"
$Column = $ListView.Columns.Add("Name") $Column = $ListView.Columns.Add("Version") $Column = $ListView.Columns.Add("InstallDate") $Column = $ListView.Columns.Add("IndentifyingNumber")
$Form.Center() $Form.Show() While $Form.Visible $= Execute($Form.DoEvents) Loop
Exit 1
Function LoadClick()
Dim $objWMI, $products, $product, $item
$objWMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" + @WKSTA)
$products = $objWMI.ExecQuery("select Name, Version, InstallDate, IdentifyingNumber from Win32_Product")
$ListView.Items.Clear() $Form.Cursor = 11 $ListView.BeginUpdate()
For Each $product In $products
$item = $ListView.Items.Add($product.Name) $item.SubItems(1).Text = $product.Version $item.SubItems(2).Text = $product.InstallDate $item.SubItems(3).Text = $item.IndentifyingNumber
$= $Form.DoEvents(1) ;; refresh gui while loading values
Next
$ListView.EndUpdate() $Form.Cursor = 0
$objWMI = 0
EndFunction
|
Top
|
|
|
|
#127634 - 2004-10-10 04:36 AM
Re: Problem publishing SW list using WMI Win32_Pro
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
IndentifyingNumber should be IdentifyingNumber ... just a typo. Here's a changed version of the above script if you want to change a value in the listview. If you need to actually remove and re-insert a record, thats a different story.
Code:
Break On
$System = CreateObject("Kixtart.System")
$Form = $System.Form() $Form.ClientSize = 400,400
$MainMenu = $System.MainMenu
$FileMenu = $MainMenu.MenuItems.Add("File") $LoadMenu = $FileMenu.MenuItems.Add("Load Products") $LoadMenu.OnClick = "LoadClick()"
$ExitMenu = $FileMenu.MenuItems.Add("Exit") $ExitMenu.OnClick = "quit"
$Form.Menu = $MainMenu
$TabControl = $Form.TabControl() $TabControl.Dock = "Fill" $TabPage = $TabControl.TabPages.Add("Products")
$ListView = $TabPage.ListView() $ListView.Dock = "Fill" $ListView.OnDoubleClick = "ListViewDoubleClick()"
$Column = $ListView.Columns.Add("Name") $Column = $ListView.Columns.Add("Version") $Column = $ListView.Columns.Add("InstallDate") $Column = $ListView.Columns.Add("IdentifyingNumber")
$Form.Center() $Form.Show() While $Form.Visible $= Execute($Form.DoEvents) Loop
Exit 1
Function LoadClick()
Dim $objWMI, $products, $product, $item
$objWMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" + @WKSTA)
$products = $objWMI.ExecQuery("select Name, Version, InstallDate, IdentifyingNumber from Win32_Product")
$ListView.Items.Clear() $Form.Cursor = 11 $ListView.BeginUpdate()
For Each $product In $products
$item = $ListView.Items.Add($product.Name) $item.SubItems(1).Text = $product.Version $item.SubItems(2).Text = $product.InstallDate $item.SubItems(3).Text = $product.IdentifyingNumber
$= $Form.DoEvents(1) ;; refresh gui while loading values
Next
$ListView.EndUpdate() $Form.Cursor = 0
$objWMI = 0
EndFunction
Function ListViewDoubleClick()
Dim $version, $newVersion
$version = $ListView.SelectedItem.SubItems(1).Text
$newVersion = $System.InputBox.Show("Enter new version","Script",$Version)
If $newVersion
$ListView.SelectedItem.SubItems(1).Text = $newVersion
Endif
EndFunction
|
Top
|
|
|
|
#127636 - 2004-10-17 04:55 PM
Re: Problem publishing SW list using WMI Win32_Pro
|
1984
Starting to like KiXtart
Registered: 2003-08-14
Posts: 150
|
I'll tried to use your code and adapt it to mine, but no success :-( . I need to restate what im trying to do:
I have a TabControl with 4 TabPage. "Hardware", "Software", "OS Details" and "Software" In the "OS Details" when the "OS Details Update" button is clicked it will read several registry key values and publish the 2 columns "Object" and "Value" in the ListView for "OS Details" .
e.g. Object -------------------- Value ProxyServer -------------- www.proxy-server.com SystemPath --------------- %SystemRoot%\system32;%SystemRoot%;C:\Program Files\ATI Technologies\ATI Control Panel;
and so on.....
So far so good.
Now I want to make some changes to readed values in the 2nd column "Value":
e.g double click on "Value" column for "SystemPath", remove the part "C:\Program Files\ATI Technologies\ATI Control Panel;". Then Changes the "www.proxy-server.com" to "www.pserver.com".
And when I have done all changes push a button and write back the changes to to targets regisrty keys.
Here is the code i use:
;************* TABCONTROL1 ************** $TabControl1 = $Form.Controls.TabControl() $TabControl1.Bounds = 15,175,460,300 $TabControl1.FontSize = 8 $TabControl1.FlatStyle = 2
$TabPage3 = $TabControl1.TabPages.Add $TabPage3.Text = " OS Details"
;************* OS Details************** $OSD = $TabPage3.Controls.ListView $OSD.AllowColumnReorder = "True" $OSD.Anchor = 5 $OSD.AutoArrange = "False" $OSD.BackColor = 255,255,255 $OSD.BorderStyle = 2 $OSD.CheckBoxes = "False" $OSD.Enabled = "True" $OSD.FontBold = "False" $OSD.FontItalic = "False" $OSD.FontName = "Tahoma" $OSD.FontSize = 8 $OSD.FontUnderline = "False" $OSD.ForeColor = 0,0,0 $OSD.FullRowSelect = "True" $OSD.GridLines = "True" $OSD.Height = 225 $OSD.HeaderStyle = 2 $OSD.HideSelection = "True" $OSD.LabelEdit = "True" ; <---- If "True" I can change values for first column "Object". But it is not here the changes should be!!) $OSD.LabelWrap = "False" $OSD.Left = 12 $OSD.MultiSelect = "False" $OSD.TabStop = "False" $OSD.Tag = "" $OSD.ToolTipText = "" $OSD.Top = 15 $OSD.View = 1 $OSD.Visible = "True" $OSD.Width = 425
$=$OSD.Columns.Add("Object",150) ; <--------- First column, e.g. "ProxyServer" (Not to be changed!) $=$OSD.Columns.Add("Value",200) ; <--------- 2nd column, e.g. "www.proxy-server.com" (Here i want to changed listed value, after its published) ;*************************************
;************* OS Details Update ************** $OSDUpdate = $TabPage3.Controls.ToolButton $OSDUpdate.Anchor = 5 $OSDUpdate.TextAlign = 32 $OSDUpdate.Enabled = "False" $OSDUpdate.FlatStyle = 2 $OSDUpdate.FontBold = "False" $OSDUpdate.FontItalic = "False" $OSDUpdate.FontName = "Tahoma" $OSDUpdate.FontSize = 8 $OSDUpdate.FontUnderline = "False" $OSDUpdate.ForeColor = 0,0,0 $OSDUpdate.Height = 24 $OSDUpdate.icon = 5 $OSDUpdate.Left = 415 $OSDUpdate.Style = 1 $OSDUpdate.TabStop = "True" $OSDUpdate.Tag = "" $OSDUpdate.Text = "" $OSDUpdate.ToolTipText = "" $OSDUpdate.Top = 245 $OSDUpdate.Visible = "True" $OSDUpdate.Width = 22 $OSDUpdate.OnClick = "OSDC()" ;*************************************
Function OSDC() $OSD.Items.Clear $pc = $OSD.Items.Add("ProxyServer") $pc.SubItems(1).text = ReadValue('\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings','ProxyServer') $pc = $OSD.Items.Add("SystemPath") $pc.SubItems(1).text = ReadValue('\HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment','Path')
;..... and so on
$OSDUpdate.pushed = "False" EndFunction
What 2 do? /C
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 515 anonymous users online.
|
|
|