星期二, 十月 23, 2007

Sqlite3 3.5.1 如何读取汉字?

首先.sqlite3 建立的数据库默认编码是UTF-8.
当进入管理界面通过.read sql.txt运行的命令或insert into插入的汉字,sqlite3认为是"合格"的
UTF-8字符串。

所以需要,使用UltraEdit之类的软件,首先把sql.text转换为标准的utf-8的编码,然后再用.read读取

在powershell读取sqlite.net的数据库代码:
1.首先需要建立一个数据库,名字叫szsk.db3,只要在sqlite3.exe 后面跟随数据库名就可以了。
sqlite3.exe szsk.db3 ,然后敲入.quit推出,就发现szsk.db3已经被建立了。
sqlite3.exe可以从www.sqlite.org下载最新的window 版本。

把System.Data.SQLite.dll文件放在当前目录下.
SQLITE.NET 2.0 下载地址: http://sourceforge.net/projects/sqlite-dotnet2
cls
$global:sdb="$pwd\szsk.db3"
$global:url="$pwd\System.Data.SQLite.dll"
$createTable=@"
CREATE TABLE IF NOT EXISTS DoubleBall (
id integer primary key AUTOINCREMENT,
_Year varchar(4),
_Month varchar(2),
_Day varchar(2),
_Term varchar(3),
_N1 varchar(2),
_N2 varchar(2),
_N3 varchar(2),
_N4 varchar(2),
_N5 varchar(2),
_N6 varchar(2),
_Blue varhcar(2)
)
"@
$dropit= "drop table doubleball"

$command="";
trap [exception]
{
write-host "Exception"
}
function initdb
{
[void][system.reflection.Assembly]::LoadFile($url)
if ((test-path $sdb) -eq $FALSE)
{
$global:conn=new-object System.Data.SQLite.SQLiteConnection("data source="+$sdb+";Version=3;New=TRUE;")
}else
{
$global:conn=new-object System.Data.SQLite.SQLiteConnection("data source="+$sdb+";Version=3;New=false;")
}
}
function getDBConnection
{
$conn=new-object System.Data.SQLite.SQLiteConnection("data source="+$sdb+";Version=3;New=false;")
}
initdb

$command=new-object System.Data.SQLite.SQLiteCommand

if($args.count -eq 0)
{
return $conn
}else
{
$sql="select * from stocklist where stockCode='" + $args[0]+".sz'"
$command.CommandText =$sql

$command.Connection=$conn

$conn.open()
$dataReader =$command.ExecuteReader()
$script:cnName=$args[0]
while($dataReader.Read() )
{
$script:cnName $dataReader.GetString(1)
}
$dataReader.close()
$conn.close()
return $cnName
}

星期五, 十月 19, 2007

Vbscript 实现 cls命令

目的:在Vbscript中实现清空当前cmd窗口的内容。经过实验 发现一下代码可以实现。

Set WshShell = CreateObject("wscript.shell")
WshShell.SendKeys "%( )+E+P{ENTER}CLS{ENTER}{TAB}",True
Wscript.Sleep 5000

但是这个代码有一个问题就是键盘缓冲区是在当前VBS执行完成后,才被发送到当前cmd
窗口,因此是一种后script方式,不是希望在执行其他vbscript之前清空的方式。

经过努力,发现没有其他办法实现。


星期三, 十月 17, 2007

如何在vbscript/cscript 中调用.dll

1.普通DLL
必须是通过regsvr32 可以注册的dll才能在vbscript中被调用,应为createobject必须是 ActiveObject dll,如果是标准的函数库,则无法使用。必须包装成Activexobject

2..NET Dll
必须通过 regasm注册后,就可以在vbscript中使用了?

regasm System.Data.SQLite.DLL /tlb:System.Data.SQLite.tlb /codebas

星期三, 十月 10, 2007

Powershell .ps1 如何得到返回的对象?

把需要返回的对象在ps1文件的最后一行写明就可以了。
其他命令的输出需要同管道|out-null,来回避。

比如下面:
[system.reflection.Assembly]::LoadFrom($url) |out-null

$conn=new-object System.Data.SQLite.SQLiteConnection("data source="+$sdb+";Version=3;New=TRUE;")

如果想返回一个connection object
就在ps1文件的最后一行写明
$conn就可以了。

星期一, 十月 08, 2007

PowerShell如何处理HTMLDocument Object

