When you right click on a .inf file you have an option to "Install". I want to install a .inf file from the command line using a batch file. What is the "right" way to do this?
Thanks!
[edit]
I should clarify that I am trying to run this on Windows XP (and not Vista). Though I appriciate (and up-voted) the below answer mentioning InfDefaultInstall.exe, I believe that program was not shipped with XP.
You can find the command when looking at the HKCR\inffile\shell\Install\command registry key. On Windows XP this is
%SystemRoot%\System32\rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 %1
on Windows Vista and later this would be
%SystemRoot%\System32\InfDefaultInstall.exe "%1"
To use the batch file across several Windows versions you would need some trickery. You could use reg.exe to query for the key and try parsing the output (I didn't find a quick way of getting only the value from reg). If you know what platforms you're running on you could also hard-code the command lines and switch according to the Windows version (which would need another hack to find that out. %OS% doesn't tell you more than "Windows NT", unfortunately.).
rem tested/works
:inf
ver | findstr /il "Version 6." > nul
if %ERRORLEVEL%==0 goto :vista
:xp
start/wait rundll32.exe setupapi,InstallHinfSection DefaultInstall 4 %_%
goto :eof
:vista
%SystemRoot%\System32\InfDefaultInstall.exe "%_%"
:eof
Should works on any Windows system that has IE 4.0+:
RunDll32 advpack.dll,LaunchINFSection <file.inf>,DefaultInstall
Related
I have some issue in a driver & I have to troubleshoot it, before that I need to build it. I have no experience in driver.
I have the source code & bat file. It might be using WDK 7(I'm not sure)
Can anyone guide me in building the driver project with below bat file.
Ofcourse I can understand bat file is setting environment variables & calling build.exe
My main questions are:
1. Which WDK i need to install, so that I can specify its path in bat file
2. How to run bat file, do i need to run in visual studio command prompt or how?
if you give some Some general idea on building a driver for a beginner that would be much appreciated. Thanks.
[if you need any info, which i can provide please feel free to ask]
bat fie:
rem #echo off
rem --------------------------------------------------------------------
rem SafeBoot Windows NT 32 bit driver build script
rem --------------------------------------------------------------------
set MC_ENV=fre
if "%1%"=="debug" goto dbg
if "%2%"=="debug" goto dbg
if "%3%"=="debug" goto dbg
goto nodbg
:dbg
echo **** DEBUG BUILD ****
set MC_ENV=chk
:nodbg
rem --------------------------------------------------------------------
rem We want the absolute path of this directory, so we use a little utility
rem that creates a batch file that sets this into a environment variable.
rem --------------------------------------------------------------------
..\Translations\Bin\setcd -d DRV_DIR > thisdir.bat
call thisdir
del thisdir.bat
if NOT "%DDK64%"=="" goto x1
set DDK64=D:\Tools\WinDDK\6000
rem set DDK64=C:\WinDDK\6001.18001
:x1
set MSTOOLS=%MSSdk%
set BASEDIR=
set DDKBUILDENV=
set NTDBGFILES=
set DDK_INC_PATH=
set DDK_LIB_DEST=
set DDK_LIB_PATH=
set CRT_INC_PATH=
set CRT_LIB_PATH=
set BUILD_ALT_DIR=
call %DDK64%\bin\setenv %DDK64% %MC_ENV% i386
echo %DRV_DIR%
cd %DRV_DIR%
if NOT "%1"=="/a" goto build
del /q objfre_wlh_x86\i386\*.*
del /q objchk_wlh_x86\i386\*.*
rmdir /Q /S driver32
md driver32
:build
rem set MSC_OPTIMIZATION=/Od
echo Building started...
%DDK64%\bin\x86\build.exe -f -z -E
echo Building completed...
if ERRORLEVEL 1 goto error
rem copy objfre_wlh_x86\i386\McPvDrv.sys driver32\McPvDrv.sys
if "%MC_ENV%"=="chk" (
md ..\..\..\build\Win32\Debug
copy objchk_wlh_x86\i386\McPvDrv.sys ..\..\..\build\Win32\Debug\McPvDrv.sys
echo chk
If you want to build a driver for Windows 7 or newer use Visual Studio 2015 which is integrated with the lastest WDK 10. Building drivers is way easier this way.
If you want to build drivers for Windows XP then you will have to use WDK 7 and use a scripts similar like yours. Wdk 7 has no integration with visual studio. You have to specify source file in a special file called sources. See example drivers from Wdk 7. You can find a good cmd for building such drivers https://www.osronline.com/article.cfm?article=43 This website has the best driver dev tips
If you do not need XP support I highly recommend you go the much much easier way using Visual Studio 2015, windows sdk and windows 10 wdk.
LE:
You can also use Visual Studio 2013 which supports integration with WDK 8 and WDK 8.1 but not with WDK 10.
From your .bat file, it has:
if NOT "%DDK64%"=="" goto x1
set DDK64=D:\Tools\WinDDK\6000
rem set DDK64=C:\WinDDK\6001.18001
:x1
So, it might be looking for that version. If so, here is a page: What is the Microsoft name for WinDDK version 6001.18001?
Also, see https://en.wikipedia.org/wiki/Windows_Driver_Kit Your .bat wants, by default, build 6000 (released: november 29, 2006 for Windows Vista)
You could also try to use the latest one. Here's the link for WDK 10 with download instructions. WDK 7 should be similar: https://msdn.microsoft.com/en-us/library/windows/hardware/ff557573%28v=vs.85%29.aspx so find the right page. This page also has links to other pages that may help answer your other questions.
In any case, you'll need to modify the .bat to point to the correct WinDDK directory by setting the DDK64 variable to point to it.
You can probably install multiple different versions to different directories, but my guess is that the latest will let you build backward compatible versions. So, if you're building for Win7 (e.g.), get the latest DDK for Win7 (see the table in the wiki page).
Is the directory of findstr always C:\Windows\system32\ for all OS from Windows XP to server 2012?
Or in other words is it safe to replace the following expression in a windows batch file:
findstr
to
C:\Windows\system32\findstr
Extra information just for completeness.
Environment variable windir exists since Windows 95 and contains the path to Windows directory independent on which drive it is located and which name it has.
For NT based Windows (NT4, Windows 2000, Windows XP, Vista, Windows 7 / 8 / 8.1) there is additionally the environment variable SystemRoot which contains also the path to Windows directory as this is the parent directory for the system directories
System32
Sysnative (only Windows x64 and only for 32-bit applications)
SysWOW64 (only Windows x64)
For details about file system redirection read the File System Redirector page of Microsoft.
It is not only safe to use either
%windir%\System32\findstr.exe
or
%SystemRoot%\System32\findstr.exe
I would highly recommend using always one of those two strings in batch files as then it does not depend which folders are in environment variable PATH and which file extensions in environment variable PATHEXT.
There are some bad installers which add the folder path of the installed application to system environment variable PATH at beginning instead of appending at end and contain in the application's folder also find.exe or findstr.exe which are portings from Unix and therefore work completely different than find.exe and findstr.exe of Windows. AVRStudio is (or perhaps was as not verified with latest version of AVRStudio) an example breaking batch files of IT administrators not using always complete file name for Windows commands after installation.
Rather %windir%\system32\findstr.exe as its possible windows to be installed on different than C:\ drive.
I am afraid I don't understand the purpose of your question, so I rephrase it in a slightly different way.
If you type findstr in a computer and the FINDSTR command run, then you may know the location of such findstr command this way:
for %%a in (findstr.exe) do echo %%~$PATH:a
So you may replace the following expression:
findstr
... by the next two lines:
for %%a in (findstr.exe) do set "findstrPath=%~$PATH:a"
%findstrPath%
... in a Windows Batch file and you will get exactly the same result.
So, the question arises: if you get the same result in both cases, why do you want to use the second, more complicated one?
Note also that the same point apply with any other external command like find, xcopy, forfiles, etc. Why findstr would be special in this point?
As I said before, I don't understand the purpose of your question...
I need your help, I'm building small installation batch file for my small application (My app.exe must be copied in different places of windows version and architecture).
I played with it, but can't solve the given task...
I created this code: (For testing purposes)
If Exist "C:\Users\All Users\ntuser.dat" Goto Win 7
If Exist "C:\Documents and Settings\All Users\ntuser.dat" Goto Win XP
:Win 7
C:\w7\test.txt
:Win XP
C:\wxp\test.txt
But when executing the batch file (from windows xp) both jobs are done (Both files are opened)... why I can't understand... as I know it must open only win xp section code
Please how to modify the code, give me an example..
My Mission is:
I want that my app.exe file copied in different locations of different windows versions and builds (WinXP - X86-X64, Win7 - X86-X64)
If it is windows 7x64 x86 or win xp-x86,x64 it must only use the code which is set for the given system and not other
Thank You In Advanced
try this:
If Exist "C:\Users\All Users\ntuser.dat" Goto Win_7
If Exist "C:\Documents and Settings\All Users\ntuser.dat" Goto Win_XP
:Win_7
C:\w7\test.txt
goto:eof
:Win_XP
C:\wxp\test.txt
goto:eof
You need to tell it to stop running when it reaches the end of that section, or it will keep going into the next one. (Spaces in the branch labels aren't really a good idea either, although they're allowed. Why use them, when the user will never see them?)
If Exist "C:\Users\All Users\ntuser.dat" Goto Win7
If Exist "C:\Documents and Settings\All Users\ntuser.dat" Goto WinXP
:Win7
C:\w7\test.txt
goto :eof
:WinXP
C:\wxp\test.txt
goto :eof
:eof is a pre-defined branch label that means end of file. More info in the goto documentation
Microsoft Windows XP comes with a VBS script to manage local and network printers from the command line:
To Get the default printer details from command line:
cscript C:\windows\system32\prnmngr.vbs -g
To Get the list of printers added to the system from Windows command line:
cscript C:\windows\system32\prnmngr.vbs -l
Is there any equivalent commands for Windows 7? I just need to get the default printer details and get the list of printers attached to the system.
In Windows 7 these same scripts are found in
C:\Windows\System32\Printing_Admin_Scripts\en-US
List of all printers names and shows default one (You can get more details read documentation)
wmic printer get name,default
If you want output to file use:
wmic printer get name,default > D:\catalog\file.txt
Availability
The wmic command is an external command that is available in the below Microsoft operating systems as wmic.exe.
Windows XP professional
Windows 2003
Windows Vista
Windows 7
Windows 8
Windows 10
On Windows 10, the scripts are found in the same place as Windows 7.
Execute the following command to display the default printer.
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -g
Note if there is no default printer, the script will return nothing
i found mine in the sideXside folder...
C:\windows\winsxs\x86_microsoft-windows-p..inscripts.resources_31bf3856ad364e35_6.1.7600.16385_en-us_0e83b619ada3e7ed\
i ran the following:
cscript C:\windows\winsxs\x86_microsoft-windows-p..inscripts.resources_31bf3856ad364e35_6.1.7600.16385_en-us_0e83b619ada3e7ed\prnmngr.vbs -g
it worked.
To list active printer components on Windows 8.1:
c:>cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -l | findstr "Printer name"
To remove printer in Windows 8.1:
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Printer name"
I had trouble with a printer not showing in devices/printers so unable to remove it, although it was there when I pressed file > print in firefox. It was also stopping me from using the printer name for the actual installation (it bugged me having to append _1 at the end of the default printer!"
Using a batch file (no VBScript files):
#echo off
::Get printer CLSID
for /f %%a in ('reg query HKCU\Printers\Defaults') do (set regkey=%%a)
::Get printer name from the previous CLSID
for /f "tokens=3*" %%a in ('reg query %regkey%') do (set printername=%%a %%b)
echo Printer name is: %printername%
I wish that could help you
I have a dll loaded into LSASS. I need to replace it on reboot.
There is an old utility called inuse from win2k reskit. It does not seem to work anymore (I am on windows 7)
Anybody know the right way to do it now?
Movefile from Sysinternals should do the trick :)
http://technet.microsoft.com/en-us/sysinternals/bb897556
Copying system dlls on Windows 7 (and Vista) is described in System File Checker tool article (in "Step2: If the System File Checker tool cannot repair a file").
Here is a quick (almost copy&paste) solution:
REM you will need to change this :-)
SET tmpset_SOURCE=c:\Windows\SysWOW64\d3d10_1.dll
SET tmpset_DEST=c:\_tmp\SysWOW64\d3d10_1.dll
REM copy and paste this straight to cmd:
takeown /f %tmpset_DEST%
icacls %tmpset_DEST% /GRANT %USERNAME%:F
copy %tmpset_SOURCE% %tmpset_DEST%