Is there a way to forcibly change drivers for particular devices in a batch file?
What my issue is here is that I'm trying to automate the process of selecting the correct driver for a projector that is connected to a computer and right now the projector is turned on automatically after the computer is started through a batch file.
However generic drivers are selected instead of the proper driver for that projector.
Is there a command I can use to forcibly change the driver for that projector or is there another way to change the default driver from the generic to the one I need automatically rather than manually?
In your batch file you need to find out:
Windows x86 (32 bit) or Windows x64 (64 bit) for example with:
if "%ProgramFiles(x86)%" == "" goto Driver32Bit
:Driver64Bit
echo Detected Windows x64
rem Commands for installing correct 64 bit driver after determining Windows version.
goto :EOF
:Driver32Bit
echo Detected Windows x86
rem Commands for installing correct 32 bit driver after determining Windows version.
goto :EOF
Windows version using command ver for selecting correct driver directory.
In each directory containing the driver files for appropriate Windows there should be dpinst32.exe or dpinst64.exe to install the driver. See Driver Package Installer (DPInst) for details about this free Microsoft application for installing drivers.
Very often the manufacturer of the driver delivers the driver packages already with dpinst32.exe and dpinst64.exe as often used by their own driver installers, too. Otherwise you need to download Windows Driver Kit and extract those two files from WDK package. Installing WDK is not necessary.
Related
I am currently trying to uninstall display adapter driver in power shell.
I can simply go to device manager to find display adapter and uninstall the driver and then install the new driver. But I want to write an automated script to make it easy.
I tried to use "pnputil.exe -f -d oem##.inf" in power shell to uninstall the display adapter driver.
But it did not work and gave me something like that
"Deleting the driver package failed: One or more devices are presently installed using the specified INF"
Does anyone know how can I solve this problem and make pnputil work?
This isn't a PowerShell question really, as it's a window util.
from running pnputil /?
/delete-driver <oem#.inf> [/force]
Delete driver package from the driver store.
/force - delete driver package even when it is in use by devices.
so running pnputil.exe /delete-driver oem##.inf /force should work for you.
Example removing a device using the driver first on the commandline with devon. Devon comes with the Window SDK. Windows SDK - Windows app development _ Microsoft Developer The pnputil command should work after that.
devcon remove "HDAUDIO\FUNC_01&VEN_1013&DEV_4206&SUBSYS_106B0600"
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
When i executed the command via command propmt to install the driver :
cd C:\Windows\System32
pnputil.exe -i -a "C:\Users\Desktop\Drivers\IPEnabled_001.inf"
It work fine.
But if i execute the command in Installanywhere tool
It showing the error message:
pnputil.exe is not recognized as an internal or external command
So could you please tell why it is showing the error message and how the reslove that error?
Thanks in advance.
Please also suggest the alternate way to install inf driver
pnputil.exe is on 64-bit Windows available only as 64-bit application which means there is %SystemRoot%\System32\pnputil.exe (x64) but no %SystemRoot%\SysWOW64\pnputil.exe (x86).
Which directory becomes current directory on using cd C:\Windows\System32 depends on 64-bit Windows on architecture of the application which started Windows command interpreter cmd.exe. A 64-bit application starts really %SystemRoot%\System32\cmd.exe, but a 32-bit application starts %SystemRoot%\SysWOW64\cmd.exe. The reason is the Windows File System Redirector which redirects any file access to %SystemRoot%\System32 to the directory %SystemRoot%\SysWOW64 on Windows x64 for x86 applications.
It is best to check for existence of this file before executing it for this task running pnputil.exe existing only in directory %SystemRoot%\System32 on any Windows independent on Windows architecture.
if exist %SystemRoot%\System32\pnputil.exe (
set "SystemPath=%SystemRoot%\System32"
) else if exist %SystemRoot%\Sysnative\pnputil.exe (
set "SystemPath=%SystemRoot%\Sysnative"
) else (
echo ERROR: Cannot find pnputil.exe to install the driver.
echo/
pause
goto :EOF
)
%SystemPath%\pnputil.exe -i -a "%USERPROFILE%\Desktop\Drivers\IPEnabled_001.inf"
The first IF condition is true for 32-bit applications on 32-bit Windows and 64-bit applications on 64-bit Windows.
The second IF condition is true for 32-bit applications on 64-bit Windows. Sysnative is a special redirector for x86 applications on Windows x64. Sysnative does not exist for x64 applications. Sysnative is not a directory or a symbolic link or a hard link. So it is not possible to use if exist %SystemRoot%\Sysnative as this condition is never true. It is required to check if a file exists in the redirected directory, for example with if exist %SystemRoot%\Sysnative\* which is only true on running currently 32-bit cmd.exe on 64-bit Windows.
The final ELSE branch is true for example on Windows XP which does not have pnputil.exe at all.
However, it is not recommended to use pnputil.exe to install drivers. Microsoft publishes for free the Driver Package Installer DPInst. There is a 32-bit (dpinst32.exe) and a 64-bit version (dpinst64.exe). Installation of one or more drivers is very easy using the driver package installer.
Let us look on how hardware producing companies which offer also the appropriate drivers like Intel ® install drivers using Driver Package Installer.
There is usually a directory structure in a driver installer package like:
VISTA32
VISTA64
WIN7-x86
WIN7-x64
XPx86
XPx64
Or a directory structure like:
VISTA
x86
x64
WIN7
x86
x64
XP
x86
x64
The directory structure varies from installer package to installer package, but that does not really matter and usually it is quite easy to see which driver files in which directory are for which version of Windows including architecture.
And there are additionally dpinst32.exe and dpinst64.exe being either stored in parent directory of all the subdirectories with the driver files or on just two driver directories directly in the directory containing the driver files.
Let us make the driver installation example very simple and assume there are only two driver files in a package, one for Windows x86 and one for Windows x64.
WIN-32
dpinst32.exe
*.cat
*.dll
*.inf
*.sys
WIN-64
dpinst64.exe
*.cat
*.dll
*.inf
*.sys
The code to install the 32-bit driver(s) in WIN-32 on 32-bit Windows and 64-bit driver(s) in WIN-64 on 64-bit Windows by a simple batch file executed either by 32-bit or 64-bit cmd.exe is very easy.
set "WINARCH=64"
if "%ProgramFiles(x86)%" == "" set "WINARCH=32"
cd WIN-%WINARCH%
dpinst%WINARCH%.exe
The environment variable ProgramFiles(x86) exists only on Windows x64 which makes it very easy to determine the architecture of Windows, see also WOW64 Implementation Details. The architecture of the processor does not really matter because on a PC with an AMD 64-bit (compatible) processor can be installed nevertheless a 32-bit Windows.
dpinst32.exe and dpinst64.exe started without any option simply install all drivers found in current directory.
I am using the Windows postscript print driver that is shipped with ghostscript (lib/ghostpdf.inf) to generate postscript files from print jobs.
However the postscript driver is not digitally signed, so Windows 8 and Windows Server 2012 won't allow installing it without booting into the "allow unsigned drivers"-mode.
Do you know if there is any signed version out there to be used with the latest Windows versions?
If thats not the case, I am fine compiling and signing it myself, however I was not able to find the source code for the postscript print driver within the git repo available at http://git.ghostscript.com/ghostpdl.git.
May I've just overseen it since I am not familiar with building drivers.
Can one give me a hint where I can find the postscript driver files to compile it myself?
EDIT: How does the .INF file tell windows where the driver binaries are located? I've looked into the "ClassGUID" however its the same for all drivers and the registry entry says something about C:\Windows\System32\ntprint.dll. I don't think this is important for the problem, is it?
To sign "the ghostscript driver" you just have to sign the INF-file that comes with Ghostscript.
There's an article on technet describing the steps required to do so.
The steps are:
1) Create/acquire a certificate
2) Ensure that your computer trusts the certificate (place it in your cert store if required)
3) Download and install the Windows Driver Kit (WDK)
4) Change the CatalogFile=oemprint.cat in the INF file to ghostpdf.cat
5) Change the DriverVer=01/02/2007,1.0.0.1 to DriverVer=01/01/2013,1.0.0.1 (maybe you need some other date, you'll see that in the next step)
6) Use the Inf2Cat tool to create a cat file (was at C:\Program Files (x86)\Windows Kits\8.0\bin\x86 for me):
NOTE
Use cmd.exe not powershell, as powershell gives Parameter format not correct. error all the time
Command:
inf2cat.exe /driver:c:\path\to\folder\whereCatFileIsIn /os:7_X86,7_X64,8_X86,8_X64[,other OS you'd like to support]
7) Sign the cat file using the signtool (Same directory as the Inf2Cat tool)
Command:
SignTool.exe sign /f "C:Path\to\my.pfx" /t http://timestamp.verisign.com/scripts/timestamp.dll "C:\Path\To\ghostpdf.cat"
(See the signtool docs for more informations about the available paramters)
.inf files are not drivers, they are just text files with some installer information. There is no signed version of this, nor do you need it, you can use the output of any PostScript driver with Ghostscript.
You can't compile a .inf file, because there is nothing to compile, I have no idea how you go about signing such a thing in the latest versions of Windows, but if you want to give it a try you can open the .inf file with a text editor.
Q: Do you know if there is any signed version out there to be used with the latest Windows versions?
* Workaround *
A: For my Postscript driver issue I re-used the already signed driver from freeware PDF generator PDFil Writer.
https://www.pdfill.com/freewriter.html
In my case, I am a Sybase Powerbuilder developer, and my application depends on the Ghostscript Postscript driver.
I hope this helps.
I have a .inf file and a .sys file and a couple of dll's.
to install the driver manually i do from elevated command prompt :
devcon install driver.inf HID\driver
I want some pointers on how to make the installer for this driver .
Thanks.
PS: I am a complete noob when it comes to things related to drivers.
We can use a simple installer based on NSIS that copies the files and executes the command . Also devcon binary is not redistibutable but we can copy parts of the devcon source that we need in order to create a specific driver installer binary.
I would like to install my USB device driver [.inf file] using PnPUtil.exe utility on both 32bit and 64bit systems for Windows Vista and Windows 7.
I tested on my machine [Windows 7 32bit] and everything was fine because PnpUtil.exe is located in: C:\Windows\System32\PnPUtil.exe.
But in 64bit Windows 7 the utility is not in this directory.
When I tried installing driver on different Windows 7 - 64bit machine I could found PnPUtil.exe in this location: C:\WIndows\winsxs\amd64_microsoft-windows-pnputil_31bf3856ad364e35_6.1.7600.16385_none_5958b438d6388d15\pnputil.exe
and the test was also fine.
So how can I exactly detect this directory on all platforms?
I noticed the path is dependent on built of Windows version - 6.1.7600.16385 - but how to detect the rest of path?
Or is the path always the same on all 64 bit platforms? And what about Vista?
The location of PnPUtil.exe seen from you installer application depends on the bitness of your installer:
32bit installer on 32bit Windows: %WinDir%\System32
64bit installer on 64bit Windows: %WinDir%\System32
32bit installer on 64bit Windows: %WinDir%\Sysnative (Windows Vista and up)
More info here:
http://www.samlogic.net/articles/sysnative-folder-64-bit-windows.htm
I recently came across this problem while trying to create an installer for ReplicatorG, which includes the Arduino drivers and some drivers specific to the Makerbot Replicator.
It seemed that there isn't any way to determine the location of PnPutil, and I instead had to acquire Microsoft's DIFx and use their redistributable DPinst.
There were a couple of strange things about DPinst that made it difficult to use. The first is that it didn't seem to run properly if it was located in a directory tree with spaces in the path. Who knows why. The second was that, because the Arduino drivers are unsigned, it needed to be run in legacy mode to keep from popping up a big, red dialog warning the user. To run it in legacy mode you use the /lm flag, but the flag must be lowercase. Again, it's unclear why.
In the end, I had the installer copy dpinst and each of the drivers to a folder in the temporary directory and then run dpinst. It pops up a nice little wizard and tells the user which drivers were installed.
From C:\WIndows\winsxs\
dir /s PnPUtil.*
will scan subdirectories