Jump to content

Batch Script Tips and Tricks for XPCDs


Recommended Posts

Hi all,

i saw your fantasic scripts here !

DarkShadows FindFreeDriveLetter and Yzöwl's code

My question now is:

How can i use this scripts (for my UA-CD) in combination with a diskpart script to assign my drive letters ?

I tryed this utility: mdes Mapdrive

Edit

Mapdrive Automatic drive letter assignement works now !

Mdes fixed it ! here

Im stil interested for a diskpart. drive dedection and letter assignment script

Thank you for your help

Edited by new_user
Link to comment
Share on other sites


Here is a .vbs script that I wrote to allow users to change their User Name, Company, and Computer Name.  [...]

Option Explicit

Set ws = WScript.CreateObject("WScript.Shell")
Dim ws, t, p1, p2, n, g, cn, cg, o, co

p1 = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\"
p2 = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\"

n = ws.RegRead(p1 & "RegisteredOwner")
g = ws.RegRead(p1 & "RegisteredOrganization")
o = ws.RegRead(p2 & "ComputerName")
t = "Change Personal Info & Computer Name"
cn = InputBox("Enter Your Full Name", t, n)
If cn <> "" Then
 ws.RegWrite p1 & "RegisteredOwner", cn
End If

cg = InputBox("Enter Your Company Name", t, g)
If cg <> "" Then
 ws.RegWrite p1 & "RegisteredOrganization", cg
End If

co = InputBox("Enter Computer Name", t, o)
If co <> "" Then
 ws.RegWrite p2 & "ComputerName", co
End If

This is a very nice scipt that I will be using. I was wondering though ( and please forgive my newbness if this is already answered someplace else :blushing: ) is it possible to add a few lines to this to prompt for CD key as well. It would be handy for us who have more than one copy of XP

something like:

k = ws.RegRead(p3 & "CDkey")
ck = InputBox("Enter Your XP CD Key", k)
If ck <> "" Then
 ws.RegWrite p3 & "CDKey", ck
End If

Thanks :thumbup

Edited by one4other
Link to comment
Share on other sites

Here A VBS Script For Checking To See If The XPCD Is In The CDROM

If It Not There Then It List All CDROMS On The Computer.

 

  Dim Work

   Work = Array(CreateObject("Wscript.shell"),CreateObject("Scripting.FileSystemObject"),CreateObject("Scripting.FileSystemObject").Drives)

   For Each strD In Work(2)

  If strD.DriveType = 4 Then

  If Not Work(1).FileExists(StrD & "\WIN51") Then

   Work(0).Popup "This Is The Wrong CD" & vbCrLf & StrD, 3,"CD List", 0 + 32

  Else

   Work(0).Popup "This Is The XPCD" & vbCrLf & StrD & "\WIN51", 3,"CD List", 0 + 32

  Exit For

  End If

  End If

   Next

Edited by gunsmokingman
Link to comment
Share on other sites

  • 2 weeks later...

This is my current runonceex

cmdow @ /HID
@Echo Off

for %%i 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 %%i:\Win51ip.sp2 set CDROM=%%i:

SET XPCD=%CDROM%\Install

SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx

REG ADD %KEY% /V TITLE /D "Installing applications..." /f

REG ADD %KEY%\001 /VE /D "Preparing Installation..." /f
REG ADD %KEY%\001 /V 1 /D "%XPCD%\preclean.cmd" /f

...

I tried to change the CDROM finding using Yzöwl method but I am having no luck, and I'm noob at batch scripting :( Could anyone guide me, please ?

Link to comment
Share on other sites

xtremexxx, are you seeing red?

cmdow @ /HID

@Echo Off

for %%i 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 (

fsutil fsinfo volumeinfo %%i:|find "CDFS">nul 2>&1||goto :eof

)

set CDROM=%%i:

SET XPCD=%CDROM%\Install

SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx

REG ADD %KEY% /V TITLE /D "Installing applications..." /f

REG ADD %KEY%\001 /VE /D "Preparing Installation..." /f

REG ADD %KEY%\001 /V 1 /D "%XPCD%\preclean.cmd" /f

...

Link to comment
Share on other sites

wow.

just read through this thread and i'm sooo confused.

I've always used the classic:

for %%i 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 %%i:\WIN51 set CDROM=%%i:
ECHO Found CD-Rom as drive %CDROM%

to determine my CDROM drive. I used it because I always test out my batch files first from my external USB HDD, which i later compile & burn onto a DVD for installation.

I am trying to figure out the best way to determine the drive. is my method best?

i don't like the method with stuff on top and bottom, and i edit in between.

i like having the file find the cdrom drive in the beg. and then i do what i want afterwards.

what's best for me?

