返回列表 发帖

[问题求助] 请教VBS不能创建对像

set oDOM = WScript.GetObject("http://city.ip138.com/ip2city.asp")
flag=0
for i=1 to 10
   if oDOM.readyState = "complete" then
      flag=1
      exit for
   end if
   WScript.sleep 500
next
if flag=0 then
    WScript.Echo "timeout ..."
    wscript.quit
end if
s=oDOM.documentElement.innerText
Set Re = New RegExp
Re.Pattern="(\d+)\.(\d+)\.(\d+)\.(\d+)"
for each r in Re.Execute(s)
     res=r
     exit for
Next
WScript.Echo "IPAddress: " & res
'设置剪切板的内容
Dim Form, TextBox
Set Form = CreateObject("Forms.Form.1")
Set TextBox = Form.Controls.Add("Forms.TextBox.1").Object
TextBox.MultiLine = True
TextBox.Text = res
TextBox.SelStart = 0
TextBox.SelLength = TextBox.TextLength
TextBox.Copy
MyVar = MsgBox (res,64,"请Ctrl+V粘贴IP地址")COPY
以上代码我用VBSEDIT编译出来可以运行并且正常! 但是用脚本运行要报错. 请教大神怎么处理啊?

没装 office,确切说是没装 vba

TOP

既然都调用 ie 了,就用 clipboardData.setData 好了——假如楼主不在意可能弹出的提示的话

TOP

如何破解! 有没有更好的代码呀  后就是后面复制的部分!

TOP

没装 office,确切说是没装 vba



如何破解! 有没有更好的代码呀  后就是后面复制的部分!

TOP

弹出提示不好!~  我想应该有解决办法吧  ~?是吧?版主!

TOP

本帖最后由 pcl_test 于 2015-7-6 21:47 编辑

批处理
@set @n=0; /* & echo off&cscript -nologo -e:jscript "%~f0"|clip&echo;外网IP已写入剪贴板&ping -n 2 0 >nul&exit /b& rem */
var url = "http://city.ip138.com/ip2city.asp";
http = new ActiveXObject("Msxml2.XMLHTTP");
stream = new ActiveXObject("ADODB.Stream");
http.open("GET", url, false);
http.send(null);
stream.Type=1;
stream.Mode=3;
stream.Open();
stream.Write(http.responseBody);
stream.Position=0;
stream.Type=2;
stream.Charset="gb2312";
var m = stream.ReadText.match(/\[(\d+\.\d+\.\d+\.\d+)\]/);
stream.Close();
WSH.Echo(m[1]);COPY

TOP

回复 7# pcl_test

谢谢!!

对于VBS脚本我疑惑的是编译成EXE可以运行得到IP地址到剪切板.为什么脚本运行不对

TOP

回复 8# lover5U
set oDOM = WScript.GetObject("http://city.ip138.com/ip2city.asp")
flag=0
for i=1 to 10
   if oDOM.readyState = "complete" then
      flag=1
      exit for
   end if
   WScript.sleep 500
next
if flag=0 then
    WScript.Echo "timeout ..."
    wscript.quit
end if
s=oDOM.documentElement.innerText
Set Re = New RegExp
Re.Pattern="(\d+)\.(\d+)\.(\d+)\.(\d+)"
for each r in Re.Execute(s)
     res=r
     exit for
Next
CreateObject("wscript.Shell").Run "cmd.exe /c echo " & res& " | clip",0,False
MsgBox "外网IP为"&res&vbCrLf&"请Ctrl+V粘贴IP地址"COPY

TOP

回复 9# pcl_test

谢谢.正在学习代码中......

TOP

回复 8# lover5U


    所噶,目测你的 office 是 32 位的,64 位进程不能调用 32 位控件,解决方法是用 32 位宿主执行脚本

TOP

返回列表