上次写的文章中因为无法使用Com对象“HTMLFILE”,而不得不采用IE.Application对象来处理
HTMLDocument对象。
但是速度上同同样的VBS代码比感觉差太多。所以始终想使用"HTMLFILE"来处理HTML Document.

最终通过get-member发现了 在PowerShell里使用的IHTMLDocument2_write方法可以用来初始化HTMLDocument对象内容。

如下代码,可以在POWERSHELL里使用了。

$htmlDoc= New-Object -com "HTMLFILE"
$page = "<html><body>this is a test</body></html>"
$htmlDoc.IHTMLDocument2_write($page)
$htmlDoc.close

如何在PowerShell调用Dll文件。

PowerShell中可以直接使用.NET的Dll库,通过如下语句:
[system.reflection.Assembly]::LoadFrom("dll所在绝对路径");

但是传统的非.NET生成的Dll库如何使用呢?
比较复杂,基本可以按照下列语句来使用:
$dir="C:\\curl-7.16.4\\FTCTRLPRO3.dll"
$ctor = [Runtime.InteropServices.DllImportAttribute].GetConstructor([string])
$attr = New-Object Reflection.Emit.CustomAttributeBuilder $ctor, $dir

这只能简单载入Dll,如果想使用Dll的具体的函数,可以参看如下文章:
http://www.leeholmes.com/blog/ManagingINIFilesWithPowerShell.aspx
##############################################################################
##
## Invoke-WindowsApi.ps1
##
## From PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
## Invoke a native Windows API call that takes and returns simple data types.
##
## ie:
##
## ## Prepare the parameter types and parameters for the
## CreateHardLink function
## $parameterTypes = [string], [string], [IntPtr]
## $parameters = [string] $filename, [string] $existingFilename, [IntPtr]::Zero
##
## ## Call the CreateHardLink method in the Kernel32 DLL
## $result = Invoke-WindowsApi "kernel32" ([bool]) "CreateHardLink" `
## $parameterTypes $parameters
##
##############################################################################

param(
[string] $dllName,
[Type] $returnType,
[string] $methodName,
[ Type[]] $parameterTypes,
[Object[]] $parameters
)

## Begin to build the dynamic assembly
$domain = [AppDomain]::CurrentDomain
$name = New-Object Reflection.AssemblyName 'PInvokeAssembly'
$assembly = $domain.DefineDynamicAssembly( $name, 'Run')
- Show quoted text -
$module = $assembly.DefineDynamicModule( 'PInvokeModule')
$type = $module.DefineType('PInvokeType', "Public,BeforeFieldInit")

## Go through all of the parameters passed to us. As we do this,
## we clone the user's inputs into another array that we will use for
## the P/Invoke call.
$inputParameters = @()
$refParameters = @()

for($counter = 1; $counter -le $parameterTypes.Length; $counter++)
{
## If an item is a PSReference, then the user
## wants an [out] parameter.
if($parameterTypes[$counter - 1] -eq [Ref])
{
## Remember which parameters are used for [Out] parameters
$refParameters += $counter

## On the cloned array, we replace the PSReference type with the
## .Net reference type that represents the value of the PSReference,
## and the value with the value held by the PSReference.
$parameterTypes[ $counter - 1] =
$parameters[$counter - 1 ].Value.GetType().MakeByRefType()
$inputParameters += $parameters[$counter - 1].Value
}
else
{
## Otherwise, just add their actual parameter to the
## input array.
$inputParameters += $parameters[$counter - 1]
}
}

## Define the actual P/Invoke method, adding the [Out]
## attribute for any parameters that were originally [Ref]
## parameters.
$method = $type.DefineMethod( $methodName, 'Public,HideBySig,Static,PinvokeImpl',
$returnType, $parameterTypes )
foreach($refParameter in $refParameters)
{
[void] $method.DefineParameter($refParameter, "Out", $null)
}

## Apply the P/Invoke constructor
$ctor = [Runtime.InteropServices.DllImportAttribute ].GetConstructor([string])
$attr = New-Object Reflection.Emit.CustomAttributeBuilder $ctor, $dllName
$method.SetCustomAttribute($attr)

## Create the temporary type, and invoke the method.
$realType = $type.CreateType()

$realType.InvokeMember($methodName, 'Public,Static,InvokeMethod', $null, $null,
$inputParameters)

## Finally, go through all of the reference parameters, and update the
## values of the PSReference objects that the user passed in.
foreach($refParameter in $refParameters)
{
$parameters[$refParameter - 1].Value = $inputParameters[$refParameter - 1]
}

