how to replace locked dll (was inuse) - windows

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%

Related

What is the location of FINDSTR on all Windows OS from Windows XP to Windows server 2012?

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...

Batch file to start all programmes in the start folder of XP

I need start all folders in a the Windows "Start/Programs/Startup folder" of an XP machine, explorer is disabled to stop top people playing and remove the Start and Task-bar.
I can run a batch file at start-up but how do I write the batch to run ALL programs in the "Start/Programs/Startup folder" the programs in the folder may change but the batch needs to remain the same
I am able to open each file individually using the below code but I really need to be able to open everything in the folder to avoid problems in the future
start "" /b "C:\Documents and Settings\User\Start Menu\Programs\Startup\PROG.appref-ms"
I have tried the code below, that batch starts but nothing starts
%DIR%=C:\Documents and Settings\Pete\Start Menu\Programs\Startup
for %%a in (%DIR%\*) do "%%a"
Running the batch from the desktop also doesn't run the programs in the start folder, the DIR address is taken from windows explorer when I navigated to the folder with the short cuts in
This is an interesting request--one that I would question the motive behind, but since you asked, here's a way you could accomplish it:
#echo off
set DIR=C:\Your\Directory
for %%a in ("%DIR%\*") do "%%a"

How do I remove previous extension<->Program affiliations programatically?

I would like to write a batch file which ensures that when a user clicks on a .JNLP file, it opens using javaws.exe (located in program files/java/... you know the drill)
I have written the following batch file:
ASSOC .jnlp=JNLPFILE
IF EXIST "%ProgramFiles% (x86)" (GOTO x86) ELSE (GOTO x64)
:x86
FTYPE JNLPFILE="%ProgramFiles% (x86)\Java\jre7\bin\javaws.exe" "%1"
goto:eof
:x64
FTYPE JNLPFILE="%ProgramFiles%\Java\jre7\bin\javaws.exe" "%1"
I am testing this all in windows 7 64-bit.
This... doesn't work. Well, that's not entirely accurate. It modifies the registry correctly, and it adds .jnlp to windows list of Recommended programs to run. It does exactly what it should.
But it doesn't solve my problem. See, For testing, I went to Default Programs and associated .jnlp files with Notepad. And when I try to open .Jnlp files, IT tries to open in notepad, even after my code has run.
If I do an open with on a .jnlp, it gives me the option to open with Notepad or javaws.exe If I've run my code with the ASSOC, it adds a SECOND option of javaws.exe
I've tried ASSOC .jnlp="" and FTYPE JNLPFILE="" To try and clear notepad out, but had no luck.
How do I make my batch file blow away prior settings and assert its dominance on the machine?
EDIT: Using the answers below, I have added a single command to the beginning of my batch file, which should take care of my problem and make things work correctly.
REG DELETE HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jnlp /f
Windows Explorer keeps its own list of file extensions for the user.
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
To remove programs from this list, delete the program entry from
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.‌​jnlp\OpenWithList
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jnlp\OpenWithProgIDs
and set the desired UserChoice Progid in
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jnlp\UserChoice
Also, note that the OpenWithList and OpenWithProgids can be set at multiple levels.
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.xyz\OpenWithList
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.xyz\OpenWithProgIDs
HKCR\.xyz\OpenWithList
HKCR\.xyz\OpenWithProgIDs
HKCR\SystemFileAssociations\FileType\OpenWithList

shell:Common Startup as a parameter to XCOPY

I have a simple batch script that copies a file to the startup folder, but it appears that I can't use shell:Common Startup as a parameter to xcopy. I have tried this
xcopy hurrdurr.exe "shell:Common Startup"
and many other variations, and they don't work. As an aside, if this did work, "hurrdurr.exe" would run on every startup right, assuming I got clearance via uac to do the xcopy operation? Would using a environment variable be better? The os in question is Windows XP and proceeding.
I'm not sure why your shell command won't work, but if you need to get your program to load on startup then I would much prefer using the registry, it's cleaner and simpler, and it means you don't have to copy the file somewhere else, especially if that file is dependant on other things.
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v "Hurrdurr" /d "hurrdurr.exe" /f
Just run cmd as admin and it will work :)
If you do want to use the startup folder though, on Win7 you can use
"%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"
I would also use a shortcut as #David suggested instead of copying the actual file.

Installing a .inf file using a windows batch file

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

Resources