Jump to content

How to run my script connected to the internet before logon screen appears?


Recommended Posts

Im trying to achieve my script or GUI to run before the logon screen after an os image has been applied. The problem is not getting it to run, but to have it make a connection to the internet, as my script runs Windows Update to download available updates.

Is there a way to make a connection to the internet from within my script? Or has Windows even loaded the drivers for the NIC before or after the logon screen appears?

Currently i am using the current registry key to make it run:

HKEY_LOCAL_MACHINE\SYSTEM\Setup\CmdLine, "wscript //nologo //B "C:\Windows\OSDINST\StartInstallationScreen.vbs"

The above makes Windows Setup fires a VBScript, that launches my GUI.

I don't what to do to make it work. I know i could run it during login, but that is not what I want to achieve.

 

Any help is appreciated.

Thanks in advance

Edited by doestergaard
Link to comment
Share on other sites

Hi Jos

Thanks for the reply. Unfortunately, I have already tried that. My Task Scheduler will run behind the logon screen, and I don't think that I have access to it, as the installation process will execute at the very first boot after Windows Setup

At work we have a similar process, but it installs it as a service. I have tried that as well, but the program still seems to stay behind the logon screen, I really don't know how they have achieved it, but its no magic trick of cause. I just can't figure it out myself :)

Edited by doestergaard
Link to comment
Share on other sites

The service is running fine, its just that the Windows Logon Screen will not let my program run on top of it. The second problem is also, that It will automatically log in the primary user account (no password).

I some how need it to prevent the logon screen from appear until AFTER my script has run succesfully.

As of now, im not running it as a service, but trying to achieve it with the following registry key (which also runs btw):

HKEY_LOCAL_SYSTEM\Setup\CmdLine, "wscript //nologo //B C:\Windows\OSDINST\StartInstallationScreen.vbs

But since there is no internet connection at this stage (it seems) when the above key is fired by Windows Setup, my code will throw back the error "Could not connect to the internet..."

EDIT: Here is the script that runs the InstallationScreen:

Dim objShell, objFSO
Dim sInstallScreenPath

Set objShell=WScript.CreateObject("WScript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")

sInstallScreenPath="C:\Windows\OSDINST"

If objFSO.FileExists(sInstallScreenPath & "\InstallationScreen.exe") = False Then
    WScript.Echo "ERROR: Could not find InstallationScreen.exe"
Else
    objShell.Run "C:\Windows\OSDINST\paexec.exe -i -d " & sInstallScreenPath & "\InstallationScreen.exe", 0, False
End If
WScript.Sleep 1000
objShell.Run "%WINDIR%\System32\oobe\windeploy.exe", 0, True
objShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\Setup\CmdLine", "wscript //nologo //B """ & sInstallScreenPath & "\StartInstallationScreen.vbs""", "REG_SZ"
Set objShell=Nothing
Set objFSO=Nothing

Here is my code (InstallationScreen):

#cs ----------------------------------------------------------------------------

  InstallSystem:    1.0
  Author:           Daniel Østergaard Nielsen

  Script Function:
    Deploy Windows Updates and Software

#ce ----------------------------------------------------------------------------

#pragma compile(ProductVersion, 1.0.51)

DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)

#include <GUIConstants.au3>
#include <Date.au3>
#include <File.au3>

Opt("MustDeclareVars", 1)
Opt("TrayIconHide", 1)
Opt("GUIOnEventMode", 1)

Global $_hGUI, $_oBackground, $_iRegType, $_iWidth, $_iHeight, $_sResolution, $_sProgressMain, $_sProgressSub

Main()

Func Main()
   $_iWidth = @DesktopWidth
   $_iHeight = @DesktopHeight

   ; Detect OS Arch
   If FileExists("C:\Program Files (x86)") Then $_iRegType = 64

   ; Detect Setup Phase
   If RegRead("HKEY_LOCAL_MACHINE" & $_iRegType & "\SYSTEM\Setup", "SystemSetupInProgress") = 1 Then
      OSD_MiniSetup()
   Else
      OSD_InstallScreen()
   EndIf

EndFunc ; <== Main()

