Jump to content

RunOnceEx from CD tip


Recommended Posts

Hi! I read through articles at msfn.org (btw GREAT work).

I am working as deployment consultant and I think I could help/improve few things... For example RunOnceEx from CD - U dont need to search cd.txt, U can use WMI (WMIC) to find the cd drive... For example this "script" will make the job:

wmic cdrom where "VolumeName='0006'" get drive /value > temp.txt

FOR /F "usebackq tokens=2 delims==" %i IN (`type temp.txt`) DO echo %i > temp.txt

set /p test1= < temp.txt

Link to comment
Share on other sites


OK, I found further reading about WMI HERE, but I'm not a programmer. Can you provide a real-life example of how this script would be implemented to initialize RunOnceEX from CD? Real tutorial-type leg bone connected to the hip bone stuff for dumb-dumb heads. :w00t:

Link to comment
Share on other sites

Wmic is EXTREMELY powerfull command-line utility, that provides access to WMI classes without knowing about programming. I made presentation about it for Microsoft few weeks ago :)

So this is script to find the letter of cddrive, where boot cd is inside...

wmic cdrom where "VolumeName='XPSP2'" get drive /value > cddrive.txt

this command will find the cdrom drive, where is media named XPSP2. Then it will same the drive letter to file cddrive.txt (it will looks like Drive=D:)

FOR /F "usebackq tokens=2 delims==" %i IN (`type cddrive.txt`) DO echo %i > drive.txt

This line will open the file, pick up X: part and save it to same file again.

set /p cddrive= < cddrive.txt

this last drive will input the cddrive letter do variable cddrive...

Link to comment
Share on other sites

I preffer MHz method. It works great in Win2K, WinXP and the code is reusable with all my versions since I am looking for CD.bin which is present on all of my CD.

The method you suggested is checking for the CD label which is different on every CD.

I like it when my Unattended OS are updated the same way. One less thing to worry about. I can copy/paste my code from one another without having to care about fancy details

Link to comment
Share on other sites

  • 5 months later...

Hello,

Yesterday I've found a new way to determine the cdrom drive letter during installation. It's quite simple and less typing. Replace in the RunOnceEx.cmd (or any other batchfile) the following:

for %%a in (C 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 %%a:\WIN51 set CDROM=%%a:

with

set CDROM=%~d0

Now a little explanation for "%~d0"

%0 (zero) is a variable which contains the filename being executed. With the "~ + a letter" you can retrieve several details about the executed file and ~d will retrieve the drive letter. Since RunOnceEx.cmd in on the CD, it returns your cdrom driveletter (assigned during installation).

Here is a little batchfile to show you what you can do with it:

@echo off
echo This script will show several (hopefully) interresting things of the
echo variable %%0
echo.
echo Command executed         (%%0)  : %0
echo Directories              (%%~p0): %~p0
echo Drive                    (%%~d0): %~d0
echo Filename (no ext.)       (%%~n0): %~n0
echo Extension                (%%~x0): %~x0
echo Full path + filename     (%%~f0): %~f0
echo Modification time (file) (%%~t0): %~t0
echo Filesize                 (%%~t0): %~t0
pause

Put this in a batchfile and execute it. copy/move it to another directory (and/or drive) to see how it's effect. rename it and execute it again. This method cannot determine you cdrom driveletter when the batchfile is not stored on you CD. More info can be found in the help of the FOR command (for /?)

It works on Win XP (Pro). I don't know about other OS'es.

I hope you can do something with it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...