如何Windows 64bit里面运行32bit的脚本

在使用VBA call Jmail发邮件时发现在32bit系统没有问题的脚本,在64bit不能使用, Jmail免费版又没有64bit的,这时就有了如标题描述的问题.

如果你的脚本要依赖于32bit的COM 对象, 那么在转移到64bit时会发现对象无法创建. 这样我们需要在64bit里面 用可以解释32bit的脚本的解释器.

如果是.net application, 那么在编译时选择使用32bit编译就可以了

如果是IIS hosted application, 需要打开IIS的32bit兼容.

 

Key Word:windows 2008, 64bit, vba,jmail

Running 32bit dependent scripts in a 64bit world

Josh Poley

Bungie

11,025 Points 13 5 1
Recent Achievements
Blog Conversation Starter New Blog Rater New Blog Commentator
18 Sep 2008 1:44 PM

 

As seen earlier, it can be problematic to run scripts which rely on 32bit COM objects on a 64bit platform. To make things easier, I wrote basic some script code to detect that the wrong scripting host was run and fork out to the correct one. This just uses a variation of the "detect cscript vs. wscript" pattern, but instead we look at the current processor and do a check to see if we are running the wrong flavor of the script host.

 

//

// this script code relies on 32bit COM objects, if we are running on

// a 64bit system we will want to run under WOW64 (the x86 emulator).

//

 

var shell = WScript.CreateObject("WScript.Shell");

var cpu = shell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%").toLowerCase();

var host = WScript.FullName.toLowerCase();

 

// check to see if we are on an AMD64 processor and running the

// wrong version of the scripting host.

if(host.indexOf("system32") != -1 && cpu == "amd64")

    {

    var syswow64Host = host.replace(/system32/g, "syswow64");

    var newCmd = syswow64Host + " \"" +

        WScript.ScriptFullName + "\" //Nologo";

 

    // ATTEMPT to pass all the same command

    //  line args to the new process

    var args = WScript.Arguments;

    for(i=0; i<args.length; i++)

        newCmd += " " + args(i);

 

    WScript.Echo("Running the syswow64 bit version instead...\n  " +

        newCmd + "\n");

 

    // launch the new script and echo all the output

    var exec = shell.Exec(newCmd);

    while(exec.Status == 0)

        {

        if(!exec.StdOut.AtEndOfStream)

            WScript.Echo(exec.StdOut.ReadAll());

        WScript.Sleep(100);

        }

 

    if(!exec.StdOut.AtEndOfStream)

        WScript.Echo(exec.StdOut.ReadAll());

 

    WScript.Quit(exec.ExitCode);

    }

 

// the real script code goes here ...

 

WScript.Echo("done");

 

In this sample we are just checking for AMD64, so you may want to add logic for Itanium or other platforms as well.

 

Be sure to notice the "ATTEMPT" comment when transposing the command line options from the current process into the new one. The way that the command shell handles double quotes makes it hard to reproduce the exact command line from the support we have in script. For example, if you pass /abc="hello world" as an argument, the quotes will get stripped out and you will actually see /abc=hello world from your script code. If we pass this raw argument (as shown above) into the new process then the one argument will be interpreted as two because of the missing quotes. It is left as a reader exercise to detect spaces and reconstruct the exact arguments if needed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值