Solved

Vista - DOS Batch file help - Copy files from CDROM

Posted on 2007-11-20
10
3,131 Views
Last Modified: 2012-06-21

I have a batch file that works perfect in XP but not in Vista.  In xp when you run the batch file from the CDROM it knows that you are copying files from the CDROM

In Vista I get file not found so it it not using the directory where I am copying the files from so I guess I need to somehow set the path for it..

Here is the batch file:

echo off
cls

copy DMTechWP.jpg c:\windows
copy choice.exe c:\windows
copy procexp.chm c:\windows
copy px.exe  c:\windows
copy pskill.exe  c:\windows
copy pslist.exe  c:\windows
copy autoruns.exe  c:\windows
copy autoruns.chm  c:\windows
copy pendmoves.exe c:\windows
copy movefile.exe c:\windows
copy uptime.exe c:\windows
copy DMTIcon.ico c:\windows
copy DMTechGroup.url c:\docume~1\%username%\favorites
copy DMT-RemoteSupport.url C:\DOCUME~1\%username%\STARTM~1\Programs
copy regjump.exe c:\windows

ECHO 
ECHO 
ECHO 
echo.
echo.
echo.
    choice /c:yn Change the OEM Logo File?
    if errorlevel 2 goto noedit
    if errorlevel 1 goto Edit

    :Edit
copy oeminfo.ini c:\windows\system32
copy oemlogo.bmp c:\windows\system32
    goto End

    :noedit
    goto End

   :End

echo.
    choice /c:yn Run Tweaks?
    if errorlevel 2 goto noedit
    if errorlevel 1 goto Edit

    :Edit
RunAsDate.exe 10\07\2007 "%cd%\tweaks.exe"


    goto End

    :noedit
    goto End

   :End


ECHO 
ECHO 
ECHO 
echo.
echo.
echo.
    choice /c:yn Apply Host Spyware Block File?
    if errorlevel 2 goto NoHost
    if errorlevel 1 goto Host

    :Host

IF NOT EXIST HOSTS GOTO noHostsFile
IF "%OS%"=="Windows_NT" GOTO HostsFile
IF EXIST %winbootdir%\HOSTS*.* ATTRIB +A -H -R -S %winbootdir%\HOSTS*.*>NUL
IF EXIST %winbootdir%\HOSTS.MVP DEL %winbootdir%\HOSTS.MVP>NUL
IF EXIST %winbootdir%\HOSTS REN %winbootdir%\HOSTS HOSTS.MVP>NUL
IF EXIST %winbootdir%\NUL COPY /Y HOSTS %winbootdir%>NUL
GOTO noHostsFile
:HostsFile
IF EXIST %windir%\SYSTEM32\DRIVERS\ETC\HOSTS*.* ATTRIB +A -H -R -S %windir%\SYSTEM32\DRIVERS\ETC\HOSTS*.*>NUL
IF EXIST %windir%\SYSTEM32\DRIVERS\ETC\HOSTS.MVP DEL %windir%\SYSTEM32\DRIVERS\ETC\HOSTS.MVP>NUL
IF EXIST %windir%\SYSTEM32\DRIVERS\ETC\HOSTS REN %windir%\SYSTEM32\DRIVERS\ETC\HOSTS HOSTS.MVP>NUL
IF EXIST %windir%\SYSTEM32\DRIVERS\ETC\NUL COPY /Y HOSTS %windir%\SYSTEM32\DRIVERS\ETC>NUL
      color 1F
      echo.
      echo  ÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœÃœ
      echo  Ã                                          ÃšÃ„ÄÄ¿Þ
      echo  Ã THE MVPS HOSTS FILE IS NOW UPDATED       ³ û ³Þ
      echo  Ã                                          Ã€Ã„ÄÄÙÞ
      echo. ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
      echo.
      echo.
      echo. Previous version saved and renamed to HOSTS.MVP
:noHostsFile


    goto End

    :NoHost
    goto End

   :End

AAC-CMDPrompt.reg
SafeSites.reg
StartupCPL.exe

pause
0
Comment
Question by:DMTechGrooup
10 Comments
 
LVL 22

Expert Comment

by:cookre
Comment Utility
The first thing I'd do is add:
d:           (or whichever)
cd \

at the top of the bat file - just to make sure it works.

The proper thing, if possible, of course, is to fully qualify the files being copied.
0
 
LVL 24

Author Comment

by:DMTechGrooup
Comment Utility
Problem is on 1 computer it's D and the next computer it's E and so on.
0
 
LVL 51

Expert Comment

by:Netman66
Comment Utility
Try adding this to the top of the batch (after cls):

for /f "tokens=3 delims=\:" %%k in ('reg query hklm\system\mounteddevices^|findstr /C:"5C003F003F005C0049004400450023004300640052006F006D"') do set CDROM=%%k:
CD %CDROM%

0
 
LVL 22

Expert Comment

by:cookre
Comment Utility
I was thinking of a VBScript to query WMI Win32_CDROMDrive Class:
http://msdn2.microsoft.com/en-us/library/aa394081.aspx
0
 
LVL 22

Expert Comment

by:cookre
Comment Utility
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")


For Each objItem in colItems
      objItem.Drive will have, for example, E:
      Next

