Hi all!
I’m setting up MDT and am trying to create a task sequence will run an interactive bat file.
The reason is that, for Lenovo, there is a command line utility that we must run to set the asset tag. I’d like to have a command prompt pop up asking for the computer name and would then the script would run the utility to set it.
I can work out the script on my own if I can get the MDT task sequence to run the bat file; but I haven’t been able to figure it out. Each time the deploy fails with this error:
Litetouch deployment failed, Return Code = -2147467259 0x80004005
I’ve found some info on using serviceui.exe to do this but still no luck.
Any help would be appreciated!
3 Spice ups
beta
(beta)
November 11, 2016, 4:24pm
2
Clarifying exactly what you need here: are you just trying to set the asset tag to the computer name? I’m just thinking you wouldn’t need to make things interactive if that’s the case.
Either way, what about writing a VBscript that gets the info you want to use for you asset tag and then call the Lenovo utility from the VBscript?
Yes we set the computer name to the asset tag automatically in MDT. This is just for when the asset tag is blank.
Do you have any example of a vbscript that would prompt for input?
jagowu
(Jago Wu)
November 14, 2016, 11:44am
4
In the deployment share you should see a $OEM$ folder. Place your script and batch file there.
On the TS Add a new command line with this code.
cmd /c “%SCRIPTROOT%$OEM$\mybatchfile.bat”
Also in order to make your .bat file reference the script (while the script is in the same folder as the .bat file) then you should use the following code in this example.
@ECHO ON
“%~dp0myscript.vbs”
I can get it working if I include my scripts in the boot image and reference them there.My Task Sequence only has 1 step, which is a “Run Command Line” step that runs x:\SetAssetTag.vbs. That works.
However I haven’t been able to get the variables to work like %SCRIPTROOT% or %DEPLOYROOT%.
jagowu
(Jago Wu)
November 16, 2016, 2:54pm
6
Can you give me an example of the full path you are attempting?
I’m not exactly sure what I was dong wrong, but I must have had the syntax wrong.
I was able to get this working with this command. It uses ServiceUI to launch the batch file in the current session so you can interact with it. The “Installation Progress” window is still on top, but it isn’t very tall so it’s not a problem
%ToolRoot%\ServiceUI.exe %windir%\system32\cmd.exe /c %SCRIPTROOT%\Lenovo_settag.bat
My bat file looks like this. The WINAIA64.exe Lenovo utility needs to be in the Scripts directory of your Deployment Share.
@ECHO OFF
ECHO Asset Tag has not been set
ECHO.
SET /P AssetTag=Enter Asset Tag:
REM Set Asset Tag
ECHO.
ECHO Set Asset Tag to "%AssetTag%"
%SCRIPTROOT%\WINAIA64.exe -silent -set "USERASSETDATA.ASSET_NUMBER=%AssetTag%"
GOTO:eof
One more question, how do I get this step to run only when the vendor is Lenovo?
A few years ago, I did something very similar with MDT, except we mostly use Dell here. Since we use the asset tag as part of the name of the computer, I built a custom TS Wizard screen to both generate the computer name and set the Asset tag. It also sets several other BIOS settings like WoL and BIOS password. If the Asset Tag is already set in the BIOS, the field get pre-populated. The first part of the computer name gets sets based on location.
If you only want the script to run on Lenovo computers you could set something at the start of your script to check for Vendor info. Something like this:
@echo off
for /F %%a in ('wmic csproduct get vendor /value^|find /i "Vendor"') do set "%%~a"
ECHO %Vendor%
IF "%Vendor%"=="Lenovo" GOTO:eof
paulhaen
(paulhaen)
April 25, 2017, 5:30am
10
Hi,
Is this custom TS Wizard something you would like to share? It looks like something we can use.
I can try to get something together as soon as I get a chance.
Below is the code for the custom Task Wizard screen.
<!--
' // ***************************************************************************
' //
' // Microsoft Deployment Toolkit Solution Accelerator
' //
' // File: DeployWiz_GenerateComputerName.xml
' //
' // Purpose: Custom form for computer names. This is to be used with MDT 2013
' //
' // ***************************************************************************
-->
<Wizard>
<Global>
<CustomScript>DeployWiz_GenerateComputerName.vbs</CustomScript>
</Global>
<Pane id="GenerateComputerName" title="GenerateComputerName">
<Body><![CDATA[
<H1>Room Number or Location</H1>
<H2>Enter the room number this computer is located. </H2>
<table style="width: 100%;">
<tr>
<td style="width: 180px;"><span class=Larger><u class=Larger>R</u>oom Number:</span></td>
<td align="left">
<input type=text id="RoomNumber" name=RoomNumber size="5" maxlength="5" language=vbscript onpropertychange=ValidateRoomNumber AccessKey=r />
<label class=ErrMsg for=RoomNumber>* Required</label>
<label class=ErrMsg id=InvalidChar>Invalid characters! Make sure it is all caps.</label>
<label class=ErrMsg id=BadLength>Maximum of 5 characters!</label>
</td>
</tr>
</table>
<br>
<H1>Asset Tag</H1>
<H2>Enter the asset tag number. </H2>
<table style="width: 100%;">
<tr>
<td style="width: 180px;"><span class=Larger>Asset <u class=Larger>T</u>ag:</span></td>
<td align="left">
<input type=text id="AssetTag" name=AssetTag size="6" maxlength="6" language=vbscript onpropertychange=ValidateAssetTag AccessKey=t />
<label class=ErrMsg for=AssetTag>* Required</label>
<label class=ErrMsg id=OvInvalidChar>Invalid characters! Tag should be numbers only.</label>
<label class=ErrMsg id=OvBadLength>Maximum of 6 characters!</label>
</td>
</tr>
</table>
<br>
<table style="width: 100%;">
<tr>
<td style="width: 180px;"><span class=Larger>AD Computer <u class=larger>d</u>escription:</span></td>
<td align="left">
<input type=text id="Description" name=ComputerDescription size=40 language=vbscript AccessKey=d />
</td>
</tr>
</table>
<br>
<table style="width: 100%;">
<tr>
<td align="left"><span class=Larger>Generated Computer Name:</span><br>
<input type=text id="SBComputerName" name=SBComputerName size=15 disabled=true />
</td>
</tr>
</table>
]]></Body>
<Validation><![CDATA[ValidateRoomNumber]]></Validation>
<Validation><![CDATA[ValidateAssetTag]]></Validation>
<Condition><![CDATA[Property("DeploymentType")<>"REPLACE" and Property("DeploymentType")<>"CUSTOM" and Property("DeploymentType") <> "StateRestore" ]]></Condition>
<Condition><![CDATA[Instr(1, oEnvironment.Item("ImageFlags"), "SERVER", 1) = 0 ]]></Condition>
<Initialization><![CDATA[InitializeGenName]]></Initialization>
<Condition><![CDATA[UCase(Property("SkipGenName"))<>"YES"]]></Condition>
</Pane>
</Wizard>
Here is the code for the VBS script to make it work.
' // ***************************************************************************
' //
' // Microsoft Deployment Toolkit Solution Accelerator
' //
' // File: DeployWiz_GenerateComputerName.vbs
' //
' // Purpose: Custom form for computer names. This is to be used with MDT 2013
' //
' // ***************************************************************************
Option Explicit
Function InitializeGenName
If UCase(oEnvironment.Item("SkipGenName")) = "YES" then
RoomNumber.disabled = true
AssetTag.disabled = true
ValidateRoomNumber = true
ValidateAssetTag = true
End if
End Function
Function ValidateRoomNumber
' Check Warnings
ParseAllWarningLabels
If Len(RoomNumber.value) > 5 then
InvalidChar.style.display = "none"
BadLength.style.display = "inline"
ValidateRoomNumber = false
ButtonNext.disabled = true
ElseIf IsValidRoomNumber ( RoomNumber.Value ) then
ValidateRoomNumber = TRUE
InvalidChar.style.display = "none"
BadLength.style.display = "none"
generateComputerName()
Else
InvalidChar.style.display = "inline"
BadLength.style.display = "none"
ValidateRoomNumber = false
ButtonNext.disabled = true
End if
End function
Function IsValidRoomNumber( RoomNumber )
Dim regEx
Set regEx = New RegExp
regEx.Pattern = "[^A-Z0-9]" 'Strict Subset
' regEx.Pattern = "[^a-zA-Z0-9\!\@\#\$\%\^\&\'\)\(\.\-\_\{\}\~ ]" ' SetComputerName compliant
IsValidRoomNumber = not regEx.Test ( RoomNumber ) and len(RoomNumber) <= 5
End function
Function ValidateAssetTag
' Check Warnings
ParseAllWarningLabels
If Len(AssetTag.value) > 6 then
OvInvalidChar.style.display = "none"
OvBadLength.style.display = "inline"
ValidateAssetTag = false
ButtonNext.disabled = true
ElseIf IsValidAssetTag ( AssetTag.Value ) then
ValidateAssetTag = TRUE
OvInvalidChar.style.display = "none"
OvBadLength.style.display = "none"
generateComputerName()
Else
OvInvalidChar.style.display = "inline"
OvBadLength.style.display = "none"
ValidateAssetTag = false
ButtonNext.disabled = true
End if
If window.event.srcElement is ButtonNext or window.event.KeyCode = 13 then
If Msgbox("Please verify the Asset Tag is: " & AssetTag.Value, 4, "Asset Tag Correct?") = vbYES Then
'If the computer make is not a Dell then skip/exit
If Instr(1, oEnvironment.Item("Make"), "Dell", 1) = 0 Then
Exit Function
'If the asset tag matches then set other settings
ElseIf AssetTag.Value = oEnvironment.Item("AssetTag") Then
RunCommand "cctk.exe -i Settings.ini", 1, true
Exit Function
'If the asset tag doesn't match then set all settings
Else
RunCommand "cctk.exe -i Settings.ini", 1, true
RunCommand "cctk.exe --asset="& AssetTag.Value, 1, true
Exit Function
End If
End If
End If
End function
' Limits the Asset tag field to only numbers
Function IsValidAssetTag(AssetTag)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = "[^0-9]" 'Strict Subset
IsValidAssetTag = not regEx.Test ( AssetTag ) and len(AssetTag) <= 6
End function
' Function that generates the computer name based on user input and sets it to the OSDComputerName variable
Function generateComputerName
oEnvironment.Item("OSDComputerName") = oEnvironment.Item("SiteName") & "-" & RoomNumber.Value & "-" & AssetTag.Value
SBComputerName.Value = oEnvironment.Item("SiteName") & "-" & RoomNumber.Value & "-" & AssetTag.Value
End Function
' Function to run command as if running from command line
Function RunCommand ( sCmd, iWindowStyle, bWaitOnReturn )
oLogging.CreateEntry "About to run command: " & sCmd, LogTypeInfo
RunCommand = oShell.Run ( sCmd, iWindowStyle, bWaitOnReturn )
oLogging.CreateEntry "Command has returned: " & RunCommand, LogTypeInfo
End Function
Finally, here are a couple of links about creating your own Wizard.
Using the Wizard Editor is fairly self explanatory for adding simple wizard panes. In 90%+ deployment scenarios, a simple wizard pane including a couple of radio buttons suffice. Here is a simple "Department Name" Wizard Pane, which include 2 radio...
If you have any other questions, feel free to ask.
paulhaen
(paulhaen)
May 5, 2017, 12:17pm
14
Thanks a lot Jonathan for sharing this.
I will look in to it and see how far I get.