星期五, 十月 05, 2007

Akashic records

空之境界中对于阿克夏记录,或者说阿卡沙年代记的注解十分简单和模糊。阿克夏记录(Akashic Records)并不具备电脑分析和处理信息的功能,它所能做的只有忠实详细的记录而已。

阿 克夏的概念起源于印度。在婆罗门教的文献中,“阿克夏”被描述为“宇宙的精神—物质”,它包括了所有的存在与发展。与之类似的“梵”(婆罗门教与印度教的 主神之一,为创造之神,亦指终生之本)在实质上通常被视作非个人的、无法识别的最高宇宙原理,万物来源于它,万物又回归于它。它非实体、非物质、非先天而 又永恒存续,无始无终。按照古老的印度学说,梵“能够穿透一切,赋予至高无上的天神或是小到极点的矿物原子以生机。”古印度秘密学说最后明确指出,“阿克 夏就是一切创造物的起源于回归之地”,阿克夏“比一切万物都更古老”,简直就是“最后的终点”。阿克夏就是世间万物的根源(荒耶宗莲竭尽全力所追求的,想 必就是这个东西了);而阿克夏记录则使得任何时刻——包括过去、现在和未来——所发生的任何事情都不致归于遗忘之中,它记录了一切的信息。

当 然在客观上,没有确切的证据能证明这样一种所谓的“宇宙记忆”确实存在,或者证明这个世界上从一开始曾经发生的一切都被记录了下来。但若仅仅因此就认为阿 克夏记录是不存在的,同样不能令人信服。即使是现代,这种现象也能得到共鸣和认同,只是换了一个完全不同的名字:形态发生场。

剑桥大学的 生化学家鲁伯特·谢尔德雷克在其著作《创造性的宇宙》中写道,形态发生场能够摆脱时间和空间发挥作用。具体地说,如果一个生物种类的成员获得了一种新的行 为,那么它自己的形态发生场会由此改变。只要这种新的行为在足够长的时间里得到了坚持,物种成员之间就会形成一种相互影响,进而影响整个物种。实际的例子 是:一只老鼠一旦学会了在一明一暗的信号下告到黄油,其他老鼠就会越来越快地掌握这个方法。直到最后,所有的老鼠——即便不是由最初的那只生出来的,也不 曾与它有过接触——都学会了这种行为。

按照谢尔德雷克的观点,自然是具有“记忆”的,我们通常视作自然法则的东西只不过是“习惯”。自然存在与“习惯”也就是“行为模式”之中。根据这一构想,自然界中的每一类事物都必须按照它那一类的“集体记忆”内容来行事,从有生命的事物到无生命的物质都是如此。

调试.NET错误工具

再运行Powershell经常出现一些系统错误,可以通过
C:\Program Files\Microsoft.NET\SDK\v2.0\Bin\FUSLOGVW.exe 来观察错误。
首先运行FUSLOGVW.exe ,然后再运行Powershell,就可以在FUSLOGVW.exe窗口中看到错误内容。如图


双击条目或按下 查看日志按钮,则在IE中查看日志内容

Dll 函数查看工具

因为在Powershell里调用一些dll,总是出现错误。
才寻找到了一些Dll函数查看器。
都挺不错的。
DLL Export Viewer
http://www.nirsoft.net/utils/dll_export_viewer.html

国产的。
http://www.onlinedown.net/soft/17471.htm

星期四, 十月 04, 2007

在Powershell里访问Mysql 5.0 数据库

首先必须安装了Mysql 5.0 Connector .net 5.0的driver,
下载地址:http://www.mysql.org/downloads/connector/net/5.0.html
然后编写如下代码。
[void][system.reflection.Assembly]::LoadFrom("D:\mysql\MySQL Connector Net 5.0.8.1\Binaries\.NET 2.0\MySQL.Data.dll")
$myconnection = New-Object MySql.Data.MySqlClient.MySqlConnection
$myconnection.ConnectionString = "server=localhost;user id=root;password=root;database=mrpII;pooling=false"
$myconnection.Open()
$mycommand = New-Object MySql.Data.MySqlClient.MySqlCommand
$mycommand.Connection = $myconnection
$mycommand.CommandText = "SELECT * from MRP_BOM"

