Since my last post I came to the realisation that I really didn’t like the way that the Diskpart box popped up on screen during the function call, so I did what I said I should have done and created the function the other way. This also cleans up the text files after completion, which is something the previous function didn’t do.
For completeness I also made the function a little more generic, so it takes the Volume Label as the Variable, and falls back to “IMAGE” if none was passed.
Function GetVolumeNumberHidden(Label) On Error Resume Next Const ForWriting = 2 Const ForReading = 1 If Label="" Then Label="IMAGE" End If Set oShell = CreateObject("WScript.Shell") Set oFSO = CreateObject("Scripting.FileSystemObject") TempFile = oShell.ExpandEnvironmentStrings("C:\Temp\dp.txt") ListFile = oShell.ExpandEnvironmentStrings("C:\Temp\dl.txt") Set oFile = oFSO.OpenTextFile(TempFile,ForWriting,True) oFile.WriteLine("LIST VOLUME") oFile.Close() oShell.Run "%comspec% /c diskpart /s " & TempFile & _ " > " & ListFile, 0, True Ouptut = "" Str = "" Set oFile = oFSO.OpenTextFile(ListFile,ForReading) Do until oFile.AtEndOfStream Str = oFile.ReadLine If InStr(Str,"Volume") > 0 Then If Not (Mid(Str,10,3) = "###") Then DriveLetter = Mid(Str,16,1) VolumeNumber = Trim(Mid(Str,10,3)) If StrComp(Trim(Mid(Str,20,12)),Trim(Label))=0 Then GetVolumeNumberHidden = VolumeNumber oFile.Close If oFSO.FileExists(TempFile) Then oFSO.DeleteFile TempFile, True End If If oFSO.FileExists(ListFile) Then oFSO.DeleteFile ListFile, True End If Exit Function End If End If End If Loop oFile.Close If oFSO.FileExists(TempFile) Then oFSO.DeleteFile TempFile, True End If If oFSO.FileExists(ListFile) Then oFSO.DeleteFile ListFile, True End If End Function
This function now makes its way into the Completed stage and now I move on to other things. I have been working very frantically on my AutoStore script. This function is used in both the Store/Restore installation, and the AutoStore script itself, in order to get the timestamp of the previously stored image files. Some of the other fun things I have been playing with involve Novell Workstation Policy Packages, and Package Schedules. In order to initiate the AutoStore process I have created an array of Package Schedules that calls my AutoImage.vbe file. I noticed that during the process of Installation, the MSI had not completed before the AutoImage.vbe file was attempted to be run. This lead to a WScript error because the target file did not exist. I modified the run information to the following:
C:\Windows\System32\cmd.exe /c "if exist ( C:\SOE\AUTOSTORE\AutoImage.vbe) ( start wscript C:\SOE\AUTOSTORE\AutoImage.vbe Interval=14 Force )"
At first glance it may seem that some of this can be discarded, however it is all required. In order to first check that the file exists without requiring ANY script to have been installed onto the target machine we need to use “if exist” which requires running through cmd.exe because it is a command interpreter command, not a stand alone executable. If we do not use Start then the command screen stays open while the script runs, or while a popup box explaining to users that they need to reboot is displayed. This appears a disjointed visually and lead to me wanting to close all those blank black windows. WScript does not explicitly need to be called, but since I want to specify WScript instead of CScript I have included it for completeness sake.
In order that the command window does not show up for most of the background calls to the script I have ensured that it runs in the SYSTEM security space. The Unsecure System space is used only for those functions where the script requires user input or provides user feedback. This limits the interruption to the general use of the PCs.
I spent much of the past few days creating and modifying the scripts, and I spent all afternoon packaging the script into the MSI and creating the Policy Packages. I have also now documented the Policy Package creation process and documented the usage of the script. Hopefully I can get it all slapped together and rolled out, as we need to force a store before Monday, when an updated software package is being forced out. I have to love the communication we get prior to these things. I have had to kill myself to get the modifications done to their current point, and as yet they are untested for machines which have not received some of the custom modifications we have implemented. All will come to light tomorrow.