473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help with SetupInstallFromInfSection

I was hoping someone could help me get SetupInstallFromInfSection
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.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace UIUHWScan.Classes
{
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 SetupInstallFromInfSection
//
const uint SPINST_LOGCONFIG =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_PROFILEITEMS = 0x00000100;

const uint SPINST_COPYINF = 0x00000200;
const uint SPINST_ALL = 0x000003ff;

const uint SPINST_SINGLESECTION = 0x00010000;
const uint SPINST_LOGCONFIG_IS_FORCED = 0x00020000;
const uint SPINST_LOGCONFIGS_ARE_OVERRIDES = 0x00040000;
const uint SPINST_REGISTERCALLBACKAWARE = 0x00080000;
const uint SPINST_DEVICEINSTALL = 0x00100000;

//
// CopyStyle values for copy and queue-related APIs
//
const uint SP_COPY_DELETESOURCE = 0x0000001; // delete
source file on successful copy
const uint SP_COPY_REPLACEONLY = 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_OR_SAME = SP_COPY_NEWER;
const uint SP_COPY_NOOVERWRITE = 0x0000008; // copy only if
target doesn't exist
const uint SP_COPY_NODECOMP = 0x0000010; // don't decompress
source file while copying
const uint SP_COPY_LANGUAGEAWARE = 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_SOURCEPATH_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_IN_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_CABINETCONTINUATION = 0x0000800; // Used
with need media notification
const uint SP_COPY_FORCE_NOOVERWRITE = 0x0001000; // like
NOOVERWRITE but no callback nofitication
const uint SP_COPY_FORCE_NEWER = 0x0002000; // like NEWER
but no callback nofitication
const uint SP_COPY_WARNIFSKIP = 0x0004000; // system
critical file: warn if user tries to skip
const uint SP_COPY_NOBROWSE = 0x0008000; // Browsing is
disallowed for this file or section
const uint SP_COPY_NEWER_ONLY = 0x0010000; // copy only if
source file newer than target
const uint SP_COPY_RESERVED = 0x0020000; // was:
SP_COPY_SOURCE_SIS_MASTER (deprecated)
const uint SP_COPY_OEMINF_CATALOG_ONLY = 0x0040000; //
(SetupCopyOEMInf 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_MACHINE = 0x80000002L;

//
// Operation/queue start/end notification. These are ordinal
values.
//
const uint SPFILENOTIFY_STARTQUEUE =0x00000001;
const uint SPFILENOTIFY_ENDQUEUE =0x00000002;
const uint SPFILENOTIFY_STARTSUBQUEUE =0x00000003;
const uint SPFILENOTIFY_ENDSUBQUEUE =0x00000004;
const uint SPFILENOTIFY_STARTDELETE =0x00000005;
const uint SPFILENOTIFY_ENDDELETE =0x00000006;
const uint SPFILENOTIFY_DELETEERROR =0x00000007;
const uint SPFILENOTIFY_STARTRENAME =0x00000008;
const uint SPFILENOTIFY_ENDRENAME =0x00000009;
const uint SPFILENOTIFY_RENAMEERROR =0x0000000a;
const uint SPFILENOTIFY_STARTCOPY =0x0000000b;
const uint SPFILENOTIFY_ENDCOPY =0x0000000c;
const uint SPFILENOTIFY_COPYERROR =0x0000000d;
const uint SPFILENOTIFY_NEEDMEDIA =0x0000000e;
const uint SPFILENOTIFY_QUEUESCAN = 0x0000000f;

const uint SPFILENOTIFY_FILEINCABINET = 0x00000011; // The
file has been extracted from the cabinet.
const uint SPFILENOTIFY_NEEDNEWCABINET = 0x00000012; // file
is encountered in the cabinet.
const uint SPFILENOTIFY_FILEEXTRACTED = 0x00000013; // The
current file is continued in the next cabinet.
const uint NO_ERROR = 0;

#endregion

#region Delegates

public delegate uint PSP_FILE_CALLBACK(uint context, uint
notifaction,
IntPtr param1, IntPtr param2);

#endregion

#region DLL Imports

[DllImport("setupapi.dll", SetLastError = true, CharSet =
CharSet.Unicode)]
private static extern bool SetupInstallFromInfSection(IntPtr
owner,
IntPtr infHandle, string sectionName, uint flags, IntPtr
hKey,
IntPtr sourceRootPath, uint copyFlags, PSP_FILE_CALLBACK
msgHandler,
ref uint context, IntPtr deviceInfoSet, IntPtr
deviceInfoData);

[DllImport("setupapi.dll", SetLastError = true)]
public static extern IntPtr SetupOpenInfFile(
string FileName,
IntPtr InfClass,
int InfStyle,
int ErrorLine
);

[DllImport("setupapi.dll", SetLastError = true)]
public static extern void SetupCloseInfFile(
IntPtr InfHandle
);

#endregion

/// <summary>
/// The FileCallback callback function is used by a number of
the setup functions. The PSP_FILE_CALLBACK 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.WriteLine("CallBack: Context = {0}, Notifacation =
{1}",
context, notification);
return rtnValue;
}

public bool InstallSection()
{
string windowsFolder =
Environment.GetEnvironmentVariable("WINDIR");
string halINF = Path.Combine(windowsFolder, @"inf
\hal.inf");
IntPtr hInf = SetupOpenInfFile(halINF, IntPtr.Zero,
INF_STYLE_WIN4, 0);
if (hInf == (IntPtr)(-1))
{
int err = Marshal.GetLastWin32Error();
Console.WriteLine("Invalid INF File: {0}", halINF);
return false;
}
try
{
string installSection = "E_ISA_UP_HAL";
bool iResult = false;
PSP_FILE_CALLBACK callback = new
PSP_FILE_CALLBACK(CallBack);
uint context = 0;
unchecked
{
SetupInstallFromInfSection(IntPtr.Zero, hInf,
installSection,
SPINST_ALL, new
IntPtr((int)HKEY_LOCAL_MACHINE), IntPtr.Zero,
SP_COPY_FORCE_IN_USE, callback, ref context,
IntPtr.Zero, IntPtr.Zero);
}
if (!iResult)
{
int err = Marshal.GetLastWin32Error();
Console.WriteLine("Error : {0}",
err.ToString("x"));
return false;
}
Console.WriteLine("Successfull!");
}
finally
{
SetupCloseInfFile(hInf);
}

return true;
}
}
}
Oct 28 '08 #1
3 3855
Rymfax <cw*****@bigbangllc.comwrote:
>
I was hoping someone could help me get SetupInstallFromInfSection
working properly. I'm trying to start in install section in a driver
INF (hal.inf specifically).
What's the point of this? If you have an EISA machine, this should be done
automatically. If not, what good is it going to do to install an EISA
section?
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 29 '08 #2
On Oct 29, 12:11*am, Tim Roberts <t...@probo.comwrote:
Rymfax <cwal...@bigbangllc.comwrote:
I was hoping someone could help me get SetupInstallFromInfSection
working properly. *I'm trying to start in install section in a driver
INF (hal.inf specifically).

