3 Replies Latest reply on Jun 11, 2011 5:11 AM by Jens Eckervogt

    Example for Runasadmin with AIr Applications

    Jens Eckervogt



      i have problem of nativepath because nativepathw rite to reg file example:


      How does air app work when air app writes double backsplash "\\".


      I have been coded thsi example for writing reg file than air app opens cmd file than cmd calls admin right of regedit.


      protected function init(event:FlexEvent):void
                          // Center main AIR app window on the screen
                          nativeWindow.x = (Capabilities.screenResolutionX - nativeWindow.width) / 2;
                          nativeWindow.y = (Capabilities.screenResolutionY - nativeWindow.height) / 2;
                          // Load regFile and cmdFile
                     private var airAdminFile:File = File.applicationDirectory.resolvePath("AirAdmin.exe");
                     private var regeditFile:File = new File("C:\\Windows\\regedit.exe");
                     private var regFile:File = File.documentsDirectory.resolvePath("AirAdmin.reg");
                     private var cmdFile:File = File.documentsDirectory.resolvePath("AirAdmin.cmd");
                     private var cmdAppFile:File = new File("C:\\Windows\\System32\\cmd.exe");
                     protected function getRegFile():void
                          // regfile
                          var regFileStream:FileStream = new FileStream;
                          var regFileStructur:String = 'Windows Registry Editor Version 5.00\n';
                          regFileStructur += File.separator + "\n" + File.lineEnding;
                          regFileStructur += '[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers]\n' + File.lineEnding;
                          regFileStructur += '"' + airAdminFile.nativePath + '"="RUNASADMIN"\n' + File.lineEnding;
                          var cmdFileStream:FileStream = new FileStream;
                          var cmdFileContent:String = regeditFile.nativePath + ' /s "' +regFile.nativePath + '"' + File.lineEnding;
                          if(regFile.exists, cmdFile.exists)
                               regFileStream.open(regFile, FileMode.READ);
                               regFileStructur = String(regFileStream.readUTFBytes(regFileStream.bytesAvailable));
                               cmdFileStream.open(cmdFile, FileMode.READ);
                               cmdFileContent = String(cmdFileStream.readUTFBytes(cmdFileStream.bytesAvailable));
                               regFileStream.open(regFile, FileMode.WRITE);
                               cmdFileStream.open(cmdFile, FileMode.WRITE);
                     protected function openShell():void


      Than i try example when air application gets to administrative mode.


      PS: If your air app already is in the administrative mode. Than it will change to state like this




      Than it runs with administrative right. If you like your app with rewriting and deleting function once applicationDirectory


      I hope you because it should fix for "\\" in regfile


      Why does nativepath not work with "\\" , when air app create regfile:

      Windows Registry Editor Version 5.00
      [HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
      "C:\Program Files (x86)\AirAdmin\AirAdmin.exe"="RUNASADMIN"


      I try nativepath with air app function "\" to "\\" via replacement?


      Windows Registry Editor Version 5.00
      [HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
      "C:\\Program Files (x86)\\AirAdmin\\AirAdmin.exe"="RUNASADMIN"


      How does air app write when regfile does not give error with "\\"?


      Can you help me? I can not find google Problem with nativepath


      Thanks Jens