Link to comment
Share on other sites

  • 3 weeks later...

Great info, but i think i'll stick to the

for %%i 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 %%i:\unattend.txt set CDROM=%%i:

methad. This allows me to have an unattended install disk with default progs to be insatlled, but also allows me to check for a second cd in a drive that has more software on it. The second cd can change its contents and all i have to do is to keep the txt file the same.

e.g.

for %%i 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 %%i:\unattend.txt set CDROM=%%i:

.....
.....
for %%j 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 %%j:\software.txt call %%j:\setup.cmd

This means i can use the unattend for more than one PC (dont worry the cd-key is requested, and not embeded in the winnt.sif file), with the second disk containing the software i require for the pc's on the second disk (as you dont always want to install the same software on different pc's)

Link to comment
Share on other sites

@ phkninja

many of the altenative methods mentioned will incorporate your idea, just using a slightly different method.

Taking a WMIC approach for example, I would do it according not to a file on the cd, but the volume name given by me when I created the disk.

@echo off&setlocal enableextensions
for /f "usebackq skip=1" %%a in (
`wmic cdrom where "VolumeName='UAWXPCD'" get drive ^2^>nul`
) do if errorlevel 0 set UACDROM=%%a
for /f "usebackq skip=1" %%b in (
`wmic cdrom where "VolumeName='XTRASOFT'" get drive ^2^>nul`
) do if errorlevel 0 set SOFT_CD=%%b
if defined UACDROM echo/ %%UACDROM%% is set as %UACDROM%
if defined SOFT_CD echo/ %%SOFT_CD%% is set as %SOFT_CD%
endlocal&goto :eof

You would ony need to adjust your VolumeNames to suit 'UAWXPCD' and 'XTRASOFT'

<Edit>

Small error noticed and fixed…

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

Here is a VBS file that check only for CD Or DVD drive

This can be modified to suit your needs. I have left it as

generic as possible.

This checks to see if a disk is in the CD DVD if it is a popup confirms it

If the drive is empty it popup a missing message

Green Text Are Comments And Do Not affect The script

Other things that can be check using this, there is more to this class but the

editor I use is a free version and does not give all it can list.

strDrive.VolumeName

strDrive.FileSystem

strDrive.RootFolder

strDrive.DriveLetter

strDrive.IsReady

strDrive.ShareName

strDrive.DriveType

Dim Act, Fso, Drv, strDrive

Set Act = CreateObject("Wscript.shell")

Set Fso = CreateObject("Scripting.FileSystemObject")

Set Drv = Fso.Drives

  For Each strDrive In Drv

    If strDrive.DriveType = 4 Then '''' CD Or DVD drive

    If strDrive.IsReady = True Then '''' Checks If The Drive Has a Disk In it

      Act.Popup strDrive.VolumeName & vbCrLf & strDrive.DriveLetter & ":\" &_

      vbCrLf & strDrive.IsReady,5,"CD Rom Info",0 + 32

     Else

     Act.Popup "The CD Or DVD Does Not Appear Ready" & vbCrLf &_

     strDrive.DriveLetter & ":\", 5, "Missing CD", 0 + 32

    End If

   End If

  next

Edited by gunsmokingman
Link to comment
Share on other sites

Here is a VBS script that uses WMI to check for the volume name

Edit The Array to Suite Your Needs.

Blue Text Is Where You Add The Volume Name And The Varible Name In The Check

Green Text Are The Checks For The Volume Name

The Varible Name RomVol = objcolRom.VolumeName

Red Text Are The error Controls

Dim RomVol, RomID, RomName, RomDscpt, RomDID, RomMaker, RomMedia '''' VARIBLES FOR SCRIPT

Dim Act, Fso, strComputer, V, ChkRom, Ts

V = vbCrLf

Set Act = CreateObject("Wscript.shell")

Set Fso = CreateObject("Scripting.FileSystemObject")

strComputer = "."

ChkRom = Array ("EDXPSP2","WINPE3IN1_PRV","XPSP2.ISO")'''' Array For Volume Names

Function Mbox()

   Act.Popup "Volume : " & RomVol & V & "Drive Letter : " & RomID & "\" &_

   V & "Name : " & RomName & V & "Description : " & RomDscpt &_

   V & "Device ID : " & RomID & V & "Manufacture : " & RomMaker, 10, "Media Information", 0 + 32   

End Function

Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colRom = objWMI.ExecQuery("Select * from Win32_CDROMDrive")