Since one box may have multiple CD drives, in the for each loop you look for the presence of one of the files to be copied, you use that objItem.Drive
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 51

Expert Comment

by:Netman66
Comment Utility
The entire other script is batch, so unless you want to code it up for him it may be easier to find it in a DOS-form.  I'd prefer VB myself, but that may not always be something easily altered by a non-VB scripter.

0
 
LVL 28

Accepted Solution

by:
Michael Pfister earned 500 total points
Comment Utility
When you run the batch from the cdrom, its easy to make the directoy of the cdrom the current directory:

pushd %0\..

:
your script goes here
:
popd



Make sure you're running this with an administrative account and elevated (or UAC is turned off), otherwise you won't be able to copy files to the system directory.

hope it helps.

0
 
LVL 9

Expert Comment

by:MSE-dwells
Comment Utility
Though not in direct response to the question posted, this might be useful to assist in determining the right drive letter.  

I've written a simple script that can be executed standalone or incorporated into others in order to provide a list of available drive letters and their associated type.  It also accepts a wildcarded argument to constrain which drive types are displayed -

C:\>dumpdrives

#ERROR - administrative process context required

... elevated shell in Vista -

C:\>dumpdrives
C: - Fixed Drive
D: - CD-ROM Drive
E: - CD-ROM Drive
F: - CD-ROM Drive
Z: - Remote/Network Drive

... or -

C:\>dumpdrives net
Z: - Remote/Network Drive

... or -

C:\>dumpdrives cd
D: - CD-ROM Drive
E: - CD-ROM Drive
F: - CD-ROM Drive

... hopefully, someone will find that of use.

PS - the latest versions of scripts such as these can be found here -

ftp://falcon.msetechnology.com/scripts
:: dumpDrives.CMD - Dumps drive letter for local machine

::                - accepts a wilcarded argument constraining the output to the specified drive type
 

:: Dean Wells - MSEtechnology / November 2007 (dwells@somewhere.com)
 

@echo off
 

setlocal
 

if "%*"=="" (

	set commandSUFFIX=find /v "ThIsIsNtGoInGtOeXiSt"

) else (

	set commandSUFFIX=find /i "%*"

)
 

:: Script enumerates assigned drive letters and type [requires administrative privilege]

fsutil fsinfo drives >"%TEMP%\%~n0.$$$" 2>nul

if not errorlevel 1 (

	for /f "tokens=1 delims=\ skip=10" %%d in ('cmd /u /c type "%TEMP%\%~n0.$$$" ^| find /v ""') do (

		if not "%%d"=="" if not "%%d"==":" if not "%%d"==" " (

			for /f "tokens=*" %%s in ('fsutil fsinfo drivetype %%d: ^| %commandSUFFIX%') do (

				echo %%s

			)

		)

	)

) else (

	echo/

	if errorlevel 255 (

		echo #ERROR - unable to execute FSUTIL.EXE

	) else (

		echo #ERROR - administrative process context required

	)

	echo/

)

del "%TEMP%\%~n0.$$$" 2>nul
 

:END

Open in new window

0
 
LVL 29

Expert Comment

by:matrixnz
Comment Utility
Or you could use something simple like

FOR %%X IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%X:\autoruns.exe SET CDDRV=%%X:

copy %CDDRV%\DMTechWP.jpg c:\windows
etc...
0
 
LVL 24

Expert Comment

by:SunBow
Comment Utility
Problem (for me too) is just what is wrong with Vista, I think that should be addressed first to be a lasting solution, I've deferred upgrading so can only try hints.

* open a command window, and look at what is current prompt (such as desire for e:\MyStuff> )

* from there also check the path

* I'd stick to DOS only (else why not code the whole process in VBS?). Simple answer is to copy all the code to each machine, the add either d: or e: at the top, and  to ensure that the correct directory is pointed to (the 'cd' command) as the current one to copy from. This is a ditto to the first comment.

* Making assumption that you are creating the cd and then making copies of its contents (like backup/restore) then the batch file is best placed in the same directory as the backup files. I assume that this is how it used to be, and have to wonder if it still is.

* With assumption that this is a dynamic process, where over time you will change the file contents of which files to copy, or to not copy, then the hardcoding of the drive (above) can be cumbersome. For that it should be fairly simple to have a separate CMD file on each computer that you need edit just the once to do the drive issue, perhaps a one line file called SetDrive.cmd that has either the d: or e: command, then the first line of your program could be like

     Call  c:\Config\SetDrive.cmd

* Remember the issue of human error. Is it really true that everything is being done exactly the same on the Vista machine as it was on the XP? Questioning whether the CMD program is on the hard drive or CD, whether it is run by clicking it or going to a command window and just running it from the default. Possibly you are not doing that part exactly the same way

* If you can make shortcuts and this is a frequent task, then another method is to first make a shortcut icon to run CMD. Then change its properties to have the cd or dvd as the current directory. You should then edit the description accordingly. This will allow easier access to your cd files from the (old dos) prompt. That enables things like running a 'DIR' command to list the files to your printer, and you can keep that listing with the CD to help identify (remember) file contents when offline (when it is on the shelf).

Once the DIR command lists the files, including the batch program(s) then you have the verification of success to add confidence.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now