2017-05-23 4 views
1
私は、次の環境設定があるWebアプリケーションに取り組んでいます

:ウェブサイトは インストールし、グループポリシー

  • ウェブサイトChromeで動作するように設計されて

    1. はクロームに依存します社内で開発され、Chrome Playストアでホストされる拡張機能
    2. 拡張機能を簡単にするため、GoogleのシステムチームでExtensionInstallForcelistグループポリシーを設定しています(詳しくはhttp://dev.chromium.org/administrators/policy-list-3#ExtensionInstallForcelist)。これにより、Chromeは拡張機能を入手し、必要に応じて手動によるユーザーの操作を必要とせずに更新できるようになります。
    3. これはイメージングされたデバイス上にすべて設定されています(別々のブラウザーとグループポリシーを持つ別々のデバイスで、それぞれ独自に拡張子を取得します)

    私が直面している問題は、このグループポリシーでChromedriverインスタンスを使用しようとするときです。

    ポリシーを有効にすると、「拡張子を読み込めませんでした:。(拡張ID)が管理者によってブロックされました」というエラーが表示されます。私たちのテストを実行するとき。

    これは、Chromeオプション(拡張機能の追加)を通じてChromedriverに拡張機能を追加したためです。

    これを回避するために、私たちのイメージングされたデバイスのグループポリシーを手動でオフにすることはできますが、Chromedriverに拡張機能をインストールできるようにグループポリシーに追加できる設定があるのでしょうか?

    私が動作するようには思えなかったことそれ以外の場合はこれを回避するには、いくつかの方法を試してみた:グループポリシーで設定されたレジストリ値の

    1. コマンドラインの変更 - 、として動作しませんでしたレジストリ値を変更しても問題は解決しましたが、まだテスト実行中にエラーが発生しました
    2. グループポリシーのPowerShell変更 - Get Group Policyコマンドレットの追加インストールが必要なため動作しません。
    3. GPMC C#ライブラリはこの時点で非常に古くなっているようです(.NET 2.0を使用するものもあります)。クラスを使用するためのコードをいくつかセットアップできましたが、GPODomainオブジェクトを作成するための「参照が見つかりません」という例外が発生しました。

    ありがとうございますChromedriverをforce installグループポリシーで動作させる。

  • 答えて

    0

    ウェブ上のさまざまな回答をたくさん見た後、私はこの解決策が動作することを発見しました。

    [STAThread] 
        private static bool DisabledChromeExtensionGPO() 
        { 
         var PolicyExists = ComputerGroupPolicyObject.GetPolicySetting(@"HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\ExtensionInstallForcelist!1"); 
    
         if (PolicyExists != null) 
         { 
    
          ComputerGroupPolicyObject.SetPolicySetting(@"HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\ExtensionInstallForcelist!1", "null", RegistryValueKind.String); 
         } 
    
         return true; 
        } 
    

    ながら:このような呼び出しを使ってChrome拡張グループポリシーをインストールし

    }

    using Microsoft.Win32; 
    using Microsoft.Win32.SafeHandles; 
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Reflection; 
    using System.Runtime.InteropServices; 
    using System.Text; 
    using System.Threading; 
    using System.Threading.Tasks; 
    
    namespace Automation.Core 
    { 
    [ComImport, Guid("EA502722-A23D-11d1-A7D3-0000F87571E3")] 
    internal class GPClass 
    { 
    } 
    
    [ComImport, Guid("EA502723-A23D-11d1-A7D3-0000F87571E3"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 
    public interface IGroupPolicyObject 
    { 
        uint New([MarshalAs(UnmanagedType.LPWStr)] string domainName, [MarshalAs(UnmanagedType.LPWStr)] string displayName, uint flags); 
    
        uint OpenDSGPO([MarshalAs(UnmanagedType.LPWStr)] string path, uint flags); 
    
        uint OpenLocalMachineGPO(uint flags); 
    
        uint OpenRemoteMachineGPO([MarshalAs(UnmanagedType.LPWStr)] string computerName, uint flags); 
    
        uint Save([MarshalAs(UnmanagedType.Bool)] bool machine, [MarshalAs(UnmanagedType.Bool)] bool add, [MarshalAs(UnmanagedType.LPStruct)] Guid extension, [MarshalAs(UnmanagedType.LPStruct)] Guid app); 
    
        uint Delete(); 
    
        uint GetName([MarshalAs(UnmanagedType.LPWStr)] StringBuilder name, int maxLength); 
    
        uint GetDisplayName([MarshalAs(UnmanagedType.LPWStr)] StringBuilder name, int maxLength); 
    
        uint SetDisplayName([MarshalAs(UnmanagedType.LPWStr)] string name); 
    
        uint GetPath([MarshalAs(UnmanagedType.LPWStr)] StringBuilder path, int maxPath); 
    
        uint GetDSPath(uint section, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder path, int maxPath); 
    
        uint GetFileSysPath(uint section, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder path, int maxPath); 
    
        uint GetRegistryKey(uint section, out IntPtr key); 
    
        uint GetOptions(out uint options); 
    
        uint SetOptions(uint options, uint mask); 
    
        uint GetType(out IntPtr gpoType); 
    
        uint GetMachineName([MarshalAs(UnmanagedType.LPWStr)] StringBuilder name, int maxLength); 
    
        uint GetPropertySheetPages(out IntPtr pages); 
    } 
    
    
    public enum GroupPolicySection 
    { 
        Root = 0, 
        User = 1, 
        Machine = 2, 
    } 
    
    public abstract class GroupPolicyObject 
    { 
        protected const int MaxLength = 1024; 
    
        /// <summary> 
        /// The snap-in that processes .pol files 
        /// </summary> 
        private static readonly Guid RegistryExtension = new Guid(0x35378EAC, 0x683F, 0x11D2, 0xA8, 0x9A, 0x00, 0xC0, 0x4F, 0xBB, 0xCF, 0xA2); 
    
        /// <summary> 
        /// This application 
        /// </summary> 
        private static readonly Guid LocalGuid = new Guid(GetAssemblyAttribute<GuidAttribute>(Assembly.GetExecutingAssembly()).Value); 
    
        protected IGroupPolicyObject Instance = (IGroupPolicyObject) new GPClass(); 
    
        static T GetAssemblyAttribute<T>(ICustomAttributeProvider assembly) where T : Attribute 
        { 
         object[] attributes = assembly.GetCustomAttributes(typeof(T), true); 
         if (attributes.Length == 0) 
          return null; 
    
         return (T)attributes[0]; 
        } 
    
        public void Save() 
        { 
         var result = Instance.Save(true, true, RegistryExtension, LocalGuid); 
         if (result != 0) 
         { 
          throw new Exception("Error saving machine settings"); 
         } 
    
         result = Instance.Save(false, true, RegistryExtension, LocalGuid); 
         if (result != 0) 
         { 
          throw new Exception("Error saving user settings"); 
         } 
        } 
    
        public RegistryKey GetRootRegistryKey(GroupPolicySection section) 
        { 
         IntPtr key; 
         var result = Instance.GetRegistryKey((uint)section, out key); 
         if (result != 0) 
         { 
          throw new Exception(string.Format("Unable to get section '{0}'", Enum.GetName(typeof(GroupPolicySection), section))); 
         } 
    
         var handle = new SafeRegistryHandle(key, true); 
         return RegistryKey.FromHandle(handle, RegistryView.Default); 
        } 
    } 
    
    public class GroupPolicyObjectSettings 
    { 
        public readonly bool LoadRegistryInformation; 
        public readonly bool Readonly; 
    
        public GroupPolicyObjectSettings(bool loadRegistryInfo = true, bool readOnly = false) 
        { 
         LoadRegistryInformation = loadRegistryInfo; 
         Readonly = readOnly; 
        } 
    
        private const uint RegistryFlag = 0x00000001; 
        private const uint ReadonlyFlag = 0x00000002; 
    
        internal uint Flag 
        { 
         get 
         { 
          uint flag = 0x00000000; 
          if (LoadRegistryInformation) 
          { 
           flag |= RegistryFlag; 
          } 
    
          if (Readonly) 
          { 
           flag |= ReadonlyFlag; 
          } 
    
          return flag; 
         } 
        } 
    } 
    
    public class ComputerGroupPolicyObject : GroupPolicyObject 
    { 
        public readonly bool IsLocal; 
    
        public ComputerGroupPolicyObject(GroupPolicyObjectSettings options = null) 
        { 
         options = options ?? new GroupPolicyObjectSettings(); 
         var result = Instance.OpenLocalMachineGPO(options.Flag); 
         if (result != 0) 
         { 
          throw new Exception("Unable to open local machine GPO"); 
         } 
         IsLocal = true; 
        } 
    
        public static void SetPolicySetting(string registryInformation, string settingValue, RegistryValueKind registryValueKind) 
        { 
         string valueName; 
         GroupPolicySection section; 
         string key = Key(registryInformation, out valueName, out section); 
    
         // Thread must be STA 
         Exception exception = null; 
         var t = new Thread(() => 
         { 
          try 
          { 
           var gpo = new ComputerGroupPolicyObject(); 
           using (RegistryKey rootRegistryKey = gpo.GetRootRegistryKey(section)) 
           { 
            // Data can't be null so we can use this value to indicate key must be delete 
            if (settingValue == null) 
            { 
             using (RegistryKey subKey = rootRegistryKey.OpenSubKey(key, true)) 
             { 
              if (subKey != null) 
              { 
               subKey.DeleteValue(valueName); 
              } 
             } 
            } 
            else 
            { 
             using (RegistryKey subKey = rootRegistryKey.CreateSubKey(key)) 
             { 
              subKey.SetValue(valueName, settingValue, registryValueKind); 
             } 
            } 
           } 
    
           gpo.Save(); 
          } 
          catch (Exception ex) 
          { 
           exception = ex; 
          } 
         }); 
         t.SetApartmentState(ApartmentState.STA); 
         t.Start(); 
         t.Join(); 
    
         if (exception != null) 
          throw exception; 
        } 
    
        public static object GetPolicySetting(string registryInformation) 
        { 
         string valueName; 
         GroupPolicySection section; 
         string key = Key(registryInformation, out valueName, out section); 
    
         // Thread must be STA 
         object result = null; 
         var t = new Thread(() => 
         { 
          var gpo = new ComputerGroupPolicyObject(); 
          using (RegistryKey rootRegistryKey = gpo.GetRootRegistryKey(section)) 
          { 
           // Data can't be null so we can use this value to indicate key must be delete 
           using (RegistryKey subKey = rootRegistryKey.OpenSubKey(key, true)) 
           { 
            if (subKey == null) 
            { 
             result = null; 
            } 
            else 
            { 
             result = subKey.GetValue(valueName); 
            } 
           } 
          } 
         }); 
         t.SetApartmentState(ApartmentState.STA); 
         t.Start(); 
         t.Join(); 
    
         return result; 
        } 
    
        public static string Key(string registryInformation, out string value, out GroupPolicySection section) 
        { 
         // Parse parameter of format HKCU\Software\Policies\Microsoft\Windows\Personalization!NoChangingSoundScheme 
         string[] split = registryInformation.Split('!'); 
         string key = split[0]; 
         string hive = key.Substring(0, key.IndexOf('\\')); 
         key = key.Substring(key.IndexOf('\\') + 1); 
    
         value = split[1]; 
    
         if (hive.Equals(@"HKLM", StringComparison.OrdinalIgnoreCase) 
          || hive.Equals(@"HKEY_LOCAL_MACHINE", StringComparison.OrdinalIgnoreCase)) 
         { 
          section = GroupPolicySection.Machine; 
         } 
         else 
         { 
          section = GroupPolicySection.User; 
         } 
         return key; 
        } 
    } 
    

    を強制的にオフにします。

    それとの対話処理するために、グループポリシーのクラスを作成します。ポリシーは引き続きregeditにそのキーを表示しますが、キーの値はnullに設定されます。

    この値をnullに設定すると、現時点でChrome搭載ドライバでローカルChrome拡張ファイルを読み込むことができました。

    関連する問題