I have tried googling it but couldn't find it. I know the command for it is cd /media for linux but have no idea what it is for Windows.I also tried the dir command but couldn't find anything related to media or usb.
You can access the USB drive by its drive letter. To know the drive letter you can run this command:
C:\>wmic logicaldisk where drivetype=2 get deviceid, volumename, description
From here you will get the drive letter (Device ID) of your USB drive.
For example if its F: then run the following command in command prompt to see its contents:
C:\> F:
F:\> dir
firstly you have to change the drive, which is allocated to your usb.
follow these step to access your pendrive using CMD.
1- type drivename follow by the colon just like k:
2- type dir it will show all the files and directory in your usb
3- now you can access any file or directory of your usb.
Try this batch :
#echo off
Title List of connected external devices by Hackoo
Mode con cols=100 lines=20 & Color 9E
wmic LOGICALDISK where driveType=2 get deviceID > wmic.txt
for /f "skip=1" %%b IN ('type wmic.txt') DO (echo %%b & pause & Dir %%b)
Del wmic.txt
pause
Related
I have a requirement where i need to delete the contents of the temp folder on number of remote windows machines.
i tried below wmic command to delete
WMIC /node:...** /user:xxxx /password:xxxx path cim_datafile WHERE "path='%Winddir%\temp*.tmp' AND Extension ='tmp'" delete**
But it throws an error saying
ERROR:
Description = The RPC server is unavailable.
Please suggest me a way to delete temp folder contents on remote machine.
Most simple way - if you're not strictly forced to use WMI, you can do that with psexec:
PsExec.exe \\<computer> cmd /c "rmdir /s /q %windir%\temp\"
or, if you're not logged into domain admin or global workstations admin account -
PsExec.exe -u <user> -p <password> \\<computer> cmd /c "rmdir /s /q %windir%\temp\"
If should not completely delete the folder since Windows keeps some files open and locked inside it, but anything not read-only or locked would be deleted, both files and folders.
Then, to do this with a list of computers, just use a cmd file like this (list.txt contains just computer names/ips, without \:
for /F %%s in (list.txt) do (
echo %%s
start "" /min PsExec.exe \\%%s cmd /c "rmdir /s /q %windir%\temp\"
)
Start command makes all psexec processes run in parallel and minimized so you don't have to wait for each computer to finish before starting another
psexec.exe is a part of sysinternals package from M. Russinovich, I'd like to leave a direct link but don't know if it's permitted or not.
I think it should be able to connect to remote pcs if you have access to file shares and remote computer management (and admin rights of course)
I am trying to add a network printer via batch file, provided I feed the data(Printer IP, Printer Name, Computer IP) into the entries.
rundll32 printui.dll,PrintUIEntry /if /b "KONICA MINOLTA C451 PS(P)" /c\\%computerNameIP% /h "x86" /f %windir%\inf\prnkm002.inf /r "IP_%computerNameIP%" /m "KONICA MINOLTA C451 PS(P)" /n\\%computerNameIP%\%printerName% /F %windir%\inf\prnkm002.inf
Now, once this command is completed, I receive the following error:
Operation could not be completed(error 0x00000032). This operation is not supported.
I ran a similar code with runs the GUI:
rundll32 printui.dll,PrintUIEntry /il /b "KONICA MINOLTA C451 PS(P)" /c\\%computerNameIP% /h "x86" /f %windir%\inf\prnkm002.inf /r "IP_%computerNameIP%" /m "KONICA MINOLTA C451 PS(P)" /n\\%computerNameIP% \%printerName% /F %windir%\inf\prnkm002.inf
and I have to choose a local local Printer: which I adjust to be TCP/IP and the drivers come default since I set it. After choosing my driver, I receive the error as well.
I just can't pinpoint what exactly isn't supported.
Windows 7 32-bit. I made adjustments to the registry, print management, group policy, but none of those seem concrete to what is preventing a remote add to a network printer.
I found another way to do it with the prncnfg.vbs files. First create the port, assign it, then manage it.
This is all located in the admin scripts in Windows folder
In the building system I use some script that copies files from a network drive to the Hudson's workspace by using SMB. Then performs decompression it and deletes the old files.
net use \\NET_DRIVE\ipc$ /user:admin password
robocopy \\NET_DRIVE\SharedFolder/ C:\Users\user\.hudson\jobs\ais\workspace vendor.7z>nul
net use \\NET_DRIVE\ipc$ /D
cd "C:\Users\user\.hudson\jobs\ais\workspace">nul
rd /s /q "C:\Users\user\.hudson\jobs\ais\workspace\vendor\">nul
7za x vendor.7z>nul
del vendor.7z>nul
When I execute this script from Windows command line, everything works and I get my archive. But when I use it in the pipeline, I get error 1326:
Logon failure: unknown user name or bad password
I added the remote domain to the script so that the Windows had not invoked a local account, but it didn't help. I decided to run the command which mount network drive "manually":
net use \\NET_DRIVE\ipc$ /user:admin password /persistent:yes
Then the script a little bit reduced and became working:
robocopy \\NET_DRIVE\SharedFolder/ C:\Users\user\.hudson\jobs\ais\workspace vendor.7z>nul
rd /s /q "C:\Users\user\.hudson\jobs\ais\workspace\vendor\">nul
7za x vendor.7z>nul
del vendor.7z>nul
But I would like to be able to mount SMB-shares from the Hudson's job. How to do it?
Hudson's/ Jenkin's service or servlet- container where it deployed should be run with administrator's privileges.
I want to find location of 'cmd.exe' or 'powershell.exe' from remote computer. I want to execute a script from remote computer. To execute it I want location of 'cmd' or 'powershell.exe'. It is possible that windows is installed on any drive. so how to find where is my windows is installed.
It's available via WMI (Win32_OperatingSystem)
wmic.exe /NODE:<remote_computer> OS GET WindowsDirectory
To get the path + file of cmd.exe you can use this variable: %ComSpec%, which will return C:\Windows\System32\cmd.exe in most cases. To get only the path to that location, you can use for instance (in the cmd)
for /f %a in ("%ComSpec%") do echo %~dpa
or (in a batch-file)
for /f %%a in ("%ComSpec%") do echo %%~dpa
Use %WINDIR% environment variable
Example:
set "_path=%WINDIR%\system32\cmd.exe" --> sets _path variable
cd /d %_path% --> goes to _path folder
I am writing a batch script to use USMT to update computers from XP to 7. Because USMT has a scanstate component that needs to be run before the OS upgrade and a loadstate computer that has to be run after the OS upgrade I am trying to use an if statement to check what the operating system is and then run the proper commands. I am new to batch files but from everything I have been reading it seems like I am writing it properly but I am obviously messing up somewhere. I am getting a "Windows is unexpected at this time error." I also know that the variables are being set properly because of the pause commands that I included. I also tried using IF %WINVERSION% == %XP% goto XPTRUE/WIN7TRUE and enclosing everything within the brackets under a :XPTRUE/WIN7TRUE but that gives the same error.
::Don't have commands print...only outputs are printed
#echo off
:: Set constants
SET XP=Microsoft Windows XP [Version 5.1.2600]
SET WIN7=Microsoft Windows [Version 6.1.7601]
SET XPUSMTLOCATION=C:\Program Files\USMT\Binaries\v4\x86
SET 7USMTLOCATION=C:\Program Files (x86)\USMT\Binaries\v4\amd64
SET BACKUPLOACTION=\\[SERVER IP]\z$\UserAccountBackUps\Backups
SET LOCALBACKUPLOCATION=C:\Backup\USMT
SET NASBACKUPLOCATION=S:\UserAccountBackUps\Backups
#PAUSE
::Get the current version of Windows batch file is running on and store it in WINVERSION
FOR /f "delims=" %%A IN ('ver') DO #SET WINVERSION=%%A
echo %WINVERSION%
PAUSE
::Get the MAC address of the computer and store it in MACA
FOR /F %%A IN ('getmac') DO #SET MACA=%%A
echo The MAC Address is: %MACA%
:: Tell user about script
echo This is a script designed to migrate computers with one network card from Windows XP to Windows 7 using USMT, this script should not be used with computers that have multiple network cards
echo Xp is %XP%
echo 7 is %WIN7%
::Check to see if the current version is XP
PAUSE
IF %WINVERSION% == %XP% (
echo This is windows XP
::Change directory to the location of USMT files
cd %XPUSMTLOCATION%
::Run scanstate to create backup
scanstate.exe C:\Backup /i:"\\[SERVER IP]\z$\UserAccountBackUps\USMT_XML_Files\MigApp.xml" /i:"\\[SERVER IP]\z$\UserAccountBackUps\USMT_XML_Files\MigDocs.xml" /i:"\\[SERVER IP]\z$\UserAccountBackUps\USMT_XML_Files\MigUser.xml" /o /v:2
::Change directory to the location of where the USMT backup is
cd %LOCALBACKUPLOCATION%
::Rename the backup to the MAC Address
rename USMT.MIG %MACA%.MIG
::Map the NAS to a drive because xcopy can not take IP addresses
echo Mapping NAS to drive
::NAS is mapped to drive S, if S is used for something else change s below to different letter
net use s: \\[SERVER IP]\z$
echo Prepairing to copy backup to NAS
::Use xcopy to transfer backup file the /v ensures the files are identical
::This must be done this way because if USMT tries to backup directly to the NAS it tries to overwrite all existing files
xcopy %LOCALBACKUPLOCATION%\%MACA%.MIG %NASBACKUPLOCATION% /v
echo The copy has completed, run this batch file again after OS Upgrade
)
IF %WINVERSION% == %WIN7% (
echo This is Windows 7
PAUSE
)
When I run this on my Windows 7 computer I get this:
I get the same output on my XP computer except it tells me the current version is xp instead. Help would be greatly appreciated.
The line below:
FOR /f "delims=" %%A IN ('ver') DO #SET WINVERSION=%%A
stores in WINVERSION variable a string that contain several words separated by spaces, for example:
SET WINVERSION=Microsoft Windows [Version 6.2.9200]
This way, the line below:
IF %WINVERSION% == %XP% (
is expanded to:
IF Microsoft Windows [Version 6.2.9200] == Microsoft Windows XP [Version 5.1.2600] (
that, of course, cause a syntax error! Type: IF /? for further details.
The way to compare two strings that may contains spaces, is enclosing they in quotes:
IF "%WINVERSION%" == "%XP%" (