Func OSD_MiniSetup()
   $_hGUI = GUICreate("InstallationScreen.exe", $_iWidth, $_iHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
   GUICtrlSetDefBkColor($GUI_BKCOLOR_TRANSPARENT, $_hGUI)
   GUICtrlSetDefColor(0xFFFFFF, $_hGUI)

   $_oBackground = GUICtrlCreatePic(@ScriptDir & "\BackgroundDefault.jpg", 0, 0, $_iWidth, $_iHeight)

   ; Screen Resolution
   $_sResolution = GUICtrlCreateLabel($_iWidth & "x" & $_iHeight, 10, 12, 75, 18)
   GUICtrlSetFont($_sResolution, 9)

   ; Progress Status
   GUICtrlCreateLabel("Please wait while Mini-Setup is preparing Windows", 0, 270, $_iWidth, 35, $SS_CENTER)
   GUICtrlSetFont(-1, 22, 600)

   ; ComputerName
   GUICtrlCreateLabel(RegRead("HKEY_LOCAL_MACHINE" & $_iRegType & "\SOFTWARE\OSD", "NewComputerName"), 0, 328, $_iWidth, 25, $SS_CENTER)
   GUICtrlSetFont(-1, 16)

   ; DiskConfig
   GUICtrlCreateLabel("DiskConfig:", 10, $_iHeight-91, 110, 22)
   GUICtrlSetFont(-1, 9)

   GUICtrlCreateLabel(RegRead("HKEY_LOCAL_MACHINE" & $_iRegType & "\SOFTWARE\OSD", "DiskConfig"), 120, $_iHeight-91, 300, 22)
   GUICtrlSetFont(-1, 9)

   ; ImageName
   GUICtrlCreateLabel("ImageName:", 10, $_iHeight-69, 110, 22)
   GUICtrlSetFont(-1, 9)

   GUICtrlCreateLabel(RegRead("HKEY_LOCAL_MACHINE" & $_iRegType & "\SOFTWARE\OSD", "ImageName"), 120, $_iHeight-69, 300, 22)
   GUICtrlSetFont(-1, 9)

   ; ModelName
   GUICtrlCreateLabel("ModelName:", 10, $_iHeight-47, 110, 22)
   GUICtrlSetFont(-1, 9)

   GUICtrlCreateLabel(RegRead("HKEY_LOCAL_MACHINE" & $_iRegType & "\SOFTWARE\OSD", "ModelName"), 120, $_iHeight-47, 300, 22)
   GUICtrlSetFont(-1, 9)

   ; ImageOSType
   GUICtrlCreateLabel("ImageOSType:", 10, $_iHeight-25, 110, 22)
   GUICtrlSetFont(-1, 9)

   GUICtrlCreateLabel(RegRead("HKEY_LOCAL_MACHINE" & $_iRegType & "\SOFTWARE\OSD", "ImageOSType"), 120, $_iHeight-25, 300, 22)
   GUICtrlSetFont(-1, 9)

   Sleep(5000)

   GUISetState(@SW_SHOW, $_hGUI)
   GUISetCursor(16, 1, $_hGUI)

   Do
      Sleep(20)
   Until @DesktopWidth > $_iWidth Or @DesktopHeight > $_iHeight

   $_iWidth = @DesktopWidth
   $_iHeight = @DesktopHeight

   ; Update screen
   WinMove($_hGUI, "", 0, 0, $_iWidth, $_iHeight)
   GUICtrlSetPos($_oBackground, 0, 0, $_iWidth, $_iHeight)
   GUICtrlSetData($_sResolution, $_iWidth & "x" & $_iHeight)

   While 1
      Sleep(20)
   WEnd
EndFunc ; <== RunMiniSetup()

Func OSD_InstallScreen()
   Local $oDate, $sIP, $iRetry = 0, $sProgressMain, $sProgressSub

   $_hGUI = GUICreate("InstallationScreen.exe", $_iWidth, $_iHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
   GUICtrlSetDefBkColor($GUI_BKCOLOR_TRANSPARENT, $_hGUI)
   GUICtrlSetDefColor(0xFFFFFF, $_hGUI)

   $_oBackground = GUICtrlCreatePic(@ScriptDir & "\BackgroundDefault.jpg", 0, 0, $_iWidth, $_iHeight)

   ; Screen Resolution
   $_sResolution = GUICtrlCreateLabel($_iWidth & "x" & $_iHeight, 10, 12, 75, 18)
   GUICtrlSetFont($_sResolution, 9)

   ; Current operation
   GUICtrlCreateLabel("Installation is running!" & @CRLF & @CRLF & "Please wait!", 0, 12, $_iWidth, 100, $SS_CENTER)
   GUICtrlSetFont(-1, 20, 600)

   ; IPaddress
   $sIP = GUICtrlCreateLabel("", 10, $_iHeight-25, 75, 22)
   GUICtrlSetFont($sIP, 9)

   ; Clock
   $oDate = GUICtrlCreateLabel(StringReplace(@MDAY, "0", "") & ". " & _DateToMonth(@MON, 2) & "  " & @HOUR & ":" & @MIN, $_iWidth-130, 12, 110, 22, $SS_RIGHT)
   GUICtrlSetFont($oDate, 9)

   ; Progress Label
   $_sProgressMain = GUICtrlCreateLabel("", 0, $_iHeight-197, $_iWidth, 22, $SS_CENTER)
   GUICtrlSetFont($_sProgressMain, 11)

   $_sProgressSub = GUICtrlCreateLabel("", 0, $_iHeight-160, $_iWidth, 22, $SS_CENTER)
   GUICtrlSetFont($_sProgressSub, 11)

   ; Version
   GUICtrlCreateLabel(FileGetVersion(@ScriptDir & "\InstallationScreen.exe", "ProductVersion"), $_iWidth-85, $_iHeight-25, 75, 22, $SS_RIGHT)
   GUICtrlSetFont(-1, 9)

   Sleep(4000)

   GUISetState(@SW_SHOW, $_hGUI)

   Do
      Sleep(2000)
      $iRetry += 1
   Until IsConnect() = True Or $iRetry = 30

   If $iRetry = 30 Then
      MsgBox($MB_ICONERROR, "InstallationScreen", "Could not connect to the internet. Please check your connection and press OK to reboot", 0, $_hGUI)
      Exit
   Else
      ; Run Windows Update Agent
      WindowsUpdateAgent()
      GUICtrlSetData($_sProgressMain, "Windows Update")

      Sleep(5000)

      GUICtrlSetData($_sProgressMain, "")

      Sleep(500)

      FinalReboot()
   EndIf

   While 1
      Sleep(20)
   WEnd
EndFunc ; <== RunInstaller()

Func IsConnect()
   Local $aConnect, $bReturn = True

   $aConnect = DllCall("connect.dll", "long", "IsInternetConnected")
   If @error Then
      Return SetError(1, 0, False)
   EndIf
   Return $aConnect[0] = 0
EndFunc ; <== IsConnect

Func WindowsUpdateAgent()
   Local $oUpdateSession, $oUpdates, $oUpdateDownloader, $oUpdatesToInstall, $iCounter, $oUpdateToDownload, $oResults, $oUpdateInstaller, $oUpdateToInstall

   $oUpdateSession = ObjCreate("Microsoft.Update.Session")
   If IsObj($oUpdateSession) Then
      GUICtrlSetData($_sProgressMain, "Initializing Windows Update")

      $oUpdates = $oUpdateSession.CreateUpdateSearcher().Search("IsInstalled=0 and IsHidden=0 and Type='Software'").Updates
      If $oUpdates.Count = 0 Then
         GUICtrlSetData($_sProgressMain, "Windows Update")
         Return False
      Else
         $oUpdateDownloader = $oUpdateSession.CreateUpdateDownloader()
         $oUpdatesToInstall = ObjCreate("Microsoft.Update.UpdateColl")

         GUICtrlSetData($_sProgressMain, "Running Windows Update")

         $iCounter = 0
         For $oUpdate In $oUpdates
            $iCounter += 1

            If $oUpdate.EulaAccepted = False Then $oUpdate.AcceptEula()

            GUICtrlSetData($_sProgressSub, "Downloading: " & "(" & $iCounter & "/" & $oUpdates.Count & ") '" & $oUpdate.Title & "'")
            $oUpdateToDownload = ObjCreate("Microsoft.Update.UpdateColl")
            $oUpdateToDownload.Add($oUpdate)

            $oUpdateDownloader.Updates = $oUpdateToDownload
            $oResults = $oUpdateDownloader.Download()

            If $oResults.Hresult = 0 And $oResults.ResultCode = 2 Or $oResults.ResultCode = 3 Then
               $oUpdatesToInstall.Add($oUpdate)
            EndIf
            $oUpdateToDownload = 0
            Sleep(20)
         Next

         GUICtrlSetData($_sProgressSub, "")
         Sleep(5000)

         $oUpdateInstaller = $oUpdateSession.CreateUpdateInstaller()

         $iCounter = 0
         For $oUpdate In $oUpdatesToInstall
            $iCounter += 1

            GUICtrlSetData($_sProgressSub, "Installing: " & "(" & $iCounter & "/" & $oUpdates.Count & ") '" & $oUpdate.Title & "'")
            $oUpdateToInstall = ObjCreate("Microsoft.Update.UpdateColl")
            $oUpdateToInstall.Add($oUpdate)

            $oUpdateInstaller.Updates = $oUpdateToInstall
            $oUpdateInstaller.Install()

            $oUpdateToInstall = 0
            Sleep(20)
         Next

         GUICtrlSetData($_sProgressSub, "")
         Sleep(5000)
      EndIf
   Else
      MsgBox($MB_ICONERROR, "Windows Update Agent", "Invalid object", 0)
   EndIf
EndFunc ; <== WindowsUpdateAgent()

Func FinalReboot()
   Run("shutdown.exe /r /t 10")
   MsgBox($MB_ICONINFORMATION, "InstallationScreen", "Computer is restarting", 0, $_hGUI)
EndFunc ; <== FinalReboot

Hope it makes sense ^_^

Edited by doestergaard
Link to comment
Share on other sites

  • Moderators

So if your script is returning an error because the internet connection is not yet established, wouldn't it simply make sense to create a While loop that pauses execution of the script until that connectivity is present??

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...