开发者

The problem on Modify windows proxy settings via registry in adobe air?

I want to modify windows proxy settings in adobe air. Below is my code. It doesn't work. What's wrong with it? Thanks.

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");
            }
        }

        p开发者_运维技巧ublic 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


Permission is not the same for different applications. If you run the bat through command line, it won't have the same effect as doing it through the app since you've never approved the app to do such a thing.

Try running the application with "run as administrator" (right-click app in start menu). I'm fairly sure it would work them. I don't think it's possible to get that permission dynamically, but I could be wrong.


change like this

var arg2:Vector. = new Vector.(); arg2.push("/c","C:\test\ModifyProxy.bat");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