自动写入文件上传到指定服务器SoftwareMeteringCLS.vbs源码

代码如下:

' 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 April 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.
'
' Added global function getSoftwareList(sHost) to be used
' from *.wsf scripts when caller script is JScript (since
' JScript can not instantiate VBS classes directly).
'
' 21 April 2002 V 1.0.2
' Replacing "[" 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 (except the Default, empty value)
' will now return Null value (previously array of size 0 was
' returned). Added (previously unneeded) type checking...
'
'
' Dependancies:
' 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!
' EnumValues 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 ' ' >>>
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

(0)

相关推荐

  • 自动写入文件上传到指定服务器SoftwareMeteringCLS.vbs源码

    复制代码 代码如下: ' FileName: SoftwareMeteringCLS.vbs ' //////////////////////////////////////////////////////////////////// If (WScript.ScriptName = "SoftwareMeteringCLS.vbs") Then Call demo_SoftwareMeteringCLS() ' ====================================

  • java文件上传至ftp服务器的方法

    用java实现ftp文件上传.我使用的是commons-net-1.4.1.zip.其中包含了众多的java网络编程的工具包. 1.把commons-net-1.4.1.jar包加载到项目工程中去. 2.看如下代码: import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import org.apache.commons.net.ft

  • java实现将文件上传到ftp服务器的方法

    本文实例讲述了java实现将文件上传到ftp服务器的方法.分享给大家供大家参考,具体如下: 工具类: package com.fz.common.util; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; imp

  • android选择视频文件上传到后台服务器

    本文实例为大家分享了android选择视频文件上传到后台服务器的具体代码,供大家参考,具体内容如下 选择本地视频文件 附上Demo 首先第一步打开打开相册选择视频文件: Intent intent = new Intent(); intent.setType("video/*"); intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); ((Activity)

  • java实现多文件上传至本地服务器功能

    博主最近在做一个内网项目,内部可以访问外部数据,但是外部访问不了内部数据,这也就造成了可能文件无法上传,所以博主另辟蹊径,在本地服务器上建立一个文件夹专门用来存储上传数据. 环境:jdk,tomcat 一.前台上传文件(ajax上传) <input type="file" name="annexUrl" id="annexUrl" multiple="multiple"/> 其中multiple="mul

  • Java将文件上传到ftp服务器

    本文实例为大家分享了Java将文件上传到ftp服务器的具体代码,供大家参考,具体内容如下 首先简单介绍一下什么是FTP,以及如何在自己的电脑上搭建一个ftp服务器: —— FTP是文件传输协议(FTP)是一种客户端/服务器协议,用于将文件传输到主机或与主机交换文件.它可以使用用户名和密码进行身份验证.匿名 FTP 允许用户从 Internet 访问文件,程序和其他数据,而无需用户 ID 或密码.总之就是方便一个可以上传下载文件的地方. 要实现上传文件,首先要在本地创建一个ftp服务器(win10

  • java中创建写入文件的6种方式详解与源码实例

    在java中有很多的方法可以创建文件写文件,你是否真的认真的总结过?下面笔者就帮大家总结一下java中创建文件的五种方法. Files.newBufferedWriter(Java 8) Files.write(Java 7 推荐) PrintWriter File.createNewFile FileOutputStream.write(byte[] b) 管道流 实际上不只这5种,通过管道流的排列组合,其实有更多种,但是笔者总结的这五种可以说是最常用及最佳实践,前提小知识 以前我在写技术文章

  • jQuery动态添加及删除表单上传元素的方法(附demo源码下载)

    本文实例讲述了jQuery动态添加及删除表单上传元素的方法.分享给大家供大家参考,具体如下: 运行效果截图如下: 点击此处查看在线演示效果. 具体代码如下: <html> <head> <script type="text/javascript" src="jquery-1.7.2.min.js"></script> <script type="text/javascript"> $(d

  • ajaxFileUpload.js插件支持多文件上传的方法

    前提条件: ajaxFileUpload.js插件多文件上传 步骤: 1.修改源码,(源码只支持单个文件的上传): 复制代码 代码如下: //修改前代码------- //var oldElement = jQuery('#' + fileElementId); //var newElement = jQuery(oldElement).clone(); //jQuery(oldElement).attr('id', fileId); //jQuery(oldElement).before(ne

  • Java实现文件上传服务器和客户端

    本文实例为大家分享了Java实现文件上传服务器和客户端的具体代码,供大家参考,具体内容如下 文件上传服务器端: /** * 使用TCP协议实现上传功能的服务器端 * 思路: * 新建ServerSocket * 等待客户端连接 * 连接上后开启子线程,把连接获取的Socket传给子线程 * 循环进行 * @author yajun * */ public class UploadServer { public static void main(String[] args) { UploadSer

随机推荐