my intent is to get this..
cls
setlocal enableextensions disabledelayedexpansion
echo Create backup txt file of mapped drives
echo -----
set /p PCname=Asset tag or IP address:
set /p UserID=UserID:
for /f "tokens=2,3 delims=," %%a in (
'wmic netuse get LocalName^, RemoteName^, Status /format:list ^| find ":"'
) do echo(%%a %%b>> \\%PCname%\c$\windows\temp\%PCname%_%UserID%_map.txt
xcopy /d/y \\%PCname%\c$\windows\temp\%PCname%_%UserID%_map.txt ".\remoteStats\"
pause
Goto :mdmenu
to map drives of a remote pc,%PCname%,to a text file with just the drive letter and path, copy that text file to the techs computer running the script into a .\remotestats\ folder
this way I can use that same text file to remap those drives automatically
:mdrestore
cls
echo Map Drives from backup txt
echo -----
echo Notes:
echo Needs a backup to restore from, inside
echo remoteStats folder
echo.
set /p PCname=Asset tag or IP address:
set /p UserID=Enter BH Username:
for /f %%a in (.\RemoteStats\%PCname%_%username%_map.txt) do Psexec \\%PCname% -d -s cmd /c net use %%a /p:Yes
psexec \\%PCname% -d cmd.exe /c net use S: \\mapped.drive\share /p:Yes
psexec \\%PCname% -d cmd.exe /c net use H: \\mappeddrive2\home /p:Yes
Print "Drives mapped"
Timeout /t 30 >nul
GOTO :mdmenu
Related
Iv got my code to show a list of USb devices connected to my laptop and i can select the USB as well but when i try to back up a folder into the USB what i get instead is a folder named f in the folder i was trying to save. This is the code i have for selectong a USB device
for /f "delims=" %%a in ('wmic logicaldisk where drivetype^=2 get deviceid ^| find ":"') do set "$List=!$List! %%a"
:USB
echo Avaiable Drive ==^> !$List!
set /p "$Drive=Enter the letter of the Backup drive : "
echo !$List! | find /i "%$Drive::=%:" && Echo drive OK || Echo drive do not exist && goto:USB
set backupcmd=robocopy
and this is the code that backup the folder
%backupcmd% "%cd%" "%$Drive%"
Give this one a go:
#echo off
setlocal enabledelayedexpansion
set num=0
for /f %%a in ('wmic logicaldisk where drivetype^=2 get drivetype^, deviceid ^| find ":"') do (
set /a num+=1
set cnt=!cnt!!num!
echo (!num!^) %%a
set "d!num!=%%a"
)
choice /c !cnt! /M "select a number to choose a drive: "
echo You've chosen drive !d%errorlevel%! you can do everything with it from here..
You will notice that I set delayedexpansion here because of the setting and using of variables inside of the parenthesised code block.
Choice is a good option here as it does not allow typing the wrong values.
How to get pc mac address and restart PC if mac is not on the list.txt?, i only have this getting mac command,
for /f "tokens=3 delims=," %%a in ('"getmac /v /fo csv | findstr Ethernet"') do set MAC=%%a
echo MAC address of this computer is %MAC%
You use getmac and pipe the result through findstr to filter on the required network adaptor.
You store the result into a variable ThisPCMAC
You use the type command to get the content of the list.txt file piped through findstr to filter on ThisPCMAC.
You store the result into a variable FoundMAC.
If FoundMAC is defined you goto :norestart
If FoundMAC is not defined you goto :restart
In :restart, you call shutdown /r with the required additional params
If mistaken, you can call shutdown /a in the allotted time (10 minutes here, see /t 600).
For further help, see shutdown /?
The 2 files should be in the same directory.
Example content of list.txt:
FF-AA-BB-CC-DD-FA
FF-AA-BB-CC-DD-FB
FF-AA-BB-CC-DD-FC
Content of RestartIfThisPCMACnotInList.bat:
#echo off
set ScriptPath=%~dp0
set ThisPCMAC=
set FoundMAC=
echo.
echo ScriptPath = %ScriptPath%
for /f "tokens=3 delims=," %%a in ('"getmac /v /fo csv | findstr Ethernet"') do set ThisPCMAC=%%a
echo.
echo MAC address of this computer is %ThisPCMAC%
for /F "usebackq delims==" %%b in (`"type %ScriptPath%list.txt | findstr %ThisPCMAC%"`) do set FoundMAC=%%b
if DEFINED FoundMAC (
goto :norestart
) else (
goto :restart
)
:norestart
echo.
echo Found %FoundMAC% in %ScriptPath%list.txt: Nothing to do.
goto :end
:restart
echo.
echo %ThisPCMAC% not found in %ScriptPath%list.txt: Restarting...
echo.
echo shutdown /r /f /t 600 /d p:00:00
shutdown /r /f /t 600 /d p:00:00
echo.
echo Cancel restart with the following command:
echo shutdown /a
goto :end
:end
echo.
echo %~fp0 ended.
pause
Example output for :norestart:
C:\test\>RestartIfThisPCMACnotInList.bat
ScriptPath = C:\test\
MAC address of this computer is "FF-AA-BB-CC-DD-FA"
Found FF-AA-BB-CC-DD-FA in C:\test\list.txt: Nothing to do.
C:\test\RestartIfThisPCMACnotInList.bat ended.
Press any key to continue . . .
Example output for :restart:
C:\test\>RestartIfThisPCMACnotInList.bat
ScriptPath = C:\test\
MAC address of this computer is "FF-AA-BB-CC-DD-FD"
"FF-AA-BB-CC-DD-FD" not found in C:\test\list.txt: Restarting...
shutdown /r /f /t 600 /d p:00:00
Cancel restart with the following command:
shutdown /a
C:\test\RestartIfThisPCMACnotInList.bat ended.
Press any key to continue . . .
I don't know how to code myself, just managed to find some from Google and try to compile it. But it didn't work as I expected. Recently I've found that there is a virus spreading among my place without the user realizing it. The batch file is supposed to remove the files from the specified drive's %temp% folder with the extension .exe with exactly 138784 bytes. This the batch file I came up with, it works for removing it from the temporary folder but not for removing the file on their removable drive:
#ECHO OFF
ECHO "Enter Drive letter"
set /p letter=
for /r %%f in (*.exe) do if %%~zF EQU 138784 del %%F /f
attrib -s -h -a /s /d %letter%:*.*
c:
cd %temp%
Del wdr201.exe /f
ECHO "Process completed."
Pause
You can give a try for this code inspired from this one : Hackoo_Virus_Cleaner.bat
#echo off
Mode con cols=80 lines=6 & Color 9E
Title Searching the Drive letter of your USB Key and clean *.lnk files by Hackoo 2016
Set TmpLogFile=%tmp%\TmpLog.txt
Set "LogFile=%UserProfile%\Desktop\Hackoo_Virus_Clean_%UserName%_Log.txt"
If Exist %TmpLogFile% Del %TmpLogFile%
If Exist %LogFile% Del %LogFile%
for /f "tokens=2" %%i in ('wmic logicaldisk where "drivetype=2" ^|find /i ":"') do (Set MyUSB=%%i)
cls
setlocal ENABLEDELAYEDEXPANSION
set _drive=%MyUSB%
If Exist !_drive! (
cls
echo.
echo #########################################################
echo Your usb key is connected as !_drive!
echo #########################################################
echo Hit any key to remove malicious files and unhide files ...
pause>nul
Cls
echo(
Echo Removing malicious files/unhiding files... Please wait, this may take a while...
del /s /f /q !_drive!\*.lnk>>"%TmpLogFile%"2>&1
Cmd /U /C Type "%TmpLogFile%" > "%LogFile%"
Start "" %LogFile%
attrib -s -h -a -r /s /d !_drive!\*.*
Explorer "!_drive!\"
) ELSE (
cls
color 0C
echo.
echo #########################################################
echo Your usb key is not detected
echo #########################################################
echo.
)
pause & exit
I have a working simple batch-file program which unhides predefined drive hidden folders.
What I want to do is:
To insert Drive letter by a user instead of predefined and other option if you suggested me.
my unhide.bat code is:
#echo off
D:
attrib -r -s -h /s /d
pause
You can use set /p DriveLetter=Please enter drive letter.. If you then run %DriveLetter% as a command, it will expand as you expect.
To make your code work:
#echo off
set /p DriveLetter=Please enter drive letter.
%DriveLetter%
attrib -r -s -h /s /d
pause
They would enter "D:" and it would accept it as such.
The only thing to note is that if someone uses an incorrect drive letter, bad stuff will happen.
Alternatively, you could use a large block with CHOICE, but that seems overkill. You'd have to define every drive letter. Thus, I won't go into detail on this.
This should do:
SET /P letter=Please give your drive letter and press ENTER:
ECHO %letter%
PAUSE
I guess that you try to unhide the folders into the USB Drive caused by a worm
If you like to detect the drive letter of your USB Key, Try this code instead,
I made this tool to unhide folders and files and delete all infected links into the USB key
#echo off
Mode con cols=98 lines=10 & Color 9E
Title Searching the Drive letter of your USB Key by Hackoo 2014
echo.
ECHO *******************************************************************************************
echo.
echo Searching the drive letter of your USB Key .......
echo.
ECHO *******************************************************************************************
wmic logicaldisk get DeviceID,DriveType /Format:CSV > %Tmp%\tmp.txt
for /f "skip=2 tokens=1-3 delims=," %%a in ('%COMSPEC% /a /c type "%Tmp%\tmp.txt"') do echo %%b %%c >> %Tmp%\tmp2.txt
for /f "tokens=1" %%i in ('%COMSPEC% /a /c type "%Tmp%\tmp2.txt" ^|Find "2"') Do (set MyUSBDrive=%%i)
Del %Tmp%\tmp.txt & Del %Tmp%\tmp2.txt
cls
echo.
ECHO *******************************************************************************************
echo.
echo The drive letter of your USB Key is %MyUSBDrive%
echo.
ECHO *******************************************************************************************
pause
cls
echo.
echo.
ECHO *******************************************************************************************
echo.
echo Press a button to delete infected shortcuts and restore hidden files in your USB key
echo.
ECHO *******************************************************************************************
pause>nul
cls
echo.
echo.
ECHO *******************************************************************************************
echo.
echo Deleting infected shortcuts and restoring hidden files
echo.
ECHO *******************************************************************************************
:: To Unhide Folders and files into your USB key
Attrib -s -h -r %MyUSBDrive%\*.* /D /S >nul 2>&1
:: To delete all infected files.lnk
Del %MyUSBDrive%\*.lnk >nul 2>&1
Explorer %MyUSBDrive%
pause
I am not really a programmer. I am a newbie.
Can you guys please help me with a windows batch file that will run a computer test?
Detect any hard drives then run a chkdisk on them
Detect any usb port
Detect any flash drive plug in the pc
Check the display pixels
I have started with this to detect the USB but somehow getting some errors
#echo off
setlocal EnableDelayedExpansion
set PNPDeviceID=4002FDCCE0E4D094
set Q='wmic diskdrive where "interfacetype='USB' and PNPDeviceID like '%%%PNPDeviceID%%%'" assoc /assocclass:Win32_DiskDriveToDiskPartition'
echo %Q%
for /f "tokens=2,3,4,5 delims=,= " %%a in (%Q%) do (
set hd=%%a %%b, %%c %%d
call :_LIST_LETTER !hd!)
goto :_END
:_LIST_LETTER
(echo %1 |find "Disk ") >nul|| goto :_EOF
for /f "tokens=3 delims==" %%a in ('WMIC Path Win32_LogicalDiskToPartition ^|find %1') do set TMP_letter=%%a
set Part_letter=%TMP_letter:~1,2%
echo %Part_letter% %1
goto :_EOF
:_END
:_EOF
:: *** end
pause
Here is a batch script that does almost everything you need.
Checkdisk will run against any local fixed drives. You can have it run in a new window (chkdskAsync=true) or have it run inside the program (chkdskAsync=false). Additionally, specify the chkdsk flags using the chkdskLaunchArguments= variable.
#ECHO OFF
CLS
SETLOCAL ENABLEDELAYEDEXPANSION
:: Use these lines to specify how CHKDSK and Notepad will run
:: ===============================================
SET chkdskLaunchArguments=/F /R
SET chkdskAsync=true
SET launchNotepad=true
:: ===============================================
COPY /Y NUL C:\Users\public\data.txt >nul 2>&1
ECHO Getting drive(s) information
FOR /F "tokens=*" %%A IN ('wmic logicaldisk get caption^, description^, providername^, volumename') DO (
ECHO.%%A>>C:\Users\public\data.txt
)
FOR /F "tokens=1,2 skip=1" %%A IN ('wmic logicaldisk get caption^, drivetype') DO (
IF %%B EQU 3 (
IF "!chkdskAsync!" EQU "true" (
START CMD /C CHKDSK %%A %chkdskLaunchArguments%
) ELSE (
CHKDSK %%A %chkdskLaunchArguments%
)
)
)
ECHO Getting resolution information
FOR /F "tokens=*" %%A IN ('wmic path Win32_VideoController get CurrentHorizontalResolution^,CurrentVerticalResolution') DO (
ECHO.%%A>>C:\Users\public\data.txt
)
ECHO Information gathered ... saved to C:\Users\public\data.txt
ECHO Showing results.
IF "!launchNotepad!" EQU "true" (
START /WAIT notepad.exe /A C:\Users\public\data.txt
)
ENDLOCAL
EXIT
When it is complete it saves everything to C:\Users\Public\data.txt. It will also launch the file in notepad (if launchNotepad=true is set to ... true).
The output looks like so:
Caption Description ProviderName VolumeName
A: Network Connection \\somefileserver.domain\ New Volume
C: Local Fixed Disk
E: Removable Disk someuser Drive
H: Network Connection \\somefileserver.domain\users$\someuser Data Share and User Home Dirs
P: Network Connection \\somefileserver.domain\Data Data Share and User Home Dirs
S: Network Connection \\somefileserver.domain\share
CurrentHorizontalResolution CurrentVerticalResolution
1920 1080
NOTE: Make sure to run this as an administrator. If you want chkdsk to run
Unfortunately, there isn't a way to grab all USB devices other than storage. Hope this helps!
I didn't realize this question is 4 years old. Going to leave my answer for posterity and anyone digging for answers.
I would recommend trying
chkdsk volume=C:\ D:\ E:\ F:\
to check the disks each as a separate volume