Search code examples
stringvbscriptcase-sensitive

Force a string to uppercase


I have a script where I need the inputted text to be sent uppercase. Right now I've figured out how to make it appear uppercase when typed but it doesn't send that way. Also keep in mind the cursor is set all the way left of some text and can't jump to the right after first keystroke.

The last part of the code is the specific input box. Thanks for any help in advance!

<html>
<head>
<title>Sysprep Deployment</title>
<HTA:APPLICATION 
     ID="objCompDeploy" 
     APPLICATIONNAME="Sysprep Deployment"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     maximizeButton="no"
     minimizeButton="no"
     sysMenu="yes"
>
</head>
<SCRIPT LANGUAGE="VBScript">

Set WshShell = CreateObject("Wscript.Shell")

Sub Window_onLoad
window.resizeTo 400,200
ComputerNameArea.Focus
  CreateObject("WScript.Shell").SendKeys "^{Home}"

'turn off setup flag in registry so we can query wmi
WshShell.RegWrite "HKLM\SYSTEM\Setup\SystemSetupInProgress", 0, "REG_DWORD"

'query wmi for serial number
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strComputer = "."
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      serialNumber = objItem.SerialNumber
   Next

'turn setup flag back on
WshShell.RegWrite "HKLM\SYSTEM\Setup\SystemSetupInProgress", 1, "REG_DWORD"

'put the serial number that was retrieved in the textbox
ComputerNameArea.Value = serialNumber

End Sub 

Sub modUnattend

run_button.Disabled = True

Set fso = CreateObject("Scripting.FileSystemObject")

base = Wshshell.ExpandEnvironmentStrings("%SystemRoot%")
unattendFile = base & "\Panther\unattend.xml"

   computerName = ComputerNameArea.Value

 Set xmlDoc = CreateObject("Microsoft.XMLDOM")
 xmlDoc.load unattendFile

 'Iterate through Unattend.xml searching for nodes and properties to replace
 Set oNodes = xmlDoc.documentElement.selectNodes("/unattend/settings/component/ComputerName")
 For each n in oNodes
  n.text = computerName
  xmlDoc.save unattendFile
 Next


'launch the continuation of setup in a hidden window and wait for return
'if we dont wait, closing mshta, closes windeploy.exe
WshShell.Run "%WINDIR%\System32\oobe\windeploy.exe", 0, True
idTimer = window.setTimeout("closeHTA", 5000, "VBScript")
End Sub

Sub closeHTA
window.close
End Sub

Sub commandLine
WshShell.Run "%WINDIR%\System32\cmd.exe", 1, True
End Sub

</SCRIPT>
<body>
<table border="0">
<tr>
<td>Computer Name:</td>
<td><input type="text" name="ComputerNameArea" size="30" maxlength="15" value="computer" style="text-transform:uppercase"></td>
</tr>
<tr>
<td>Press Enter to Continue</td>
</tr>
</table> 
<p align="right">
<input id=runbutton  class="button" type="Submit" value="            Sysprep Deployment             " name="run_button" onClick="modUnattend">
</body>`

Solution

  • If in doubt, read the documentation

    Returns a string that has been converted to uppercase.


    So, just change this line

    computerName = ComputerNameArea.Value
    

    to

    computerName = UCase(ComputerNameArea.Value)