简体   繁体   中英

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

        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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM