Page 1 of 2 12>
Topic Options
#156767 - 2006-02-07 03:09 PM ScanHardware
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
Anyone know how the ScanHardware process can be called upon to scan the system for new hardware ?
I've been looking trough W32_PnPEntity and Win32_DeviceChangeEvent but can't find anything related to the actual searching for new hardware.

If anyone has any suggestions I'd be most grateful.

Top
#156768 - 2006-02-07 03:47 PM Re: ScanHardware
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
couldn't find anything clever but if having the wizard gui showing up does not hurt, you can use:
Code:

run "rundll32.exe shell32.dll,Control_RunDLL hdwwiz.cpl"
sleep 0.1
$ = sendkeys("{space}")
$ = sendkeys("{space}")
$ = sendkeys("{space}")



hmm... not sure about the sendkeys... don't remember how to send space.
_________________________
!

download KiXnet

Top
#156769 - 2006-02-07 04:23 PM Re: ScanHardware
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
I'm assuming you are looking for a WMI way to do it, and for that I can't help. But if you are willing to use an external utility devcon is your friend.
Top
#156770 - 2006-02-07 04:23 PM Re: ScanHardware
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
Thanks

But it's not exactly the process I'm looking for. It is close though
When you enter the Device Manager you can select "Scan for Hardware Changes" it is a slightly different process then the hdwwiz.cpl you mentioned

[edit]
yeah I know about devcon, but I believe there must be a "windows" way to do it as well.


Edited by apronk (2006-02-07 04:24 PM)

Top
#156771 - 2006-02-07 04:55 PM Re: ScanHardware
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
apronk, I found references to newDev but after trying some of it's stuff, don't know how to invoke it.
here are some examples I just tried (the usual trial and failure approach):
Code:

rundll32.exe newdev.dll, InstallNewDevice
rundll32.exe newdev.dll, InstallDevInst
rundll32.exe newdev.dll, DevInstallW



that said, couldn't find a way to "run" this dll.
_________________________
!

download KiXnet

Top
#156772 - 2006-02-08 08:50 AM Re: ScanHardware
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
Jooel, thanks for your efforts
After looking into the matter even further it seems your first option was the most suitable altho not in the fashion you've state it. Let me try to explain the whole thing.

Once a machine gets hookedup to our network the loginscript I've wrote sets the registry paths for Device Drivers to a network location. But since the machine is already installed and found no drivers for certain hardware items it isn't gonna look again after the paths are changed. Thats where this scanned comes in. the "Scan for Hardware Changes" in the device manager doesnt change anything because the devices aren't changed. However I did find that if you remove the unknown device and then scan for hardware changes. (also like Allen stated devcon does the trick for scanning for hardware changes) it does work. But when you rightclick the unknown device and then invoke the "update driver" function it also works, I think this could be done in Win32_PnPEntity wich can enumerate all hardware devices just have to try to get it to return devices that have no drivers.

Top
#156773 - 2006-02-08 09:12 AM Re: ScanHardware
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
(Update) I've writtem a script that shows the devices that don't have any drivers yet, only thing left to do it to get the script to actually remove the devices from the device manager and then a script that scans for "new hardware" and all should be fine

Code:

$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_PNPEntity Where ConfigManagerErrorCode <> 0")

For Each $objItem in $colItems
? "Name: " + $objItem.Name
Next


Top
#156774 - 2006-02-08 09:40 AM Re: ScanHardware
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
you are tweaking the path of the drivers that are originally working fine.
may I ask why?
_________________________
!

download KiXnet

Top
#156775 - 2006-02-08 09:55 AM Re: ScanHardware
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
Well I change the path so Windows searches in the local path and a network path for drivers. Mainly because alot of drivers are not installed from windows itself.

Back to the remove hardware part, I've found that $objItem.Uninstall works for installed programs but not for hardware devices in the device manager, but there must be a similar command.

Top
#156776 - 2006-02-08 09:59 AM Re: ScanHardware
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sorry to still query about this, but you said the machines are already installed.
thus, there are no unknown devices in them.
thus, there is no reason to scan for new hardware.

are you just trying to override the old working drivers with the ones found on the network?
_________________________
!

download KiXnet

Top
#156777 - 2006-02-08 10:02 AM Re: ScanHardware
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
I'm sorry I ment to say that they are installed with Windows, not all the dirvers are installed yet after windows is installed, especially laptops.
Top
#156778 - 2006-02-08 11:12 AM Re: ScanHardware
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so...
iirc, after you remove the unknown hardware, if you restart, windows automatically will search for the hardware and it's drivers.
it will add extra reboot but that should do it.
_________________________
!

