VBS - 翼展电脑服务中心


批处理获取XML节点数值

2023-6-9 乱云飞 代码 评论(0) 浏览(76) 标签: 批处理 VBS 获取XML 读取XML

//用bat获取XML节点
SET FILE=onvif.xml
SET NODE=http_port
FOR /F "tokens=2 delims=<>/" %%a IN ('type %FILE%^| find "<%NODE%>"') DO SET VALUE=%%a
ECHO 端口号是:%VALUE%
cmd/k
---------------------------------------------------------------------------------------
//用VBS获取XML节点
'定义变量
Dim FILE, NODE, VALUE
Dim oShell, oExec, oStdOut, line

'设置文件名和节点名
FILE = "onvif.xml"
NODE = "http_port"

'使用CMD命令获取节点值
Set oShell = CreateObject("WScript.Shell")
Set oExec = oShell.Exec("cmd /c type " & FILE & " | find """ & NODE & """")
Set oStdOut = oExec.StdOut

'读取输出结果并提取值
Do While Not oStdOut.AtEndOfStream
    line = oStdOut.ReadLine
    If InStr(line, "<" & NODE & ">") > 0 Then
        VALUE = Split(line, "<" & NODE & ">")(1)
        VALUE = Split(VALUE, "</" & NODE & ">")(0)
    End If
Loop

'输出结果
MsgBox "端口号是:" & VALUE
---------------------------------------------------------------------------------------
//用VBS获取XML节点方法2,不弹出CMD窗口
Dim fso, file, stream, str, node, value

' 创建 File System Object
Set fso = CreateObject("Scripting.FileSystemObject")

' 打开文件
Set file = fso.OpenTextFile("onvif.xml", 1)

' 读取文件内容
str = file.ReadAll

' 关闭文件
file.Close

' 查找节点
node = "http_port"
value = ""

' 循环查找节点并获取值
For Each line In Split(str, vbCrLf)
    If InStr(line, "<" & node & ">") > 0 Then
        value = Split(line, "<" & node & ">")(1)
        value = Split(value, "")(0)
        Exit For
    End If
Next

' 输出结果
If value <> "" Then
    WScript.Echo "端口号是:" & value
End If

自动运行命令行程序并输入选项.VBS

2022-6-21 乱云飞 代码 评论(0) 浏览(11) 标签: 启动程序 VBS 自动输入

[该内容已加密,请点击标题输入密码访问]

高级系统设置,现在还有问题不会发送空格键

2019-8-6 乱云飞 评论(0) 浏览(608) 标签: VBS 系统设置 控制面板

dim Shell
Set Shell = WScript.CreateObject("WScript.Shell")
Shell.Run"rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,3"
'Shell.Run"cmd.exe /c rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,3",0
WScript.Sleep 1000
Shell.AppActivate "系统属性"
Shell.SendKeys " "

这个代码帮我省了不少力,自动设置资源管理器的图标样式为中等图标

2019-8-6 乱云飞 代码 评论(0) 浏览(673) 标签: 模拟按键 VBS 快捷键 设置图标 中等图标

on error resume next
'自动设置资源管理器的图标样式为中等图标
'VBS by 80c.cc  2019-8-6
Set Shell = CreateObject("WScript.Shell")
WScript.Sleep 1500
Shell.run "C:\windows"
WScript.Sleep 1500
Shell.SendKeys "^{a}"
WScript.Sleep 1500
Shell.SendKeys "^"+"%"+"3"
WScript.Sleep 1500
Shell.SendKeys "^%{3}"
WScript.Sleep 1500
Shell.SendKeys "%{V}"
WScript.Sleep 1500
Shell.SendKeys "{Y}"
WScript.Sleep 1500
Shell.SendKeys "{ENTER}"
WScript.Sleep 1500
Shell.SendKeys "^{TAB}"
WScript.Sleep 1500
Shell.SendKeys "{L}"
WScript.Sleep 1500
Shell.SendKeys "{ENTER}"
WScript.Sleep 1500
Shell.SendKeys "%{F4}"
WScript.Sleep 1500
Shell.SendKeys "%{F4}"

VBS以管理员身份运行程序

2019-8-4 乱云飞 评论(0) 浏览(652) 标签: VBS 管理员权限

Option Explicit
RunAsAdmin
Msgbox CreateObject("WScript.Shell").CurrentDirectory
' 以管理员身份运行 By Yu2n
Sub RunAsAdmin()
	Dim oItems, vItem, sVer, nVer, vArg, sArgs, sCurDir
	Set oItems = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
	For Each vItem In oItems
		sVer = vItem.Version
	Next
	Set oItems = Nothing
	nVer = Clng(Split(sVer, ".")(0) & Split(sVer, ".")(1))
	If nVer >= 60 Then
		If Not WScript.Arguments.Named.Exists("RunAsAdmin") Then
			For Each vArg In WScript.Arguments
				sArgs = sArgs & " """ & vArg & """"
			Next
			sArgs = sArgs & " /RunAsAdmin:True"
			CreateObject("Shell.Application").ShellExecute "WScript.exe", _
				"""" & WScript.ScriptFullName & """" & sArgs, "", "runas", 1
			WScript.Quit(0)
		Else
			sCurDir = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\") -1)
			CreateObject("WScript.Shell").CurrentDirectory = sCurDir
		End If
	End If
End Sub

激活窗口,只写窗口标题前半部分就行

2019-8-2 乱云飞 评论(0) 浏览(577) 标签: 批处理 VBS 激活窗口

Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate "任务管理"

WshShell.SendKeys "{Enter}"

-------------------------------------------------------------------

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<激活窗口
Private Sub jihuo()
Set www = CreateObject("wscript.shell") '-------------------定义shell
Shell "cmd.exe /c echo Set www = CreateObject(""WScript.Shell""):www.AppActivate ""EZSOFT"">%TEMP%\app.vbs", vbHide
Shell ("cmd /c %temp%\app.vbs"), vbHide '//激活窗口
End Sub
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

预ICP备10086-001号 © 翼展网/80C.CC 技术支持/洛阳翼展科技
TEL / 13213610060 QQ / 345794501
Powered by emlog