-1

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
meatspace
  • 859
  • 16
  • 25
user2378786
  • 41
  • 1
  • 7
  • 2
    A good first step would be to tell us what those errors are. – hammar May 17 '13 at 19:57
  • 1
    Detecting flash drives is no easy matter with batch script. I have tried it many times and never truly succeeded. I would say it is beyond the scope of help in a simple question like this. – djangofan Jul 05 '13 at 17:00
  • 1
    "Check the display pixels" = get the current display resolution? – meatspace Jan 09 '15 at 15:47

2 Answers2

0

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.

David Chapman
  • 123
  • 1
  • 7
-1

I would recommend trying

chkdsk volume=C:\ D:\ E:\ F:\

to check the disks each as a separate volume

CMS_95
  • 335
  • 3
  • 13