adobe air中通过注册表修改Windows代理设置的问题?

时间:2011-09-05 05:58:40

标签: flash flex actionscript-3 adobe air

我想在adobe air中修改windows代理设置。以下是我的代码。它不起作用。 它出什么问题了?谢谢。

public function enableProxy(started:Boolean):void 
        {

            if(NativeProcess.isSupported) {
                var OS:String = Capabilities.os.toLocaleLowerCase();
                var file:File;

                if (OS.indexOf('win') > -1) {
                    //Executable in windows
                    file = new File('C:\\Windows\\System32\\cmd.exe');
                } else if (OS.indexOf('mac') > -1 ) {
                    //Executable in mac
                } else if (OS.indexOf('linux')) {
                    //Executable in linux
                }

                var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                nativeProcessStartupInfo.executable = file;

                var args:Vector.<String> = new Vector.<String>();
                args.push("C:\\test\\ModifyProxy.bat");
                nativeProcessStartupInfo.arguments = args;
                startExecution(nativeProcessStartupInfo);
            }
        }

        private function startExecution(nativeProcessStartupInfo:NativeProcessStartupInfo):void
        {
            var nativeProcess:NativeProcess = new NativeProcess();
            nativeProcess.addEventListener(NativeProcessExitEvent.EXIT, onExitError);
            var msg:String = "";

            try {
                nativeProcess.start(nativeProcessStartupInfo);
                trace("Trying to start process");
            } catch (error:IllegalOperationError) {
                trace("Illegal Operation: "+error.toString());
            } catch (error:ArgumentError) {
                trace("Argument Error: "+error.toString());
            } catch (error:Error) {
                trace("Error: "+error.toString());
            }

            if (nativeProcess.running) {
                trace("Native Process Support");
            }
        }

        public function onExitError(event:NativeProcessExitEvent):void
        {
            trace("Native Process Exit code: " + event.exitCode);
        }

ModifyProxy.bat

REG ADD“HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Internet Settings”/ v ProxyServer / d“http = testwronguw:8888; https = testwronguw:8888;” / t REG_SZ / f

2 个答案:

答案 0 :(得分:0)

不同应用程序的权限不同。如果您通过命令行运行bat,它将不会与通过应用程序执行该操作具有相同的效果,因为您从未批准该应用程序执行此类操作。

尝试使用“以管理员身份运行”运行应用程序(右键单击开始菜单中的应用程序)。我很相信它能起作用。我不认为动态获得该许可是可能的,但我可能是错的。

答案 1 :(得分:0)

像这样改变

var arg2:Vector。 = new Vector。(); arg2.push( “/ C”, “C:\测试\ ModifyProxy.bat”);

相关问题