我想要完整的Bogdan Mitrache的答案。 要执行此操作,我使用C#自定义操作来访问注册表并控制WOW行为。
public partial class CustomActions
{
#region marshalling RegCreateKeyEx RegOpenKeyEx RegCloseKey RegSetValueEx
[Flags]
public enum RegOption
{
NonVolatile = 0x0,
Volatile = 0x1,
CreateLink = 0x2,
BackupRestore = 0x4,
OpenLink = 0x8
}
[Flags]
public enum RegSAM
{
QueryValue = 0x0001,
SetValue = 0x0002,
CreateSubKey = 0x0004,
EnumerateSubKeys = 0x0008,
Notify = 0x0010,
CreateLink = 0x0020,
WOW64_32Key = 0x0200,
WOW64_64Key = 0x0100,
WOW64_Res = 0x0300,
Read = 0x00020019,
Write = 0x00020006,
Execute = 0x00020019,
AllAccess = 0x000f003f
}
public enum RegResult
{
CreatedNewKey = 0x00000001,
OpenedExistingKey = 0x00000002
}
//[StructLayout(LayoutKind.Sequential)]
//public class SECURITY_ATTRIBUTES
//{
// public int nLength;
// public unsafe byte* lpSecurityDescriptor;
// public int bInheritHandle;
//}
[StructLayout(LayoutKind.Sequential)]
public class SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public int bInheritHandle;
}
[DllImport("advapi32.dll", SetLastError = true)]
static extern int RegCreateKeyEx(
RegistryHive hKey,
string lpSubKey,
int Reserved,
string lpClass,
RegOption dwOptions,
RegSAM samDesired,
SECURITY_ATTRIBUTES lpSecurityAttributes,
out UIntPtr phkResult,
out RegResult lpdwDisposition);
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegOpenKeyEx")]
static extern int RegOpenKeyEx(
RegistryHive hKey,
string subKey,
uint options,
RegSAM sam,
out UIntPtr phkResult);
[DllImport("advapi32.dll", SetLastError = true)]
static extern int RegCloseKey(
UIntPtr hKey);
[DllImport("advapi32.dll", SetLastError = true)]
static extern uint RegSetValueEx(
UIntPtr hKey,
[MarshalAs(UnmanagedType.LPStr)]
string lpValueName,
int Reserved,
RegistryValueKind dwType,
[MarshalAs(UnmanagedType.LPStr)] string lpData,
int cbData);
const int KEY_WOW64_64KEY = 0x0100;
const int KEY_READ = 0x20019;
#endregion
private static uint WriteValue_String(UIntPtr hKey, string sName, string sValue)
{
uint setRes = RegSetValueEx(hKey, sName, 0, Microsoft.Win32.RegistryValueKind.String, sValue, sValue.Length + 1);
return setRes;
}
/// <summary>
/// Enable AutoLogon by changing the values of the system registry keys "DefaultUserName", "DefaultPassword" and "AutoAdminLogon"
/// in "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
/// </summary>
/// <param name="session"></param>
/// <returns></returns>
[CustomAction]
public static ActionResult EnableAutoLogon(Session session)
{
_session = session;
LogUtil.WriteDebugInfo(session, "Enter Function");
try
{
SECURITY_ATTRIBUTES secAttribs = new SECURITY_ATTRIBUTES();
UIntPtr hKey;
RegResult regResult;
LogUtil.WriteDebugInfo(session, "RegOpenKeyEx");
int result = RegOpenKeyEx(
RegistryHive.LocalMachine,
@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon",
0, //must be 0
RegSAM.WOW64_64Key | RegSAM.SetValue,
out hKey);
LogUtil.WriteDebugInfo(session, "WriteValue_String");
uint setRes = WriteValue_String(hKey, "DefaultUserName", "admin");
setRes = WriteValue_String(hKey, "DefaultPassword", "admin");
setRes = WriteValue_String(hKey, "AutoAdminLogon", "1");
LogUtil.WriteDebugInfo(session, "RegCloseKey");
int closeRes = RegCloseKey(hKey);
}
catch (System.Exception ex)
{
LogUtil.WriteDebugInfo(session, "Exception occured : " + ex.Message + "\n" + ex.StackTrace);
LogUtil.WriteDebugInfo(session, "Exit Function");
return ActionResult.Failure;
}
LogUtil.WriteDebugInfo(session, "Exit Function");
return ActionResult.Success;
}
}
KEY_WOW64_32KEY(0200)表示在64位的Windows 应用程序应在32位注册表视图操作。此标志是 被32位Windows忽略。有关更多信息,请参阅访问 备用注册表视图。
此标志必须使用OR运算符与此表中其他标志 进行组合,该标志可以查询或访问注册表值。
Windows 2000:此标志不受支持。
KEY_WOW64_64KEY(0x0100)指示应用程序在64位 Windows上应该在64位注册表视图上运行。此标志是 被32位Windows忽略。有关更多信息,请参阅访问 备用注册表视图。
此标志必须使用OR运算符与此表中其他标志 进行组合,该标志可以查询或访问注册表值。
Windows 2000:此标志不受支持。
谢谢...但是,我不想写一个文件,我试图启动一个可执行文件。我最惊讶的是,从注册表读取的字符串值正在改变(请参阅转储的属性值) - 我甚至没有尝试访问任何东西......该注册表项可用于x86和x64并具有相同的值。 – atlaste 2013-02-21 10:38:52
看到我上面的回复,我编辑了我的答案。 – 2013-02-21 12:04:16
这是丑陋的...所以这意味着我想我必须在2个安装程序(这很糟糕)或基于你如何解决这个(这也很糟糕)的优秀信息非常丑陋的黑客之间进行选择......我想我' m认真考虑以前的毒药并禁用WIX中其他平台的安装程序......我想我的第一个假设是它做了“替换”是错误的,而且我犯了一个错误,但是您确认它确实是*那*丑陋...该死的。谢谢。 – atlaste 2013-02-21 12:17:17