Automatically write files and upload them to the specified server softwaremeteringcls. vbs source code

Source: Internet
Author: User

CopyCode The Code is as follows: 'filename: softwaremeteringcls. vbs
'/////////////////////////////////////// /////////////////////////////
If (wscript. scriptname = "softwaremeteringcls. vbs") then call demo_softwaremeteringcls ()

'================================================ ==================================
Function getsoftwarelist (shost)
'Callable by *. WSF; will return list (Safe array) of installed
'Software on the shost System (shost is computername or IP address ).
'
'The assumption is that shost is available and has WMI installed.

Set osoftmeter = new softwaremeteringcls
Sprogsary = osoftmeter. getlist (shost)
Set ospftmeter = nothing
Getsoftwarelist = sprogsary
End Function
'==================================== Class ======================== ======================================
Class softwaremeteringcls
'Author: Branimir Petrovic
'Date: 6 Sept 2002
'Version: 1.0.3
'
'Revision history:
'30 March 2002 v 1.0.0
'
'08 10000l 2002 v 1.0.1
'Added error handling-if the target system is not present,
'Or does not have WMI, getlist (shost) will return empty list.
'
'Addglobal function getsoftwarelist (shost) to be used
'From *. WSF scripts when caller script is JScript (since
'Jscript can not instantiate vbs classes directly ).
'
'21 then l 2002 v 1.0.2
'Replace "[" with "(" and "]" with ")" in "displayname"
'Some strings like: [see q311401 for more information]
'Can cause troubles, therefore replacement.
'
'6 Sept 2002 v 1.0.3
'Win2k' s SP3 for Windows 2000 introduced slight (but silent)
''Improvement ''In A Way registry provder's enumvalues Method
'Deals with empty keys. enumvalues method called against
'Keys without any values (partition t the default, empty value)
'Will now return null value (previously array of size 0 was
'Returned). Added (previusly unneeded) type checking...
'
'
'Dependances:
'Wsh 5.6
'
'Methods:
'-Getclassname ()
'-Getversion ()
'-Getlist (shost) shost parameter can be computer name or IP address
'Enumerates all subkeys in:
'"SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall"
'Returns array of strings, each string item containing:
'"Displaynamekeyvalue [-- version: displayversionkeyvalue]"
'
'If shost parameter is empty string or non-string value,
'Function returns list of installed software on this host.
'Otherwise it will connect to host pointed to by shost string
'(Provided sufficient level of permissions)
'
'-Gethoststring () returns name of the system or IP address

'--- Private data members
Private HKLM 'points to HKEY_LOCAL_MACHINE hive
Private uninstall_root 'Software \ Microsoft \ Windows \ CurrentVersion \ Uninstall
Private supress_hotfix_entries 'by default is true (set in class_initialize)
'(Supressess listing of installed hotfixes)
Private class_name
Private version
Private REG_SZ
Private oreg
Private scomputername

'--- Public
Public Function getclassname ()
Getclassname = class_name
End Function

Public Function getversion ()
Getversion = version
End Function

Public Function getlist (shost)
If typename (shost) = "string" and shost <> "then
Scomputername = shost
Else
Scomputername = wscript. Createobject ("wscript. Network"). computername
End if

On Error resume next
Set oreg = GetObject ("winmgmts: {impersonationlevel = impersonate }//"&_
Scomputername & "/root/Default: stdregprov ")
If err. Number <> 0 then
'Computer is not accessable or does not have WMI, return empty array
Getlist = array ()
Else
'Computer is on the network and does have working WMI,
'Return the list (Safe array) of installed software
Getlist = listinstalledprogs (oreg)
End if
On Error goto 0
End Function

Public Function gethoststring ()
Gethoststring = scomputername
End Function

'--- Private helper routines
Private sub class_initialize
'Initialize various values used by this class
HKLM = & h80000002 'hive: HKEY_LOCAL_MACHINE
Uninstall_root = "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall"
REG_SZ = 1
Supress_hotfix_entries = true
Class_name = "softwaremeteringcls"
Version = "1.0.3"
End sub

