I am attempting to remove Lenovo Fingerprint Manager Pro from a dozen or so Windows 8.1 machines due to the recurring vulnerabilities of the software.
I wrote the following batch file in order to remove it. While it worked on my initial test, it has failed upon subsequent attempts.
I was looking to see where the error is, and if someone may have a better way about going about this?
#echo off
REM This file will remove the Lenovo Finger print scanner and the relevant registry entries.
DEL "C:\windows\Installer\fa4f.msi"
set folder="C:\Program Files\Lenovo\Fingerprint Manager Pro"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
cd /d %folder%
cd ..
rmdir %folder%
REG DELETE HKEY_CLASSES_ROOT\CLSID\{940B1CC9-013F-468e-BBBF-4A975461F120} /f
REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\Lenovo\Fingerprint Software /f
REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{314FAD12-F785-4471-BCE8-AB506642B9A1} /f
ECHO Lenovo Fingerprint Scanner Removed Successfully.
In powershell you can get the program as an object and call uninstall on that object:
$App = Get-WmiObject -Class Win32_Product | Where-Object {
$_.Name -match "Software Name"}
$App.uninstall()
The if you really want to cleanup registry and all that fun stuff you can do that afterwards.
Related
I found a post on superuser to delete all creds from windows credential manager.
https://superuser.com/questions/689456/what-is-the-windows-7-command-line-to-remove-all-remember-passwords-in-credentia
Code:
echo on
cmdkey.exe /list > "%TEMP%\List.txt"
findstr.exe Target "%TEMP%\List.txt" > "%TEMP%\tokensonly.txt"
FOR /F "tokens=1,2 delims= " %%G IN (%TEMP%\tokensonly.txt) DO cmdkey.exe /delete:%%H
del "%TEMP%\List.txt" /s /f /q
del "%TEMP%\tokensonly.txt" /s /f /q
pause
This works on windows 7 but does not work on windows 10 and i'm not able to figure out why. cmdkey.exe /list still functions in windows 10 and it still pipes the file so i assuming the issue is with findstr.exe for an issue with the for loop in the batch file but I can't figure out what the problem is.
I want to be able to export key-values of registry keys as returned by reg query.
I'm trying to write a script to find registration for a particular dll and then write all keys to a backup file, before trying to achieve uninstall by deleting the keys. Here's what I could come up with so far:
#echo off
reg query HKLM\SOFTWARE\Classes /s /f %1 2>&1 >NUL
if errorlevel 1 goto DLL_MISSING
for /f "tokens=1,1" %%a in ('reg query HKLM\SOFTWARE\Classes /s /f %1 2^>NUL ^| findstr /I "^HKEY_"') do (
echo %%a
REG export %%a Backup.REG
)
goto :DLL_FOUND
:DLL_MISSING
echo Assembly not found.
goto :eof
:DLL_FOUND
echo Assembly found.
Right now reg export prompts to overwrite file, which I want append instead.
How can I achieve the same?
Also, please do suggest if there is some better way to automate uninstall duplicate(?) installs as installed by 'regasm'.
I could prefer batch-file based solution instead of Powershell or something else. Thanks!
reg.exe does not support appending/combining of several exported keys. The easiest workaround seems to be to output each key's data into a separate file, and then merge these into a single file afterwards. Note that you need to make sure that the output key file is not picked up by the FOR loop, which I ensured by simply placing the combined key file in a subfolder called target.
#ECHO OFF
MKDIR target
ECHO Windows Registry Editor Version 5.00 > target\combined.reg
FOR %%G IN (*.reg) DO (
TYPE "%%G" | FINDSTR /V "Windows Registry Editor" >> target\combined.reg
DEL "%%G"
)
This is what I wrote:
It's basically similar to what was proposed by #zb226.
#echo off
reg query HKLM\SOFTWARE\Classes /s /f %1 2>&1 >NUL
if errorlevel 1 goto DLL_MISSING
ECHO Windows Registry Editor Version 5.00 > backup.reg
for /f "tokens=1,2" %%a in ('reg query HKLM\SOFTWARE\Classes /s /f "%1" 2^>NUL ^| findstr /I "^HKEY_"') do (
echo Deleting : %%a
reg export %%a bkp_tmp.reg /y >nul 2>&1
type bkp_tmp.reg | FINDSTR /V "Windows Registry Editor" >> backup.reg
reg delete %%a /f >nul 2>&1
)
del /f bkp_tmp.reg
goto :DLL_FOUND
:DLL_MISSING
echo Assembly not found.
goto :eof
:DLL_FOUND
echo Assembly found.
It's ugly, as there definitely are key repetitions, but works for now.
The same goes for reg delete operations. It's manageable for now, but definitely there could be a better solution.
so ive been searching for the solution to this problem for awhile now, everywhere i look everyone just says "set the compsec to point to cmd"...which is super helpful cause no one actually even says how to do that.
but when i open cmd, and type "Set" and hit ENTER, it shows ComSpec=C:\Windows\system32\cmd.exe
I checked there and sure enough, cmd.exe is in there, it works just fine. But for/f still closes before performing any operation.
How do I fix this?
#echo off
for /f "tokens=2*" %%a in ('dir /b /s findstr "Find Me Testing"') do set "AppPath=%%~b"
set "AppPath=%AppPath%"
echo %AppPath%
for /f "tokens=2*" %%a in ('dir /b /s /a-d ^| findstr "Find Me Testing"') do set "AppPath=%%~b"
set "AppPath=%AppPath%"
echo %AppPath%
pause
for /f "usebackq" %a in ('dir /b /s /a-d ^| findstr "To Be Deleted.me"') do set fileLocation=%~pa
echo %fileLocation%
pause
pause
stop
pause
wait 50
As you can see I've been testing various methods of doing what I want.
I lay good odds that your problem is with the cmd.exe autorun feature.
If you open a command session and enter cmd /?, then at about the 5th paragraph you will see the following:
If /D was NOT specified on the command line, then when CMD.EXE starts, it
looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if
either or both are present, they are executed first.
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
and/or
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
I'd be willing to bet that one of those two registry settings is set to a command or script that is causing your problem. Edit your registry and remove those settings, and your problem should go away.
You can see a similar story about a user having trouble with FOR /F at https://blogs.msdn.microsoft.com/oldnewthing/20071121-00/?p=24433.
The FOR /F command executes your commands within your IN('....') clause via a new cmd.exe process, and that process will always run any autorun setting that may be present. Unfortunately it is impossible to disable this FOR /F "feature" - I think this is a horrible design flaw.
Windows pipes also use child cmd.exe processes - one for each side of the pipe. But the pipe instantiation of cmd.exe includes the /D option, so autorun is disabled. You can see this by running the following command from the command line:
echo %^cmdcmdline% | findstr "^"
On my machine it produces the following:
C:\WINDOWS\system32\cmd.exe /S /D /c" echo %cmdcmdline% "
Now do the equivalent with FOR /F (on a healthy machine)
for /f "delims=" %a in ('echo %^cmdcmdline%') do #echo %a
My machine produces:
C:\WINDOWS\system32\cmd.exe /c echo %cmdcmdline%
No /D option :(
I on windows 8.1. I get USB with hidden file/folders. To unhide them I use attrib command . I want to run the commands by simply inserting the USB. Pl help.
echo off
echo Please have patience!!! Wait or Minimise the window!!!
rem c:\script\unhide.bat
#echo off
for /F "usebackq tokens=1,2,3,4 " %%i in (`wmic logicaldisk get caption^,description^,drivetype 2^>NUL`) do (
if %%l equ 2 (
echo %%i is a USB drive.
)
)
Pause
Here I got the drive letter H. I am unable to use drive letter and use the following commands in USB. How can is I run below commands in USB. I mean Change Drive, run attrib command in USB, delete unwanted files from USB and see USB's contents.
cd\
attrib -s -h -r /s /d
del *.lnk
del thumbs.db
del desktop.ini
del autorun.inf
echo Your Folders has been recovered!!! Check your folders and files
dir
pause
exit
#ECHO OFF
SETLOCAL enableextensions
echo Please have patience!!! Wait or Minimise the window!!!
rem c:\script\unhide.bat
for /F "skip=1 tokens=1-3" %%i in ('
wmic logicaldisk where "drivetype=2" get caption^,drivetype^,SystemName
') do (
if "%%j"=="2" (
echo "%%i" is a USB drive ^(DriveType=%%j^).
pushd "%%i\"
SETLOCAL enabledelayedexpansion
echo current folder !CD!
ENDLOCAL
echo attrib -H -S -T /S /D /L >NUL 2>&1
echo del *.lnk 2>NUL
echo del thumbs.db 2>NUL
echo del desktop.ini 2>NUL
echo del autorun.inf 2>NUL
echo Your Folders has been recovered!!! Check your folders and files
dir
pause
popd
)
)
ENDLOCAL
goto :eof
Note:
wmic command changed as follows:
where clause;
description omitted as this property vary in word number and therefore breaks the tokenization;
always non-empty property SystemName appended to pass over the ending carriage return in the line returned: wmic behaviour = each output line ends with 0x0D0D0A (<CR><CR><LF>) instead of common 0x0D0A (<CR><LF>). For another (general) approach see Dave Benham's WMIC and FOR /F: A fix for the trailing <CR> problem;
for /F loop adapted according to altered wmic command (and skip=1);
operational attrib -H -S -T /S /D /L is merely echoed for debugging purposes; remove echo no sooner than debugged (the same for all del commands);
used pushd - popd pair: PUSHD changes the current directory/folder and stores the previous folder/path for use by the POPD command;
folder System Volume Information should keep attributes System & Hidden if present.
I have an issue with deleting files from a command line. I can delete the file just fine through the Windows interface but i need to be able to run a script and delete multiple files. I am getting access denied and I am logged in as administrator. Any thoughts?
Here is the code
cd C:\views\IPGW_bld4_snap\direcpc
#echo off
setlocal enableextensions disabledelayedexpansion
for /f "delims=" %%a in ('cleartool ls -r -view_only') do del /q "%%a"
pause
Here is the output from cleartool ls -r -view_only
c:\views\IPGW_bld4_snap\direcpc>cleartool ls -r -view_only
.\noc\ipgateway\build\gen_html.vcproj
.\noc\ipgateway\build\libfcgi.vcproj
.\noc\ipgateway\build\libjson.vcproj
.\noc\ipgateway\ipgw\fcgicmdinf.c
.\noc\ipgateway\ipgw\fcgicmdinf.h
.\noc\ipgateway\ipgw\genconfightml.h
c:\views\IPGW_bld4_snap\direcpc>
In a ClearCase snapshot view, you can find file in read-only by default.
As mentioned in "Batch delete : Access is denied", try using del /F /Q
for /f "delims=" %%a in ('cleartool ls -r -view_only') do del /f /q "%%a"
You can couple that with "How to delete empty folders using windows command prompt?":
for /f "usebackq delims=" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"
That way, no empty folder is left behind after removing private files.