'''' RUNS THE CHECKS FOR CD

For Each objcolRom in colRom

RomMedia = objcolRom.MediaLoaded

RomID = objcolRom.ID

If RomMedia = True Then

RomVol = objcolRom.VolumeName

RomName = objcolRom.Name

RomDscpt = objcolRom.Description

RomDID = objcolRom.DeviceID

RomMaker = objcolRom.Manufacturer

'''' CHECK THE CHKROM ARAAY

  If RomVol = ChkRom(0) Then Mbox() End If

  If RomVol = ChkRom(1) Then Mbox() End If

  If RomVol = ChkRom(2) Then Mbox() Else Act.Popup "This Is Not The Correct Volume Name" &_

   vbCrLf & "In This Drive, " & RomID & "\", 5, "Wrong Cd", 0 + 32 End If

  Else

  If RomMedia = False Then

  Act.Popup "No Cd In The Drive" & V & RomID & "\", 5,"No Disk"

Exit For

End If

End If

   Next

More Information, MSDN

Edited by gunsmokingman
Link to comment
Share on other sites

wow.

just read through this thread and i'm sooo confused.

I've always used the classic:

for %%i 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 %%i:\WIN51 set CDROM=%%i:
ECHO Found CD-Rom as drive %CDROM%

to determine my CDROM drive.  I used it because I always test out my batch files first from my external USB HDD, which i later compile & burn onto a DVD for installation.

I am trying to figure out the best way to determine the drive.  is my method best?

i don't like the method with stuff on top and bottom, and i edit in between.

i like having the file find the cdrom drive in the beg. and then i do what i want afterwards.

what's best for me?

What is best for you is what works for you. There are usually no less than 3 ways to accomplish anything. It's just that each way has its own advantages and disadvantages.

As to having issues with code at top and bottom, that is just a well-structured coding best practice. The code at the bottom is a function that is called within your code (at the top). You still set the drive at the top and your code follows. But the called function is located below your code. In fact, this structure will actually make reading your own code easier, because the function doesn't get in the way. The templates many have provided here, just help clarify what goes where. You could always stick the function up top in-line with your code.

What works for me is code that allows me to stick in a UA XPCD in and go work on something else while the PC installs itself. And in this, I still vote Set CDROM=%~d0. All other techniques will create system dialogs if one has more than one CD/DVD drive in the PC. The For-In-Do loop checks, always check every letter from C-Z, looking for something. It doesn't matter what they are looking for, it is the very fact that they check every drive (including my second empty CD drive) that causes a problem. The empty CD drives generate errors when the Windows shell tries to check them for a file, or a label or whatever, and this error puts a dialog up on the screen and halts the installation. In my opinion this behavior just chopped the "Unattended " off of "Unattended Installation."

To counter this I use Set CDROM=%~d0 as my first command.

Since I've received questions on this offline, I've created a script people can plug-in and use that solves all ambiguity as to how this technique should be employed.

It is tested on Windows XP, and should work well on Windows 2000. If someone could test it and report back to everyone, that would be helpful. I do not own a Windows 2000 license.

Download the .zip file, extract it, open the .cmd and read it. It should explain everything in sufficient detail. Post any questions to this thread.

MakeMapCD.zip

Edited by DarkShadows
Link to comment
Share on other sites

I'm not sure I like the idea of creating an additional directory.

I would probably change it to something like this

@echo off&setlocal enableextensions
set MapCD=%SystemDrive%\_MapCD.cmd
>%MapCD% echo/@echo off
>>%MapCD% echo/set CDROM=%~d0
>>%MapCD% echo/goto :eof
call %MapCD%
if defined CDROM echo/%%CDROM%% is set as %CDROM%
ping -n 4 127.0.0.1>nul&&endlocal&goto :eof

Is it your intention to call the cmd file at the start of any subsequent batch which may require the CD-ROM location?

Link to comment
Share on other sites

@Yzöwl

I'm not sure I like the idea of creating an additional directory.
The OEMSetup folder is a part of my larger OEMSetup process. I create this folder regardless, I direct all installation logs there. I set my %Temp% folders (for my OEMSetup Process, not Windows) to a subfolder inside of there. And I stage anything there that I may want to install from the hard drive, rather than directly from CD. I build PCs for customers, and I'm engineering the Unattended Installation for a system recovery CD. So I don't want files written to the root of %SystemDrive% in case something goes wrong, the customer cancels, they lose power, etc. I stick a readme.txt file in there instructing the customer what it is for, and that they can generally delete it freely with no consequence. (Unless they experience errors, in which case I want the log files!) OEMSetup was already in my process to keep things together in one folder.

Folks here at MSFN who download MakeMapCD.zip can simply change one line in MakeMapCD.cmd to write MapCD.cmd to the Root of the system drive (or to any folder, or path on it they wish). I've already documented this in MakeMapCD.cmd.

Change:

Set MapCDPath=%SystemDrive%\OEMSetup

to:

Set MapCDPath=%SystemDrive%\Your\Path

which could simply be

Set MapCDPath=%SystemDrive%

That's easy enough to do and well within the license I have provided.

I would probably change it to something like this
@echo off&setlocal enableextensions
set MapCD=%SystemDrive%\_MapCD.cmd
>%MapCD% echo/@echo off
>>%MapCD% echo/set CDROM=%~d0
>>%MapCD% echo/goto :eof
call %MapCD%
if defined CDROM echo/%%CDROM%% is set as %CDROM%
ping -n 4 127.0.0.1>nul&&endlocal&goto :eof

This script above you have posted might not work so well. Let me explain why I have the script I have:

A portion of MakeMapCD must run inside of Setlocal enableextensions, and another portion must execute outside of it. This design is quite intentional. The reasons are:

1. I want MapCDPath set globally during my CmdLines.txt execution (remember I write files there)

2. MakeMapCD must create MapCD using command extensions, which (I believe) might be disabled by default in Windows 2000 (I didn't know, so I coded defensively). I know extensions are enabled by default in Windows XP, but from your first post in this thread it sounded like they may be disabled by default in 2000. Anyway command extensions are required to facilitate the %~d0 syntax, which MakeMapCD.cmd uses to obtain the CD/DVD drive letter. However, when this script ends or an Endlocal executes (whichever occurs first), command extensions should revert back to being disabled in Windows 2000 (if my assumption is correct). I had two variables that I want set globally, but I need a Setlocal in the middle of them to actually grab the CD/DVD drive letter. This is why Setlocal and Endlocal are where they are in MakeMapCD.cmd

Chronologically:

1. Windows 2000 Command extensions disabled (again my defensive assumption)

2. MakeMapCD starts:

3. Set MapCDPath (Set globally for use in my other scripts)

4. Setlocal enableextensions (allows %~d0, but variables set after are local)

5. Create MapCD.cmd (now contains actual CD drive letter value, not a variable)

6. Endlocal (turns off local variables)

7. Call MapCD (sets %CDROM% Globally for other CmdLines.txt scripts)

However, I still recommend start any script requiring %CDROM% with:

Call %SystemDrive%\<your path if any>\MapCD.cmd

Is it your intention to call the cmd file at the start of any subsequent batch which may require the CD-ROM location?
Exactly correct. The reason why is documented under the section Other things to keep in mind at this link:

MSFN's Unattended XP CD - Adv Methods - Running RunOnceEx from CD

This is why I didn't assign a %MapCD% command, as your suggested script above does. (Normally I personally love to assign variable commands!) According to the MSFN guide, different stages of the Windows Setup process might not always keep Environmental Variables that we set from one stage of Windows Setup might not survive to the next (at least they won't survive a reboot). So %CDROM% and %MapCD% might not survive from CmdLines.txt going forward. So I want people who use this to have the habit of including it in their scripts (again a defensive coding posture). It won't hurt to call MapCD.cmd 200 times, but the one time you don't call might ruin your day.

This is why I write the MapCD file to %SystemDrive%. Writing MapCD.cmd captures the actual CD/DVD drive letter, not the string "%~d0". That will survive a reboot or a media change, and can be run from any stage, up to any point where you re-letter your drives. But at that time, since you are re-lettering, you should know the new CD-Drive letter. By contrast, Set CDROM=%~d0 can only be run from the CD/DVD ROM.

I didn't worry about adding @Echo Off to MapCD.cmd because, as you have inquired about, MapCD.cmd is intended to be called from within each of your own command scripts, which usually have @Echo Off in them. I'm essentially providing a command to assign the %CDROM% variable. However, this is really simple to add, and makes a lot of sense (again for coding defensively), so I have updated the script with this change and already reposted MakeMapCD.zip.

I don't feel it is necessary to put messages on the screen inside of MapCD.cmd. You are executing MakeMapCD.cmd from the CD/DVD ROM--the drive is there, and the Windows shell will give you the letter reliably. Personally, I don't need to know what the CD/DVD drive letter is, in fact my screens are hidden from view anyway. I only need to know that MapCD.cmd will reliably set %CDROM% whenever I require it.

If you want, you could always add If Defined Echo Message to your own script that you are calling MapCD.cmd from. As licensed and intended, nothing else is supposed to go inside of MakeMapCD, or MapCD. thus, a Goto :EOF isn't required--you are already at the end of file. MakeMapCD.cmd was not intended to be a piece of code to inject into your script, rather it is a free-standing script to be called from within CmdLines.txt. Some people will do nothing else with CmdLines.txt. MapCD.cmd can be called from any script and must be written to the hard drive, since we cannot write to CD-ROM during Windows Setup.

Edited by DarkShadows
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...