热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

代码如下:'FileName:SoftwareMeteringCLS.vbs'If(WScript.ScriptNameSoftwareMeteringCLS

代码如下:
‘ 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:
‘ “SoftwareMicrosoftWindowsCurrentVersionUninstall”
‘ 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 ‘ SoftwareMicrosoftWindowsCurrentVersionUninstall
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 %ignore_a_1%able 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 = “SoftwareMicrosoftWindowsCurrentVersionUninstall”
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 = “^Qd+$” ‘ 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

—-想了解更多的服务器相关问题处理怎么解决关注<编程笔记>




推荐阅读
  • 本文介绍了如何使用 Node.js 和 Express(4.x 及以上版本)构建高效的文件上传功能。通过引入 `multer` 中间件,可以轻松实现文件上传。首先,需要通过 `npm install multer` 安装该中间件。接着,在 Express 应用中配置 `multer`,以处理多部分表单数据。本文详细讲解了 `multer` 的基本用法和高级配置,帮助开发者快速搭建稳定可靠的文件上传服务。 ... [详细]
  • 开机自启动的几种方式
    0x01快速自启动目录快速启动目录自启动方式源于Windows中的一个目录,这个目录一般叫启动或者Startup。位于该目录下的PE文件会在开机后进行自启动 ... [详细]
  • 在JavaWeb开发中,文件上传是一个常见的需求。无论是通过表单还是其他方式上传文件,都必须使用POST请求。前端部分通常采用HTML表单来实现文件选择和提交功能。后端则利用Apache Commons FileUpload库来处理上传的文件,该库提供了强大的文件解析和存储能力,能够高效地处理各种文件类型。此外,为了提高系统的安全性和稳定性,还需要对上传文件的大小、格式等进行严格的校验和限制。 ... [详细]
  • 本文介绍如何在 Android 中自定义加载对话框 CustomProgressDialog,包括自定义 View 类和 XML 布局文件的详细步骤。 ... [详细]
  • 本文介绍如何使用 Python 的 DOM 和 SAX 方法解析 XML 文件,并通过示例展示了如何动态创建数据库表和处理大量数据的实时插入。 ... [详细]
  • 本文详细介绍了 PHP 中对象的生命周期、内存管理和魔术方法的使用,包括对象的自动销毁、析构函数的作用以及各种魔术方法的具体应用场景。 ... [详细]
  • 在软件开发过程中,经常需要将多个项目或模块进行集成和调试,尤其是当项目依赖于第三方开源库(如Cordova、CocoaPods)时。本文介绍了如何在Xcode中高效地进行多项目联合调试,分享了一些实用的技巧和最佳实践,帮助开发者解决常见的调试难题,提高开发效率。 ... [详细]
  • 在PHP中如何正确调用JavaScript变量及定义PHP变量的方法详解 ... [详细]
  • 解决Only fullscreen opaque activities can request orientation错误的方法
    本文介绍了在使用PictureSelectorLight第三方框架时遇到的Only fullscreen opaque activities can request orientation错误,并提供了一种有效的解决方案。 ... [详细]
  • 本文详细介绍了在 Ubuntu 系统上搭建 Hadoop 集群时遇到的 SSH 密钥认证问题及其解决方案。通过本文,读者可以了解如何在多台虚拟机之间实现无密码 SSH 登录,从而顺利启动 Hadoop 集群。 ... [详细]
  • 零拷贝技术是提高I/O性能的重要手段,常用于Java NIO、Netty、Kafka等框架中。本文将详细解析零拷贝技术的原理及其应用。 ... [详细]
  • 微信公众号推送模板40036问题
    返回码错误码描述说明40001invalidcredential不合法的调用凭证40002invalidgrant_type不合法的grant_type40003invalidop ... [详细]
  • 在 Ubuntu 中遇到 Samba 服务器故障时,尝试卸载并重新安装 Samba 发现配置文件未重新生成。本文介绍了解决该问题的方法。 ... [详细]
  • 本文将详细介绍如何注册码云账号、配置SSH公钥、安装必要的开发工具,并逐步讲解如何下载、编译 HarmonyOS 2.0 源码。通过本文,您将能够顺利完成 HarmonyOS 2.0 的环境搭建和源码编译。 ... [详细]
  • 基于Linux开源VOIP系统LinPhone[四]
    ****************************************************************************************** ... [详细]
author-avatar
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有