$adapter = new-object MySql.Data.MySqlClient.MySqlDataAdapter
$adapter.SelectCommand = $mycommand
$ds = new-object System.Data.DataSet
$adapter.Fill($ds)
$myconnection.close()
$ds.Tables[0] |Format-Table #非常Cool的输出效果,如下图

真是cool毙了。

如何传递一个参数到cmdlet?

增强版本的HelloWorld,通过传递一族人民到HellowWorld.
一下只写明增强版本的cmdlet程序,注册的snapin没有变化。
HelloWorld.cs
在PS下通过 get-helloworld,一个接一个输入所有名称,回车表示输入结束。
或者通过get-helloworld ("William wang","Peter Zhang","李华") 来直接得到结果.


using System;
using System.Management.Automation;


[Cmdlet(VerbsCommon.Get, "HelloWorld", SupportsShouldProcess = true)]
public class HelloWorld : PSCmdlet
{

// An array is used to support the following scenario:
[Parameter(
Position = 0,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true,
Mandatory = true,
HelpMessage = "恭贺的名字清单")]
[ValidateNotNullOrEmpty]
public string[] FullName
{
get { return fullName; }
set {fullName = value; }
}
private string[] fullName;
// Called when cmdlet is invoked.
protected override void BeginProcessing()
{
// You could open a database connection here for example.
base.BeginProcessing();
}

// Called when we have pipeline input.
protected override void ProcessRecord()
{
// this.Name could be null in BeginProcessing (no parameters passed)
// but could be filled when ProcessRecord gets called (parameters from pipeline)
try
{
if(this.fullName==null)
{
WriteObject("fullName is null");
}else
{

foreach (string item in this.fullName)
{
WriteObject("Hello World!"+item);
}
}

}catch(Exception)
{
WriteObject("excetpin");
}
}

// Called after every record has been processed.
protected override void EndProcessing()
{
base.EndProcessing();
}

// Called when the user hits CTRL+C
protected override void StopProcessing()
{
base.StopProcessing();
}
}

编写Powershell的HelloWorld的例子,开始编写cmdlet第一步

首先来自Microsoft的例子:http://msdn2.microsoft.com/en-us/library/ms714437.aspx
编译一个以C#语言编写的cmdlet需要的开发环境,可以参看:
http://msdn2.microsoft.com/en-us/library/ms714644.aspx

首先要确认安装了.NET 2.0 Framework的SDK包含csc.exe c#的命令行编译软件。
如果安装成功了.net 2.0 framework SDK,可以在一下目录发现:
C:\WINDOWS\Microsoft.NET\Framework 发现所有安装的.NET Framework的目录。
.Net framework SDK 3.0是在.NET 2.0 SDK的基础上增加了一些新的特性完成的。
所以.NET 3.0自身不带有csc.exe编译软件。
C:\WINDOWS\Microsoft.NET\Framework的典型目录如下。
<dir> v1.0.3705
<dir> v1.1.4322
<dir> v2.0.50727 csc.exe所在目录
<dir> v3.0

其次需要Powershell SDK的安装,如果安装成功可以发现如下目录。
C:\Program Files\Reference Assemblies\Microsoft 发现powershell目录
包含一些.dll 库.

C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0
2006-09-28 15:49 139,264 Microsoft.PowerShell.Commands.Management.dll
2006-09-28 15:49 294,912 Microsoft.PowerShell.Commands.Utility.dll
2006-09-28 15:49 200,704 Microsoft.PowerShell.ConsoleHost.dll
2006-09-28 15:49 65,536 Microsoft.PowerShell.Security.dll
2006-09-28 15:49 1,564,672 System.Management.Automation.dll

软后编写 用来编译C#的Powershell批处理文件,需要包含命令行编译C#代码的一些参考库
cscc.bat包含内容:

set PS_HOME="C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0"
csc.exe /reference:%PS_HOME%\Microsoft.PowerShell.Commands.Management.dll,%PS_HOME%\Microsoft.PowerShell.Commands.Utility.dll,%PS_HOME%\Microsoft.PowerShell.ConsoleHost.dll,%PS_HOME%\Microsoft.PowerShell.Security.dll,%PS_HOME%\System.Management.Automation.dll /t:library %1 %2 %3
%1 %2 %3 代表 C#的代码文件.cs文件。

编写HelloWorld的cmdlet步骤。
1.首先编写cmdlet或pscmdlet的子类:
HelloWorld.cs:
using System;
using System.Management.Automation;