What's the point of this? *If you have an EISA machine, this should be done
automatically. *If not, what good is it going to do to install an EISA
section?
--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
My application needs to be able to do this. From the stand-point of
the help I need, the section of the INF that I need to install
probably doesn't matter. The fact still remains that I can't seem to
get it to work. Do you think you could provide me with an example of
how to use SetupInstallFromInfSection? Or is there another way to
execute a particular install section from an INF to update the driver
on a device? UpdateDriverForPlugAndPlayDevices() won't work for me
because I want to execute a section that may not be the "best choice"
for the driver.

I'd really, REALLY appreaciate the thelp because I'm stuck and
frustrated.
Oct 30 '08 #3
Rymfax <cw*****@bigbangllc.comwrote:
>
My application needs to be able to do this. From the stand-point of
the help I need, the section of the INF that I need to install
probably doesn't matter. The fact still remains that I can't seem to
get it to work. Do you think you could provide me with an example of
how to use SetupInstallFromInfSection?
From C#? No.

In my own personal opinion, people trying to do SetupDi things from C# are
really just hurting themselves. The APIs are verbose and complicated. My
advice is to write this in unmanaged code.

I'm sure you understand that free advice is worth every penny that it
costs...
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 31 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: Rymfax | last post by:
I was hoping someone could help me get SetupInstallFromInfSection 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.