I am not sure if this will help, but here is some example code of how to use the function itself. I pretty much used Microsoft's MSDN and Pinvoke to knock up some quick code.
[DllImport("setupapi.dll", SetLastError = true)]
public static extern bool SetupCopyOEMInf(
string SourceInfFileName,
string OEMSourceMediaLocation,
OemSourceMediaType OEMSourceMediaType,
OemCopyStyle CopyStyle,
string DestinationInfFileName,
int DestinationInfFileNameSize,
ref int RequiredSize,
string DestinationInfFileNameComponent
);
/// <summary>
/// Driver media type
/// </summary>
internal enum OemSourceMediaType
{
SPOST_NONE = 0,
//Only use the following if you have a pnf file as well
SPOST_PATH = 1,
SPOST_URL = 2,
SPOST_MAX = 3
}
internal enum OemCopyStyle
{
SP_COPY_NEWER = 0x0000004, // copy only if source newer than or same as target
SP_COPY_NEWER_ONLY = 0x0010000, // copy only if source file newer than target
SP_COPY_OEMINF_CATALOG_ONLY = 0x0040000, // (SetupCopyOEMInf only) don't copy INF--just catalog
}
static void Main(string[] args)
{
//Not really needed but I couldn't figure out how to not specify a ref parameter
int size = 0;
bool success = SetupCopyOEMInf("source.inf", "", OemSourceMediaType.SPOST_NONE, OemCopyStyle.SP_COPY_NEWER, null, 0,
ref size, null);
if(!success)
{
var errorCode = Marshal.GetLastWin32Error();
var errorString = new Win32Exception(errorCode).Message;
Console.WriteLine(errorString);
Console.ReadLine();
}
}
Assuming your INF file is completely correct with the proper destination directories specified, this function will also try and copy any files that you have specified via the CopyFiles directive (in the INF file) to those destination directories. If the file doesnt exist, the command will fail.
One other problem I had was that the function should copy your INF and CAT files to the destination directory specified (I specified an ID of 12, which is documented as %windir%\system32\drivers) but instead it copied it to %windir%\system32\DriverStore\FileRepository\source.inf_amd64_neutral_blah. This was probably due to the fact I was testing with an inf file I created by hand and was missing required information.
Hope this helps you a bit :)