Private function listinstalledprogs (oreg)
'Returns array of strings displayname & "& displayversion
Dim oregx, ncnt, ssubkeysary, sprogname
Dim sprogsary (): redim sprogsary (1)
Ssubkeysary = getkeys (oreg, HKLM, uninstall_root)

If supress_hotfix_entries then
'Supress looking into all hot fix related sub keys (like q252795, Etc ...)
Set oregx = new Regexp
Oregx. pattern = "^ Q \ D + $" 'Will detect patterns like: q252795
Oregx. ignorecase = true

For ncnt = 0 to ubound (ssubkeysary)
If not oregx. Test (ssubkeysary (ncnt) then
Sprogname = getprognameandversion (oreg, HKLM ,_
Uninstall_root & "\" & ssubkeysary (ncnt ))

If not (isempty (sprogname) or sprogname = "") then
If not isempty (sprogsary (ubound (sprogsary)-1) then
Redim preserve sprogsary (ubound (sprogsary) + 1)
End if
Sprogsary (ubound (sprogsary)-1) = sprogname
End if
End if
Next
Else
'List all sub keys including hotfix related ones (like q252795, Etc ...)
For ncnt = 0 to ubound (ssubkeysary)
Sprogname = getprognameandversion (oreg, HKLM ,_
Uninstall_root & "\" & ssubkeysary (ncnt ))

If not (isempty (sprogname) or sprogname = "") then
If not isempty (sprogsary (ubound (sprogsary)-1) then
Redim preserve sprogsary (ubound (sprogsary) + 1)
End if
Sprogsary (ubound (sprogsary)-1) = sprogname
End if
Next
End if

Listinstalledprogs = sprogsary
End Function

Private function getkeys (oreg, hive, skeyroot)
'Returns array of strings of subkey names
Dim vkeysary
Call oreg. enumkey (hive, skeyroot, vkeysary)
Getkeys = vkeysary '>>>
End Function

Private function getprognameandversion (oreg, hive, skeyroot)
'If both values "displayname" and "displayversion" exist in skeyroot, return:
'"Displaynamekeyvalue -- version: displayversionkeyvalue"
'
'If only "displayname" exists, return:
'"Displaynamekeyvalue"
'
'Otherwise empty is returned

Dim skeyvaluesary, ikeytypesary, ncnt, svalue, sdisplayname, sdisplayversion
Oreg. enumvalues hive, skeyroot, skeyvaluesary, ikeytypesary 'fill the arrays

'6 Sept 2002
'sp3 for Win2k altered behavior of registry provider's enumvalues method!
'numvalues method after SP3 does not return empty array any more for all
'those registry keys that have only empty default value.
'therefore skeyvaluesary must be tested to see if it is an array or not.
if not isarray (skeyvaluesary) Then
exit function'' >>< br> end if

For ncnt = 0 to ubound (skeyvaluesary)
If instr (1, skeyvaluesary (ncnt), "displayname", vbtextcompare) then
If ikeytypesary (ncnt) = REG_SZ then
Oreg. getstringvalue hive, skeyroot, skeyvaluesary (ncnt), svalue
If svalue <> "" then
Sdisplayname = svalue
Sdisplayname = Replace (sdisplayname ,"[","(")
Sdisplayname = Replace (sdisplayname, "]", ")")
End if
End if
Elseif instr (1, skeyvaluesary (ncnt), "displayversion", vbtextcompare) then
If ikeytypesary (ncnt) = REG_SZ then
Oreg. getstringvalue hive, skeyroot, skeyvaluesary (ncnt), svalue
If svalue <> "then sdisplayversion = svalue
End if
End if

If (sdisplayname <> "") and (sdisplayversion <> "") then
Getprognameandversion = sdisplayname & "-- version:" & sdisplayversion
Exit function'>
End if
Next

If sdisplayname <> "" then
Getprognameandversion = sdisplayname
Exit function'>
End if
End Function

End Class
'================================== End of class ======================== ============================

Function demo_softwaremeteringcls ()
Dim osoftmeter, sprogsary, scomputer

'Scomputer = "W-BRANIMIR-666"
'Scomputer = "W-Branimir-079"
Scomputer = "" 'query local host

Sprogsary = getsoftwarelist (scomputer)
Call wscript. Echo (join (sprogsary, vbcrlf ))
End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.