[Cmdlet(VerbsCommon.Get, "HelloWorld", SupportsShouldProcess = true)]
public class HelloWorld : PSCmdlet
{

// Called when cmdlet is invoked.
protected override void BeginProcessing()
{
// You could open a database connection here for example.
base.BeginProcessing();
}

// Called when we have pipeline input.
protected override void ProcessRecord()
{
// this.Name could be null in BeginProcessing (no parameters passed)
// but could be filled when ProcessRecord gets called (parameters from pipeline)
try
{
WriteObject("Hello World!");
}catch(Exception)
{

}
}

// Called after every record has been processed.
protected override void EndProcessing()
{
base.EndProcessing();
}

// Called when the user hits CTRL+C
protected override void StopProcessing()
{
base.StopProcessing();
}
}

2.再编写一个Snapin的注册类。
HelloWorldSnapin.cs

using System;
using System.ComponentModel;
using System.Management.Automation;


[RunInstaller(true)]
public class HelloWorldSnapIn : PSSnapIn
{
public override string Name
{
get { return "HelloWorldSnapIn"; }
}

public override string Vendor
{
get { return "William Wang"; }
}

public override string Description
{
get { return "This Windows PowerShell snap-in contains the Get-HelloWorld cmdlet."; }
}
}

3.编译:
set PS_HOME="C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0"
csc.exe /reference:%PS_HOME%\Microsoft.PowerShell.Commands.Management.dll,%PS_HOME%\Microsoft.PowerShell.Commands.Utility.dll,%PS_HOME%\Microsoft.PowerShell.ConsoleHost.dll,%PS_HOME%\Microsoft.PowerShell.Security.dll,%PS_HOME%\System.Management.Automation.dll /t:library HelloWorld*.cs

得到 HelloWorld.dll文件,然后安装
InstallUtil.exe HelloWorld.dll得到如下成功message:
正在运行事务处理安装。

正在开始安装的“安装”阶段。
查看日志文件的内容以获得 C:\curl-7.16.4\helloworld.dll 程序集的进度。
该文件位于 C:\curl-7.16.4\helloworld.InstallLog。
正在安装程序集“C:\curl-7.16.4\helloworld.dll”。
受影响的参数是:
logtoconsole =
assemblypath = C:\curl-7.16.4\helloworld.dll
logfile = C:\curl-7.16.4\helloworld.InstallLog

“安装”阶段已成功完成,正在开始“提交”阶段。
查看日志文件的内容以获得 C:\curl-7.16.4\helloworld.dll 程序集的进度。
该文件位于 C:\curl-7.16.4\helloworld.InstallLog。
正在提交程序集“C:\curl-7.16.4\helloworld.dll”。
受影响的参数是:
logtoconsole =
assemblypath = C:\curl-7.16.4\helloworld.dll
logfile = C:\curl-7.16.4\helloworld.InstallLog

“提交”阶段已成功完成。

4.然后在powershell里注册这个cmdlet
add-pssnapin helloworldsnapin
如果成功,没有任何提示。


5.运行get-helloworld
得到 hello world!的提示信息。

表明最简单的Hello World cmdlet成功了。

星期四, 九月 27, 2007

如何在Powershell中解析HTMLDocument

HTML document是相对XML Document而言,非格式良好的XMLnon-well formatted.
使用标准的XMLDocument会出现语法检查错误。
必须使用mshtml.dll包含的标准HTMLDocumentClass.
标准的vbscript:代码
set htmlDoc= createobject("HTMLFILE")
page = "<html><body>this is a test</body></html>"
htmlDoc.write(page)
htmlDoc.close


对应的POWSERShell代码为:
$htmlDoc= New-Object -com "HTMLFILE"
$page = "<html><body>this is a test</body></html>"
$htmlDoc.write($page) #出错代码,出现type mismatch错误.
$htmlDoc.close

具体的原因看网络上的解释,似乎是DOM包装的时候,有些接口没有实现造成的问题。
所以目前找到的方法是使用IE控件,代码如下:
$IE= New-Object -com "InternetExplorer.Application"
$IE.navigate('about:blank')##必须的代码行
$IE.Resizable=$True
$IE.StatusBar=$True
$IE.AddressBar=$False
$IE.MenuBar=$False
$IE.Toolbar=$False
while ($IE.busy)
{
sleep -milliseconds 50
}
$page = "<html><body>this is a test</body></html>"
$IE.documetn.body.innerHTML=$page#该代码在IE7以下的IE中不能工作必须换成下面的代码
$IE.document.write( $page) #或者替换为 $oIE.document.IHTMLDocument2_write($html)

