from win32com.client import Dispatch
#ref : http://mow001.blogspot.com/2006/03/vbscript-hosting-in-msh-inputbox-in.html
vbs = Dispatch("MSScriptControl.ScriptControl")
vbs.Language = "vbscript";
wmi= r"""
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT Caption,Size FROM Win32_LogicalDisk where drivetype='3'",,48)
"""
ldisque = []
def cleanString(s):
car = [';','"','\n','\t',' ']
for c in car:
try:
s = s.replace(c,'')
except:
continue
head = s.index('{')
tail = s.index('}')
s = s.replace(':',',')
s = s.replace('=',':')
return s
vbs.addcode(wmi)
col = vbs.eval('colItems')
for item in col:
disque = item.GetObjectText_()
print cleanString(disque)
vbs = None
Monday, November 26, 2007
VBS from Python
Calling VBS from Python
from win32com.client import Dispatch
#ref : http://mow001.blogspot.com/2006/03/vbscript-hosting-in-msh-inputbox-in.html
vbs = Dispatch("MSScriptControl.ScriptControl")
vbs.Language = "vbscript";
code = """
function Input()
Input = inputbox("message","titre")
end function
function add(x,y)
add = x + y
end function
"""
vbs.addcode(code)
txt = vbs.eval('Input()')
print txt
somme = vbs.eval('add(2,3)')
vbs.ExecuteStatement('msgbox "The result is %d",,"Call VBS Add from Python"'%somme)
#ref : http://mow001.blogspot.com/2006/03/vbscript-hosting-in-msh-inputbox-in.html
vbs = Dispatch("MSScriptControl.ScriptControl")
vbs.Language = "vbscript";
code = """
function Input()
Input = inputbox("message","titre")
end function
function add(x,y)
add = x + y
end function
"""
vbs.addcode(code)
txt = vbs.eval('Input()')
print txt
somme = vbs.eval('add(2,3)')
vbs.ExecuteStatement('msgbox "The result is %d",,"Call VBS Add from Python"'%somme)
Powered by ScribeFire.
Subscribe to:
Posts (Atom)