K2000 - How to preserve output from pre-install prompting script that I wrote, to be used later by post-install tasks
Hello,
I’m still fairly new to scripting and I’ve been trying to figure out a problem that I’m hoping maybe someone can help me with.
What I’m trying to do:
THE GIST: I wanted a pre-installation task that runs right after the “get/set computer name.exe” task from KACE and prompts the user to a few questions and then stores the answers to be used later on during the post-install phase. This way certain post-installation software installs can use those answers to see if they should install that program or not. I wanted it to run right at the beginning of the entire scripted installation process so the tech can set computer name and also these install details right away and then come back later with everything done. We have some computers like checkouts that aren’t on the domain so that’s why I want the post-install tasks themselves to decide whether they run or not (not depending on any domain or server input).
The problem is really just one detail: How do I keep safe the little bat file I’m outputting from my vbs script at the pre-installation stage and put it somewhere on the structured C drive (after Windows has installed) so that I can call my information that I want from it?
I’ve tried putting the file in the X:\Applications\ and the Y:\preinstall locations that I thought were created to store pre-install task data. I tried including a folder with a blank copy of the outputted bat file (to be overwritten by my script) with my KBE, using the KBE manipulator. Clearly this aspect is beyond me as I’m grasping at straws. But I think it’d be really cool to know how to do this and make this idea work.
The Process I’m trying to build:
1. [THIS PART WORKS WELL] A pre-installation task runs before I run the disk prep tasks. I’m using a vbs script based on what I’ve gotten from the “old get/set computer name” script from KACE. It prompts the user/tech with a few questions:
a. “Is this a shared desktop?”
b. “What work area is this used in?”
c. “Is this a checkout laptop?”
d. ** The one-word answers obtained from the user are output to a bat file as variables to be called later (this works if I did it on a computer that already has a Windows file structure and I just put it in C:\temp or anywhere else).
2. [THIS PART FAILS] I need the bat file stored in a temporary location because as a pre-install task, there is no Windows file structure. When Windows has installed and created a file structure, then I need to move my little info file to the C drive to be used by post-install tasks.
Here are the scripts showing the last way I tried to do this. I’d like to see what kind of constructive advice I get on how to make this work or do something better. I’ll probably get people who want to tell me to get a K1000, and we may get the money for that down the road, but I have no idea how long from now that may be. So, this is supposed to be a poor man’s, simpler substitute for right now.
VBS SCRIPT THAT PROMPTS FOR USER/TECH INSTALL DETAILS (PRE-INSTALL TASK, ENVISIONED LIKE “GET COMPUTER NAME.EXE”)
'This script displays an input box to gather a few details about a computer system 'being installed, such as the physical work location and the status of being shared 'or not. The user input for these questions is put into a text file stored in the 'KACE application directory, which is purged at the end of the KACE scripted install process. Option Explicit '---------- FIND DRIVES ---------- DIM diskDrives Set fso = CreateObject("Scripting.FileSystemObject") Set diskDrives = fso.Drives '---------- OBTAIN THE NEEDED PREINSTALL INFORMATION WITH POP-UP PROMPTS ----------- 'ASK THE NECESSARY QUESTIONS DIM value, fso, NewsFile, strSHARED, strPHYSLOC, strCHECKOUT 'Set wshShell = WScript.CreateObject( "WScript.Shell" ) MsgBox("Hello and welcome to the joy of loading a computer. Please answer the next few questions that appear. Thank you.") strSHARED = inputbox("Is this a shared desktop? (y/n)") strPHYSLOC = inputbox("Physical work group/location:") strCHECKOUT = inputbox("Is this a checkout laptop? (y/n)") MsgBox("That helped a lot. Beginning computer reload process...") '---------- MAP X DRIVE AND CREATE DIRECTORY ---------- Dim objFSO, objFSOText, objFolder, objFile Dim strDirectory, strFile strDirectory = "X:\Applications\LCSO" strFile = "\LCSOPreinstallInfo.bat" '---------- Create file system object ------------- Set objFSO = CreateObject("Scripting.FileSystemObject") '--- Check, then create File System Object if not there ---- '--- Check that the strDirectory folder exists ------------- If objFSO.FolderExists(strDirectory) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFolder = objFSO.CreateFolder(strDirectory) End If '-------- Create the file specified by strFile ---------- If fso.DriveExists("X:") then Set NewsFile = fso.CreateTextFile(strDirectory & strFile, True) Else usbDrive = fso.GetDriveName(wscript.ScriptFullName) Set NewsFile = fso.CreateTextFile(usbDrive & "\KACE" & strFile, True) End If '---------- OUTPUT THE PREINSTALL INFORMATION ----------- NewsFile.WriteLine "@ECHO OFF" NewsFile.WriteLine ":: [LCSOPreinstallInfo]" NewsFile.WriteLine ":: THIS FILE CONTAINS VARIABLES FROM THE PREINSTALL TASK REQUESTING KACE INSTALL INFO" NewsFile.WriteLine "" NewsFile.WriteLine "SET SHARED=" & strSHARED NewsFile.WriteLine "SET PHYSLOC=" & strPHYSLOC NewsFile.WriteLine "SET CHECKOUT=" & strCHECKOUT NewsFile.WriteLine "END" NewsFile.Close
THIS NEXT VBS SCRIPT IS MEANT TO TAKE THE BAT FILE OUTPUTTED FROM THE SCRIPT ABOVE AND MOVE TO SET LOCATION ON C: DRIVE AFTER WINDOWS INSTALL (MID-LEVEL TASK, ENVISIONED LIKE “SET COMPUTER NAME.EXE”)
'PUT THE PREINSTALL INFORMATION FROM THE INITIAL TASK INTO A POST INSTALL DIRECTORY
'SO THAT POSTINSTALL TASKS CAN REFERENCE THE VARIABLES
'OBTAINED.
Set fso =
CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")
'COPY PREINSTALL BAT FILE FROM INSIDE X: MADE BY PREINSTALL
'TASK
If fso.DriveExists("X:") then
LCSOPreinstallInfoFilePath = "X:\Applications\Agency\PreinstallInfo.bat"
Else
usbDrive = fso.GetDriveName(wscript.ScriptFullName)
LCSOPreinstallInfoFilePath = usbDrive & "\KACE\PreinstallInfo.bat"
End If
If fso.FileExists(LCSOPreinstallInfoFilePath) Then
fso.CopyFile LCSOPreinstallInfoFilePath,"C:\CS
Temp\",True
End IF
'Delete file
fso.DeleteFile PreinstallInfoFilePath
Running these scripts results in the error message below. It comes up after I've completed the question prompts and when the script is trying to save the output file to the X drive, which it doesn't seem to be recognizing (I think).
Windows Script Host
Script: Y:\preinstall\43\KACEPreinstall-InputBox.vbs
Line: 38
Char: 1
Error: Path not found
Code: 800A004C
Source: Microsoft VBScript runtime error
Thank you.
-
I forgot to specify that this is for the k2000. - supergreens 8 years ago
-
Posts are editable, you know :-) - anonymous_9363 8 years ago
-
Thanks. It was my first post after joining and locked until approved, but I could still comment. I edited it now though! - supergreens 8 years ago
Answers (1)
also an FYI
The Techs at Kace are working on a task selector process that you can add in to your deployments to allow you do just what you are trying to accomplish.
Contact Corey to see if you can help test this for them.
his email is under his profile http://www.itninja.com/user/cserrins
Comments:
-
Thanks SMal.tmcc. I am trying to use the X drive, it's in the scripts above. But I keep getting the error (which I've now attached to the original post):
"Windows Script Host
Script: Y:\preinstall\43\KACEPreinstall-InputBox.vbs
Line: 27
Char: 1
Error: Path not found
Code: 800A004C
Source: Microsoft VBScript runtime error"
my mistake for not including that at first. I will see about contacting Corey too, thank you very much for that. - supergreens 8 years ago-
Does this sub dir already exist? X:\Applications\Agency.
You need to create a directory in vb prior to trying to write a file to the location. I think you are currently trying to write a file to non existent location. see this as an example http://www.computerperformance.co.uk/vbscript/vbscript_file_create.htm
For the mid level you can get by with a xcopy batch from x: to c: do not need vb do move the file - SMal.tmcc 8 years ago-
I think so. I had tried including a folder named Agency along with my KBE iso, using the KBE manipulator because the manipulator said it would put the folder I selected into X:\Applications. In a previous attempt, I had tried to create the directory in the script but had the same result as this KBE Manipulator method.
I had only used vb as my mid-level because of the part of the pre-install script that addresses use of a USB drive being used, so I was trying to stay consistent. Those were ideas I leveraged from the "get/set computername.vbs" script I saw on forums. But I'm not opposed at all to something simpler like xcopy. - supergreens 8 years ago -
I will try again in the first script to create the directory and see if it works; I'll include here the results. - supergreens 8 years ago
-
Ok the best way to debug this then is to boot into the KBE and from the main screen choose recovery and open a command window.
Go to x:\applications and check the structure.
Try to run the vbs file while in the command window so you can debug and fix code without having to go thru booting to test each time. either copy the file from y: or include it in the applications dir or put on a usb, whatever is the easiest for you to call it. keep in this window till you get it to produce the output file you want, then integrate it as a task. - SMal.tmcc 8 years ago -
That is awesome, I will do that right now. - supergreens 8 years ago
-
I updated my first script above to reflect the changes I made based on your idea to create the directory. I've also updated the error message I'm now getting, which is still the same - just a different line number. It's failing at creating the directory on the X: drive. I need to inform myself a bit more on how to do what you suggested about pulling up the command prompt in the KBE, because I loaded the KBE and went to Recovery and pulled up the command prompt but couldn't change directory to X:\. So I have more to figure out with debugging.
If you or anyone see an obvious flaw in the new first script, then I appreciate it. Otherwise, I'll update when I'm further along in debugging. - supergreens 8 years ago -
old dos change directory commands work
cd\ will take you to the x: root
cd\applications will put you in the apps dir
cd\windows\system32 will put you back in the system directory
dir to list contents
y: will change you to the y drive
x: will change you back to the drive - SMal.tmcc 8 years ago -
I started with DR-dos 1 so I still use the command calls a lot. - SMal.tmcc 8 years ago