出现的错误为:
Property 'innerHTML:' cannot be found on this object; make sure it exists
and is settable.

如何得到Windows所有安装的COM控件?

在PowerShell下,用一下命令都可以做到
1.gci HKLM:\Software\Classes -ea 0| ? {$_.PSChildName -match '^\w+\.\w+$' -and (gp "$($_.PSPath)\CLSID" -ea 0)} | ft PSChildName
2.get-wmiobject Win32_COMClass

星期三, 九月 26, 2007

PowerShell 特殊语法符号。@

@()

空数组

$hash = @{ }

创建空哈希表

@(Get-Alias;Get-Process)

执行其中的两条命令,然后在数组中返回结果


字符串常量:

@”

这是“here string”,其中可包含任意字符(包括回车和引号)。将计算表达式 $(2+2)

”@

@’

带单引号的“here string”不计算表达式。 ‘@

星期五, 九月 21, 2007

PowerShell 错误处理及查看DLL方法

可以在任何function或代码文件中申明如下语句:
trap [Exception]
{
write-host ("trapped " + $_.Exception.GetType().Name); continue;
}


星期四, 九月 20, 2007

Regular Express 表达删除一个空行(blank line)

程序开发中一个常见的问题是如何删除一大段文本中的空行。
所谓的空行就是一行只包含一些空格,制表符或其他不可见的符号的文本行。
在Vbscript的RegExp 对象,支持RegExpOption.Multiline的属性,可以轻易删除。
但其他各种语言,perl,vbscript等等,没有简单的方法。
regularE="^$"可以匹配一个只包含回车换行的空行
但通过十六进制来看很多文本往往发现很多包含000D 00 0D 00 0A之类的空行。
非常难以处理。

标准的删除一个包含很多回车换行的文本的规则表达为
regularE="[\r\n]+\s*[\r\n]+"
这里是一个详细的解释:

http://www.ultraedit.com/index.php?name=Forums&file=viewtopic&t=2777

但这种方法会删除一个所有的回车换行。
所以必须单独编写方法来出来。

星期三, 九月 19, 2007

Microsoft PowerShell 1,0 定制提示符号的简单技巧





















set-item -path function:prompt -value {' PS '+ $(Get-Date -format t) + " " + $(write-host -f red $(Get-Location) -nonewline) + '> '}

得到如下效果:

星期一, 九月 17, 2007

如何通过VBA来让Excel显示HTML代码?

目前发现的方法只是让 EXCEL通过web query是直接支持的。
如果需要更加灵活的方式,目前只能通过把 HTML代码复制到系统粘贴板,然后再让EXCEL
粘帖来实现。

首先在Excel里 ,按下Alt+F11打开宏编写。
然后在菜单工具-->引用。。里找到 Microsoft Forms 2.0 object library ,启用之,
然后书写一下代码,则可以实现了Excel的HTML渲染。

Dim MyDataObj As New DataObject

MyDataObj.SetText "

OneTwo
"

MyDataObj.PutInClipboard '复制到clipboard

然后再调用

ActiveSheet.Paste

则可以显示HTML效果了。

另外一种通过 HTMLProject 来完成,把HTML页面直接传送过去

ActiveWorkbook.HTMLProject.HTMLProjectItems(stockCode).Text = resl
ActiveWorkbook.HTMLProject.RefreshProject


星期五, 九月 14, 2007

几种语言如何设置跳过盗链的检查

一般Java 访问网站。
URL url=new URL("url地址");
然后
Connection conn = url.OpenConnection();
加入下面这行:
conn.addRequestProperty("REFERER", "http://www.mydomain.com");
然后后面再用conn.readLine等就可以避免盗链检查了。

命令行curl访问一个网站避免盗链检查的方式:

curl -x 191.168.1.1:1688 -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -D cookie0001.txt --proxytunnel -o test.html -e "http://quote.地址" %1

Vbscript设置跳过盗链检查。
一个注意事项:在HTML中,设置不起作用,这可能是防止钓鱼网站的原因。
代码如下:
Set httpObj = CreateObject("Microsoft.XmlHttp")
httpObj.open "GET", url, FALSE
'跳过盗链检查
httpObj.setRequestHeader "REFERER", "http://quote.eastmoney.com"
httpObj.send ""