download KiXnet

Top
#156779 - 2006-02-08 11:58 AM Re: ScanHardware
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
Indeed, but I still have to find out how to remove the hardware Listing it is no problem.
Top
#156780 - 2006-02-08 01:11 PM Re: ScanHardware
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
after some research, I can tell that there is no way that you can do anything to it via wmi.
you can search for these devices, which will give you exactly the same as enumkey from:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root\UNKNOWN

sadly, didn't find a way (yet) that will uninstall a device.
_________________________
!

download KiXnet

Top
#156781 - 2006-02-08 01:25 PM Re: ScanHardware
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
So far I can conclude this:
1. Scan with WMI wich devices don't have drivers (code posted earlier).
2. Use WMI to get the DeviceID.
3. Pass the DeviceID to Devcon to remove the HW (this works sucky to say the least) Devcon removes more thn bargained for.
4. Let devcon scan for new HW (this does work nicely), devices get detected and the drivers get installed from the path I've specified in the registry.

So if there is a way that WMI can remove the devices im basically finished although I'd prefer to do everything from withitn Kix/WMI.

Again thanks for your efforts, I apreciate it alot

Top
#156782 - 2006-02-08 02:07 PM Re: ScanHardware
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I think I found something.
it has nothing to do with wmi (I bet nothing good has come out of it) but with it you can do the job.
try this:
Code:

$enum = 0
do
$key = enumkey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root\UNKNOWN",$enum)
run "Rundll32.exe devmgr.dll DeviceProperties_RunDLL /DeviceID Root\UNKNOWN\"+$key
$enum = $enum + 1
until "" = $key


dx21 seemed to be the right resource to get this far:
http://www.dx21.com/SCRIPTING/RUNDLL32/VIEWITEM.ASP?OID=203&CMD=P-A

now, what one needs to do is activate the driver tab and press the remove button.
this can be done with the good old sendkeys.


Edited by Jooel (2006-02-08 02:31 PM)
_________________________
!

download KiXnet

Top
#156783 - 2006-02-08 02:12 PM Re: ScanHardware
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
I don't have the "UNKNOWN" part in my registry :/
Top
#156784 - 2006-02-08 02:21 PM Re: ScanHardware
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
So far I have this:
It basically works, but the removing part removes WAAAAYY yoo many devices, needless to say it's buggy as shizne.
Code:

$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_PNPEntity Where ConfigManagerErrorCode <> 0")

For Each $objItem in $colItems
? "Name: " + $objItem.Name
? "Attempting to Remove " + $objItem.Name
$DeviceID = CStr($objItem.DeviceID)
Shell "%comspec% /c %windir%\system32\devcon.exe remove " + "$DeviceID"
Next
Shell "%comspec% /c %windir%\system32\devcon.exe rescan"


[edit]

Just forget the way devcon removes hardware, it does indeed remove hardware but also hardware you did not specify, basically it sucks, im not spending more time on devcon for removing hardware.


Edited by apronk (2006-02-08 02:27 PM)

Top
#156785 - 2006-02-08 02:35 PM Re: ScanHardware
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the problem is, the deviceID can be shared.
thus, I had normal LPT1: and installed a fake printer port, named LPT2: and iirc they had same deviceID.
_________________________
!

download KiXnet

Top
#156786 - 2006-02-08 02:53 PM Re: ScanHardware
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
I guess the same goes for PNPDeviceID.
Btw I found what the problem was with Devcon remove ID.
Passing the $objItem.DeviceID to Devcon, for some reason the ID gets's split by the & marks. Even if you pass it as CStr($objItem.DeviceID).... Is this Kix behaviour ?

because devcon will then continue to remove each splitted string and anything that maches it. That why ALOT of stuff gets removed.
[edit]
No it's definately not kix behaviour, in CMD if you type the command manually it does the same.

Devcon Remove PCI\VEN_10DE&DEV_0322&SUBSYS_00000000&REV_A1\4&38B71F77&0&0008

but then:
Devcon Remove "PCI\VEN_10DE&DEV_0322&SUBSYS_00000000&REV_A1\4&38B71F77&0&0008"

Removes nothing :/


Edited by apronk (2006-02-08 02:56 PM)

Top
Page 1 of 2 12>


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 252 anonymous users online.
Newest Members
Raoul, Timothy, Jojo67, MaikSimon, kvn317
17875 Registered Users

Generated in 0.077 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org