I was hoping someone could help me get SetupInstallFro mInfSection
working properly. I'm trying to start in install section in a driver
INF (hal.inf specifically). I'm doing this in C#, but I also tried it
in C++ with (MOSTLY) the same parameters and got the same error, which
is 1004 (Invalid Flags).
Here's my C# code that I'm using. Any help would be MOST appreciated.
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Runtime. InteropServices ;
using System.IO;
namespace UIUHWScan.Class es
{
public class UpdateHAL
{
#region Constants
const int INF_STYLE_NONE = 0;
const int INF_STYLE_OLDNT = 1;
const int INF_STYLE_WIN4 = 2;
//
// Flags for SetupInstallFro mInfSection
//
const uint SPINST_LOGCONFI G =0x00000001;
const uint SPINST_INIFILES = 0x00000002;
const uint SPINST_REGISTRY = 0x00000004;
const uint SPINST_INI2REG = 0x00000008;
const uint SPINST_FILES = 0x00000010;
const uint SPINST_BITREG = 0x00000020;
const uint SPINST_REGSVR = 0x00000040;
const uint SPINST_UNREGSVR = 0x00000080;
const uint SPINST_PROFILEI TEMS = 0x00000100;
const uint SPINST_COPYINF = 0x00000200;
const uint SPINST_ALL = 0x000003ff;
const uint SPINST_SINGLESE CTION = 0x00010000;
const uint SPINST_LOGCONFI G_IS_FORCED = 0x00020000;
const uint SPINST_LOGCONFI GS_ARE_OVERRIDE S = 0x00040000;
const uint SPINST_REGISTER CALLBACKAWARE = 0x00080000;
const uint SPINST_DEVICEIN STALL = 0x00100000;
//
// CopyStyle values for copy and queue-related APIs
//
const uint SP_COPY_DELETES OURCE = 0x0000001; // delete
source file on successful copy
const uint SP_COPY_REPLACE ONLY = 0x0000002; // copy only if
target file already present
const uint SP_COPY_NEWER = 0x0000004; // copy only if source
newer than or same as target
const uint SP_COPY_NEWER_O R_SAME = SP_COPY_NEWER;
const uint SP_COPY_NOOVERW RITE = 0x0000008; // copy only if
target doesn't exist
const uint SP_COPY_NODECOM P = 0x0000010; // don't decompress
source file while copying
const uint SP_COPY_LANGUAG EAWARE = 0x0000020; // don't
overwrite file of different language
const uint SP_COPY_SOURCE_ ABSOLUTE = 0x0000040; //
SourceFile is a full source path
const uint SP_COPY_SOURCEP ATH_ABSOLUTE = 0x0000080; //
SourcePathRoot is the full path
const uint SP_COPY_IN_USE_ NEEDS_REBOOT = 0x0000100; //
System needs reboot if file in use
const uint SP_COPY_FORCE_I N_USE = 0x0000200; // Force
target-
in-use behavior
const uint SP_COPY_NOSKIP = 0x0000400; // Skip is disallowed
for this file or section
const uint SP_FLAG_CABINET CONTINUATION = 0x0000800; // Used
with need media notification
const uint SP_COPY_FORCE_N OOVERWRITE = 0x0001000; // like
NOOVERWRITE but no callback nofitication
const uint SP_COPY_FORCE_N EWER = 0x0002000; // like NEWER
but no callback nofitication
const uint SP_COPY_WARNIFS KIP = 0x0004000; // system
critical file: warn if user tries to skip
const uint SP_COPY_NOBROWS E = 0x0008000; // Browsing is
disallowed for this file or section
const uint SP_COPY_NEWER_O NLY = 0x0010000; // copy only if
source file newer than target
const uint SP_COPY_RESERVE D = 0x0020000; // was:
SP_COPY_SOURCE_ SIS_MASTER (deprecated)
const uint SP_COPY_OEMINF_ CATALOG_ONLY = 0x0040000; //
(SetupCopyOEMIn f only) don't copy INF--just catalog
const uint SP_COPY_REPLACE _BOOT_FILE = 0x0080000; // file
must be present upon reboot (i.e., it's
// needed by
the loader); this flag implies a reboot
const long HKEY_LOCAL_MACH INE = 0x80000002L;
//
// Operation/queue start/end notification. These are ordinal
values.
//
const uint SPFILENOTIFY_ST ARTQUEUE =0x00000001;
const uint SPFILENOTIFY_EN DQUEUE =0x00000002;
const uint SPFILENOTIFY_ST ARTSUBQUEUE =0x00000003;
const uint SPFILENOTIFY_EN DSUBQUEUE =0x00000004;
const uint SPFILENOTIFY_ST ARTDELETE =0x00000005;
const uint SPFILENOTIFY_EN DDELETE =0x00000006;
const uint SPFILENOTIFY_DE LETEERROR =0x00000007;
const uint SPFILENOTIFY_ST ARTRENAME =0x00000008;
const uint SPFILENOTIFY_EN DRENAME =0x00000009;
const uint SPFILENOTIFY_RE NAMEERROR =0x0000000a;
const uint SPFILENOTIFY_ST ARTCOPY =0x0000000b;
const uint SPFILENOTIFY_EN DCOPY =0x0000000c;
const uint SPFILENOTIFY_CO PYERROR =0x0000000d;
const uint SPFILENOTIFY_NE EDMEDIA =0x0000000e;
const uint SPFILENOTIFY_QU EUESCAN = 0x0000000f;
const uint SPFILENOTIFY_FI LEINCABINET = 0x00000011; // The
file has been extracted from the cabinet.
const uint SPFILENOTIFY_NE EDNEWCABINET = 0x00000012; // file
is encountered in the cabinet.
const uint SPFILENOTIFY_FI LEEXTRACTED = 0x00000013; // The
current file is continued in the next cabinet.
const uint NO_ERROR = 0;
#endregion
#region Delegates
public delegate uint PSP_FILE_CALLBA CK(uint context, uint
notifaction,
IntPtr param1, IntPtr param2);
#endregion
#region DLL Imports
[DllImport("setu papi.dll", SetLastError = true, CharSet =
CharSet.Unicode )]
private static extern bool SetupInstallFro mInfSection(Int Ptr
owner,
IntPtr infHandle, string sectionName, uint flags, IntPtr
hKey,
IntPtr sourceRootPath, uint copyFlags, PSP_FILE_CALLBA CK
msgHandler,
ref uint context, IntPtr deviceInfoSet, IntPtr
deviceInfoData) ;
[DllImport("setu papi.dll", SetLastError = true)]
public static extern IntPtr SetupOpenInfFil e(
string FileName,
IntPtr InfClass,
int InfStyle,
int ErrorLine
);
[DllImport("setu papi.dll", SetLastError = true)]
public static extern void SetupCloseInfFi le(
IntPtr InfHandle
);
#endregion
/// <summary>
/// The FileCallback callback function is used by a number of
the setup functions. The PSP_FILE_CALLBA CK type defines a pointer to
this callback function. FileCallback is a placeholder for the
application-defined function name.
/// Platform SDK: Setup API
/// </summary>
private uint CallBack(uint context, uint notification, IntPtr
param1, IntPtr param2)
{
uint rtnValue = NO_ERROR;
Console.WriteLi ne("CallBack: Context = {0}, Notifacation =
{1}",
context, notification);
return rtnValue;
}
public bool InstallSection( )
{
string windowsFolder =
Environment.Get EnvironmentVari able("WINDIR");
string halINF = Path.Combine(wi ndowsFolder, @"inf
\hal.inf");
IntPtr hInf = SetupOpenInfFil e(halINF, IntPtr.Zero,
INF_STYLE_WIN4, 0);
if (hInf == (IntPtr)(-1))
{
int err = Marshal.GetLast Win32Error();
Console.WriteLi ne("Invalid INF File: {0}", halINF);
return false;
}
try
{
string installSection = "E_ISA_UP_H AL";
bool iResult = false;
PSP_FILE_CALLBA CK callback = new
PSP_FILE_CALLBA CK(CallBack);
uint context = 0;
unchecked
{
SetupInstallFro mInfSection(Int Ptr.Zero, hInf,
installSection,
SPINST_ALL, new
IntPtr((int)HKE Y_LOCAL_MACHINE ), IntPtr.Zero,
SP_COPY_FORCE_I N_USE, callback, ref context,
IntPtr.Zero, IntPtr.Zero);
}
if (!iResult)
{
int err = Marshal.GetLast Win32Error();
Console.WriteLi ne("Error : {0}",
err.ToString("x "));
return false;
}
Console.WriteLi ne("Successfull !");
}
finally
{
SetupCloseInfFi le(hInf);
}
return true;
}
}
}
working properly. I'm trying to start in install section in a driver
INF (hal.inf specifically). I'm doing this in C#, but I also tried it
in C++ with (MOSTLY) the same parameters and got the same error, which
is 1004 (Invalid Flags).
Here's my C# code that I'm using. Any help would be MOST appreciated.
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Runtime. InteropServices ;
using System.IO;
namespace UIUHWScan.Class es
{
public class UpdateHAL
{
#region Constants
const int INF_STYLE_NONE = 0;
const int INF_STYLE_OLDNT = 1;
const int INF_STYLE_WIN4 = 2;
//
// Flags for SetupInstallFro mInfSection
//
const uint SPINST_LOGCONFI G =0x00000001;
const uint SPINST_INIFILES = 0x00000002;
const uint SPINST_REGISTRY = 0x00000004;
const uint SPINST_INI2REG = 0x00000008;
const uint SPINST_FILES = 0x00000010;
const uint SPINST_BITREG = 0x00000020;
const uint SPINST_REGSVR = 0x00000040;
const uint SPINST_UNREGSVR = 0x00000080;
const uint SPINST_PROFILEI TEMS = 0x00000100;
const uint SPINST_COPYINF = 0x00000200;
const uint SPINST_ALL = 0x000003ff;
const uint SPINST_SINGLESE CTION = 0x00010000;
const uint SPINST_LOGCONFI G_IS_FORCED = 0x00020000;
const uint SPINST_LOGCONFI GS_ARE_OVERRIDE S = 0x00040000;
const uint SPINST_REGISTER CALLBACKAWARE = 0x00080000;
const uint SPINST_DEVICEIN STALL = 0x00100000;
//
// CopyStyle values for copy and queue-related APIs
//
const uint SP_COPY_DELETES OURCE = 0x0000001; // delete
source file on successful copy
const uint SP_COPY_REPLACE ONLY = 0x0000002; // copy only if
target file already present
const uint SP_COPY_NEWER = 0x0000004; // copy only if source
newer than or same as target
const uint SP_COPY_NEWER_O R_SAME = SP_COPY_NEWER;
const uint SP_COPY_NOOVERW RITE = 0x0000008; // copy only if
target doesn't exist
const uint SP_COPY_NODECOM P = 0x0000010; // don't decompress
source file while copying
const uint SP_COPY_LANGUAG EAWARE = 0x0000020; // don't
overwrite file of different language
const uint SP_COPY_SOURCE_ ABSOLUTE = 0x0000040; //
SourceFile is a full source path
const uint SP_COPY_SOURCEP ATH_ABSOLUTE = 0x0000080; //
SourcePathRoot is the full path
const uint SP_COPY_IN_USE_ NEEDS_REBOOT = 0x0000100; //
System needs reboot if file in use
const uint SP_COPY_FORCE_I N_USE = 0x0000200; // Force
target-
in-use behavior
const uint SP_COPY_NOSKIP = 0x0000400; // Skip is disallowed
for this file or section
const uint SP_FLAG_CABINET CONTINUATION = 0x0000800; // Used
with need media notification
const uint SP_COPY_FORCE_N OOVERWRITE = 0x0001000; // like
NOOVERWRITE but no callback nofitication
const uint SP_COPY_FORCE_N EWER = 0x0002000; // like NEWER
but no callback nofitication
const uint SP_COPY_WARNIFS KIP = 0x0004000; // system
critical file: warn if user tries to skip
const uint SP_COPY_NOBROWS E = 0x0008000; // Browsing is
disallowed for this file or section
const uint SP_COPY_NEWER_O NLY = 0x0010000; // copy only if
source file newer than target
const uint SP_COPY_RESERVE D = 0x0020000; // was:
SP_COPY_SOURCE_ SIS_MASTER (deprecated)
const uint SP_COPY_OEMINF_ CATALOG_ONLY = 0x0040000; //
(SetupCopyOEMIn f only) don't copy INF--just catalog
const uint SP_COPY_REPLACE _BOOT_FILE = 0x0080000; // file
must be present upon reboot (i.e., it's
// needed by
the loader); this flag implies a reboot
const long HKEY_LOCAL_MACH INE = 0x80000002L;
//
// Operation/queue start/end notification. These are ordinal
values.
//
const uint SPFILENOTIFY_ST ARTQUEUE =0x00000001;
const uint SPFILENOTIFY_EN DQUEUE =0x00000002;
const uint SPFILENOTIFY_ST ARTSUBQUEUE =0x00000003;
const uint SPFILENOTIFY_EN DSUBQUEUE =0x00000004;
const uint SPFILENOTIFY_ST ARTDELETE =0x00000005;
const uint SPFILENOTIFY_EN DDELETE =0x00000006;
const uint SPFILENOTIFY_DE LETEERROR =0x00000007;
const uint SPFILENOTIFY_ST ARTRENAME =0x00000008;
const uint SPFILENOTIFY_EN DRENAME =0x00000009;
const uint SPFILENOTIFY_RE NAMEERROR =0x0000000a;
const uint SPFILENOTIFY_ST ARTCOPY =0x0000000b;
const uint SPFILENOTIFY_EN DCOPY =0x0000000c;
const uint SPFILENOTIFY_CO PYERROR =0x0000000d;
const uint SPFILENOTIFY_NE EDMEDIA =0x0000000e;
const uint SPFILENOTIFY_QU EUESCAN = 0x0000000f;
const uint SPFILENOTIFY_FI LEINCABINET = 0x00000011; // The
file has been extracted from the cabinet.
const uint SPFILENOTIFY_NE EDNEWCABINET = 0x00000012; // file
is encountered in the cabinet.
const uint SPFILENOTIFY_FI LEEXTRACTED = 0x00000013; // The
current file is continued in the next cabinet.
const uint NO_ERROR = 0;
#endregion
#region Delegates
public delegate uint PSP_FILE_CALLBA CK(uint context, uint
notifaction,
IntPtr param1, IntPtr param2);
#endregion
#region DLL Imports
[DllImport("setu papi.dll", SetLastError = true, CharSet =
CharSet.Unicode )]
private static extern bool SetupInstallFro mInfSection(Int Ptr
owner,
IntPtr infHandle, string sectionName, uint flags, IntPtr
hKey,
IntPtr sourceRootPath, uint copyFlags, PSP_FILE_CALLBA CK
msgHandler,
ref uint context, IntPtr deviceInfoSet, IntPtr
deviceInfoData) ;
[DllImport("setu papi.dll", SetLastError = true)]
public static extern IntPtr SetupOpenInfFil e(
string FileName,
IntPtr InfClass,
int InfStyle,
int ErrorLine
);
[DllImport("setu papi.dll", SetLastError = true)]
public static extern void SetupCloseInfFi le(
IntPtr InfHandle
);
#endregion
/// <summary>
/// The FileCallback callback function is used by a number of
the setup functions. The PSP_FILE_CALLBA CK type defines a pointer to
this callback function. FileCallback is a placeholder for the
application-defined function name.
/// Platform SDK: Setup API
/// </summary>
private uint CallBack(uint context, uint notification, IntPtr
param1, IntPtr param2)
{
uint rtnValue = NO_ERROR;
Console.WriteLi ne("CallBack: Context = {0}, Notifacation =
{1}",
context, notification);
return rtnValue;
}
public bool InstallSection( )
{
string windowsFolder =
Environment.Get EnvironmentVari able("WINDIR");
string halINF = Path.Combine(wi ndowsFolder, @"inf
\hal.inf");
IntPtr hInf = SetupOpenInfFil e(halINF, IntPtr.Zero,
INF_STYLE_WIN4, 0);
if (hInf == (IntPtr)(-1))
{
int err = Marshal.GetLast Win32Error();
Console.WriteLi ne("Invalid INF File: {0}", halINF);
return false;
}
try
{
string installSection = "E_ISA_UP_H AL";
bool iResult = false;
PSP_FILE_CALLBA CK callback = new
PSP_FILE_CALLBA CK(CallBack);
uint context = 0;
unchecked
{
SetupInstallFro mInfSection(Int Ptr.Zero, hInf,
installSection,
SPINST_ALL, new
IntPtr((int)HKE Y_LOCAL_MACHINE ), IntPtr.Zero,
SP_COPY_FORCE_I N_USE, callback, ref context,
IntPtr.Zero, IntPtr.Zero);
}
if (!iResult)
{
int err = Marshal.GetLast Win32Error();
Console.WriteLi ne("Error : {0}",
err.ToString("x "));
return false;
}
Console.WriteLi ne("Successfull !");
}
finally
{
SetupCloseInfFi le(hInf);
}
return true;
}
}
}