%~d0:\Tools\Fionas_Collection.bat %1 %2
set Toolpath = %1:\Tools\
set Collectdrive = %2:\Collect\
set /p Case= "What is your case number?"
echo Case Number: %Case% >> %CollectDrive%:\Collect\"%Case%_CaseFile.txt"
set /p Name= "What is your name?"
echo Examiners Name: %Name% >> %CollectDrive%:\Collect\"%Case%_CaseFile.txt"
Trying to open my USB drive and run this program that has a bunch of commands to run but every time I run it in CMD it says the filename, directory name, or volume label syntax is incorrect. I am not understanding why I keep getting this error?
Remove the spaces around the = signs.
set Toolpath=%1:\Tools\
set Collectdrive=%2:\Collect\
Related
I want to make a batch file (or PowerShell if you like it better, you can choose. My code is a batch file), to automate file transfer to an Android device
So, the user would be asked the location and name of the original file
Then, the user is asked the location of the destination.
Then, the adb push command is run
The code I have is:
set /p filename="What is the location and name of the file you want to transfer? > "
set /p location="What is the location you want to set it to? > "
set fullmsg=adb push '%filename%' '%loaction%'
echo %fullmsg%
#just echoing out, to make shure it's correct
pause
What happens now is, it outputs:
adb push 'file.txt' ''
So, the location is empty. Also, what if the filename has an apostrophe (') or something like: that's right.txt
Off course, it needs to be in quotes, but what if you have a location like: \\mysharedfolder\text files\ #notice the backslash and the space in between the words text and files
Hope this explanation is good enough, cause I don't know how to explain it well.
Thanks in advance
In PowerShell:
$file = Read-Host 'What is the location and name of the file you want to transfer?'
$location = Read-Host 'What is the location you want to set it to?'
# Showing command about to be run
Write-Host "adb push $file $location"
# pausing before running command
pause
adb push $file $location
I wanted to give this choice
#echo off
echo what operation you wanted to perform
echo a:creating a new web server?
echo or
echo b:Edit root url for already existed web server
set /P var = "What is your option a or b"
if "%var%" == "A" (
cd C:\Program Files\Infor\Mongoose\Tools
infordbcl.exe addwebserver -name:sample -product:Mongoose -rooturl:https://uscovwmongoose3
)
if "%var%" == "B" (
infordbcl.exe addwebserver -name:sample -product:Mongoose -rooturl:https://mongoose.com -
mode:edit
)
I ran this batch file using powershell.
After entering the choice A or B, the commands specified in if blocks are not getting executed in cmd.exe
Is their any syntax errors in it, please let me know
This is how Choice could be used here:
#echo off
Choice /N /C ce /M " <?> (C)reate new Server <?> (E)dit root url for existing web server"
If Errorlevel 2 (
REM If the Change directory command is also meant to execute in this block, remove and place CD command prior to choice command.
infordbcl.exe addwebserver -name:sample -product:Mongoose -rooturl:https://mongoose.com -mode:edit
) Else (
REM confirm if lack of url extension is correct
cd "C:\Program Files\Infor\Mongoose\Tools"
infordbcl.exe addwebserver -name:sample -product:Mongoose -rooturl:https://uscovwmongoose3
)
Explanation:
/N hides the default prompt (whatever keys are defined using /C or the default Y/N if /C is not used)
/C allows definition of keys within the range 0-9 and A-Z
errorlevel for each key is set according to occurance after the /C
switch
for /C ce, c will return Errorlevel 1, e will return errorlevel 2
and so on
/M "string" allows a custom string to be defined to explain the Choice. Encase the string within doublequotes.
When you test the returned Errorlevel
You must test from Highest to Lowest.
This is because the command intepreter reads If Errorlevel n as If Errorlevel n or higher
For more information and usage examples, type choice /? in cmd.exe
Basically just attempting to create a very basic program that will display the last modified date of a file on our server. Problem is I have no idea how to write it. This is what I attempted
cd \\Server\Folder
msg dir
I also ran into the problem "CMD Does not support UNC Paths as Current Directories" when I tried to change the CD to our servers directory.
What I would like it to do is display in a dialog box the modified date of a "Text.txt" located on our server \\Server\Folder
Any and all help is appreciated
Next .bat script should work:
set "_folder=\\Server\Folder"
set "_filename=Text.txt"
set "_filedatetime=N/A"
pushd %_folder%
for %%G in (%_filename%) do (
rem echo %%~tG %%~fG
if not "%%~tG"=="" set "_filedatetime=%%~tG"
)
popd
echo file %_folder%\%_filename% date and time: %_filedatetime%
Note there is no dialog box in pure cmd command line interpreter, try set /P.
Resources:
SET: Display, set, or remove CMD environment variables
PUSHD, POPD: and UNC Network paths
FOR commands
~ Parameter Extensions
I am trying to run this command in windows:
ping -n 5 127.0.0.1 > nul
I get the error:
'ping' is not recognized as an internal or external command operable
program or batch fie.
Why can't windows find ping? Here is my script where it does not work:
#ECHO OFF
::set path
SET path=M:\\5.bmp
:findfile
IF EXIST %path% (
ECHO File found
) ELSE (
ECHO File not found
ping -n 5 127.0.0.1 > nul
goto findfile
)
You have overridden the PATH environment variable, so the command processor can no longer find the ping executable.
The fix is nice and simple - just use a different variable name!
:: set path
SET MyPath=M:\\5.bmp
:findfile
IF EXIST %MyPath% (
Please note that if you genuinely wanted to set the path environment variable, you should append to it like so:
REM Set temporarily for this session
SET PATH=%PATH%;C:\Some\Folder
REM Set permanently (but note - this change will not be made to this session)
SETX PATH=%PATH%;C:\Some\Folder
Hi to fix "ping" please follow below steps
Go to Properties in My computer
Advanced system settings ----->Advanced -----> Environment Variables
Select 'PATH' from the list of system variables and edit and set PATH to c:\windows\system32 ; this will solve your problem.
-----> if still u have a problem, do the below steps...
Control Panel --> System and security --> Windows Firewall --> Advanced settings --> Inbound rules --> New rule --> custom rule
in Protocol and ports: Protocol: ICMPv4
on the same panel go to customize, choose "Specific ICMP types", check the box "echo request"
The rest is trivial; go to next... next... and save it.
You should be done. This box responds ping from this point on.
Cheers
Prasad
How to diagnose this error:
'ping' is not recognized as an internal or external command operable
program or batch fie.
Because your path environment variable does not contain the directory that points to the executable: ping.exe. So the question becomes why can't your command line program cmd.exe locate ping.exe?
You can print out your path variable on the commandline like this:
echo %PATH%
Which prints for me:
C:\WINDOWS;C:\WINDOWS\system32;C:\Program Files\jZip;C:\MinGW\bin
The above string is delimited by semicolons(;). Notice the element called: C:\WINDOWS\System32, that is the element that defines where ping.exe can be located.
Solutions
You didn't specify C:\WINDOWS\System32 in your path variable. Make sure it is there.
ping.exe is missing. Find out who deleted it and put it back.
ping.exe is corrupt. Run it where it sits: C:\WINDOWS\System32\ping.exe, or replace ping.exe.
You have overridden the PATH variable before you look for it.
I'm launching WinPE 2 from a bootable UFD, and I need to detect the drive letter in order to tell ImageX where to find the WIM. However, depending on the machine I'm imaging, there are different mounted drives.
I need a way to consistently mount the UFD at, say, P: or something. Is there a way to detect the letter of the drive from which the machine was booted, or another way to pass the location of my WIM file to a variable accessible from startnet.cmd?
Here's someone else with the same issue over at TechNet.
http://social.technet.microsoft.com/Forums/en-US/itprovistadeployment/thread/3e8bb8db-a1c6-40be-b4b0-58093f4833be?prof=required#
This VBScript will show a message for each removable drive (letter:description), could be easily modified to search for a particular drive and return the letter.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where MediaType = 11")
For Each objDisk in colDisks
Wscript.Echo objDisk.DeviceID & objDisk.Description
Next
Don't know if that helps at all.
It's a less generic solution than the others mentioned here, but there appears to be a specific way to determine which underlying volume a "RAM-drive-booted" Windows PE OS was booted from. From the documentation on Windows PE in the Windows Automated Installation Kit:
If you are not booting Windows
Deployment Services, the best way to
determine where Windows PE booted from
is to first check for
PEBootRamdiskSourceDrive registry key.
If it is not present, scan the drives
of the correct PEBootType and look for
some kind of tag file that identifies
the boot drive.
(The registry value in question sits under HKLM\SYSTEM\CurrentControlSet\Control.)
Here's a non-optimal solution. In this case, the UFD has to have a specific name, which is passed to the script which searches every possible drive letter for a match. It's probably not practical to rely on the flash drives all having the same name.
Still hoping someone pops by with a better answer!
setlocal
:: Initial variables
set TMPFILE=%~dp0getdrive.tmp
set driveletters=abcdefghijklmnopqrstuvwxyz
set MatchLabel_res=
for /L %%g in (2,1,25) do call :MatchLabel %%g %*
if not "%MatchLabel_res%"=="" echo %MatchLabel_res%
goto :END
:: Function to match a label with a drive letter.
::
:: The first parameter is an integer from 1..26 that needs to be
:: converted in a letter. It is easier looping on a number
:: than looping on letters.
::
:: The second parameter is the volume name passed-on to the script
:MatchLabel
:: result already found, just do nothing
:: (necessary because there is no break for for loops)
if not "%MatchLabel_res%"=="" goto :eof
:: get the proper drive letter
call set dl=%%driveletters:~%1,1%%
:: strip-off the " in the volume name to be able to add them again further
set volname=%2
set volname=%volname:"=%
:: get the volume information on that disk
vol %dl%: > "%TMPFILE%" 2>&1
:: Drive/Volume does not exist, just quit
if not "%ERRORLEVEL%"=="0" goto :eof
set found=0
for /F "usebackq tokens=3 delims=:" %%g in (`find /C /I "%volname%" "%TMPFILE%"`) do set found=%%g
:: trick to stip any whitespaces
set /A found=%found% + 0
if not "%found%"=="0" set MatchLabel_res=%dl%:
goto :eof
:END
if exist "%TMPFILE%" del "%TMPFILE%"
endlocal
To elaborate reuben's answer in more detail, here is my batch file:
wpeutil UpdateBootInfo
for /f "usebackq skip=1 tokens=3 delims= " %%l in ( `reg query HKLM\System\CurrentControlSet\Control /v PEBootRAMDiskSourceDrive` ) do set "PendrivePath=%%l"
set "PendriveLetter=%PendrivePath:~0,1%"
echo The boot pendrive's drive letter is %PendriveLetter%