PowerShell – Excel Report Multiple Hotfixes & Computers

email me

# Add hotfixes to scan for
$hotFixes = @(
    "KB973815", 
    "KB3176935", 
    "KB4019264",
    "KB3138901"
    )

# Add computers to scan for
$computers = (get-content -path c:\reports\computers.txt) 

# Report name
$Report = @()
$reportName = "c:\setup\Report_$(get-date -Uformat "%Y%m%d-%H%M%S").csv" 

# return hotfix
Function Get-HotFixStatus([string]$hotFixes, [string]$computers) 
{ 
  Get-WmiObject -class  win32_QuickFixEngineering -Filter "HotFixID = '$hotfixes'" -computername $computers
} 

# Output to screen - create report with true or false
Function Get-HotFixReport([string[]]$hotFixes, [string[]]$computers) 
{ 
  foreach($computer in $computers) 
  { 
    Write-Host " "
    Write-Host $computer
    foreach ($hotfix in $hotfixes) 
    { 
     Write-Host $hotfix 
     $status =  $(if(Get-HotFixStatus -hotfix $hotfix -computer $computer) {$true} else {$false}) 
     $object = New-Object -TypeName PSObject 
     $object | Add-Member -MemberType NoteProperty -Name Computer -Value $computer 
     $object | Add-Member -MemberType NoteProperty -Name HotFix -Value $hotfix 
     $object | Add-Member -MemberType NoteProperty -Name Installed -Value $status
     Write-host "--" $status
     $object      
    }
   } 
} 

Clear-Host
Write-Host "Compiling report..."
Get-HotFixReport -hotfix $hotfixes -computer $computers | 
Sort-object -property computer | 
Export-Csv $reportName -NoTypeInformation -UseCulture
ii $reportName

Write-Host " "
Write-Host "Done!"

 
 
Screenshot
 

Fixing Windows 10 Broken Apps

email me

If you’re Windows 10 apps aren’t opening, or you’re receiving errors when you click shortcuts on the Start Menu, try this:

Open the Task manager. Click File > Run new task.

In the task dialog box, make sure you check Create this task with administrative privileges.

Type CMD

Type the following 4 commands in the console:

dism /online /cleanup-image /restorehealth

sfc /scannow

powershell

Get-AppXPackage -AllUsers |Where-Object {$_.InstallLocation -like “*SystemApps*”} | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register “$($_.InstallLocation)\AppXManifest.xml”}

 

Notes

If you have problems, log in as administrator, not using a Microsoft online account, and try again.

 

Using a different source WIM

Dism /Online /Cleanup-Image /RestoreHealth /Source:wim:D:\sources\install.wim:1 /limitaccess

 

Repair Windows Store

cmd > wsreset.exe

PowerShell -ExecutionPolicy Unrestricted -Command “& {$manifest = (Get-AppxPackage *WindowsStore*).InstallLocation + ‘\AppxManifest.xml’ ; Add-AppxPackage -DisableDevelopmentMode -Register $manifest}”

 

tags: repair apps, restore apps, fix broken apps

Adobe Flash: Microsoft Security Bulletin MS17-023 – Critical

email me

https://technet.microsoft.com/en-us/library/security/MS17-023

Executive Summary

This security update resolves vulnerabilities in Adobe Flash Player when installed on all supported editions of Windows 8.1, Windows Server 2012, Windows Server 2012 R2, Windows RT 8.1, Windows 10, and Windows Server 2016.

This security update is rated Critical. The update addresses the vulnerabilities in Adobe Flash Player by updating the affected Adobe Flash libraries contained within Internet Explorer 10, Internet Explorer 11, and Microsoft Edge.

For more information about this update, see Microsoft Knowledge Base Article 4014329.

Vulnerability Information

This security update addresses the following vulnerabilities, which are described in Adobe Security Bulletin APSB17-07:

CVE-2017-2997, CVE-2017-2998, CVE-2017-2999, CVE-2017-3000, CVE-2017-3001, CVE-2017-3002, CVE-2017-3003.

Juniper Pulse Client Removal

email me

reg delete “HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers” /f
reg delete “HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Hashes” /f
reg delete “HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols” /f

  1. Uninstall Juniper or Junos software from Control Panel > Programs and Features; remove all instances of the app.
  2. Delete Juniper and / or Pulse folders from
    C:\Program Files x86\
    C:\Program Files x86\CommonFiles\
    C:\Users\Public
    C:\Users\%username%\AppData\Roaming\
    C:\Users\%username%\AppData\Local\
    C:\ProgramData\
  3. Delete JuniperSetupControl from Start >Control Panel > Internet Options > General > Settings > View Objects
  4. Remove the Juniper Networks Virtual Adapter from Device Manager, click View on top > Select Show Hidden Devices > Go to the Network Adapter and remove Juniper Networks Virtual Adapter
  5. Delete the Juniper / Pulse keys  from the registry:
    HKEY_CURRENT_USER\Software\Juniper Networks
    HKEY_CURRENT_USER\Software\Pulse
    HKEY_LOCAL_MACHINE\Software\Juniper Networks
    HKEY_LOCAL_MACHINE\Software\Pulse
    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\dsNcApt
    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\dsNcService
  6. HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion the value ‘DevicePath’ should point to ‘%SystemRoot%\inf’.
  7. Open a command line “as Administrator”, run “pnputil -e > pnplist.txt”, find everything in there that has the name JUNIPER or PULSE in it, then run “pnputil -d oemXX.inf” for each entry, where “XX” is the actual number of the entry.
  8. Restart the machine.
  9. Download and install Juniper Setup Client (I get these MSIs directly from the vendor).
  10. Manually install NCINST64.EXE and check to ensure that it is running on the PC’s SERVICES.  If it is not running, it likely will not start, and if you try to VPN in you will likely see error 23787. 14. Manually install the Pulse Installer Service.
  11. Launch Pulse, set up profile, and try logging in.

PowerShell – Move/Disable Inactive Computers in AD

email me

This is a PowerShell script I wrote to move/disable inactive computer accounts.

Download and install Quest ActiveRoles Management Shell:
http://eddiejackson.net/apps/Quest_ActiveRolesManagementShellforActiveDirectoryx64_151.zip

# SET INACTIVE DAYS
$SetInactive = 120

# SEARCH HERE
$SourceOU = "ou=SEARCHHERE,dc=DOMAIN,dc=com"

# MOVE HERE
$TargetOU = "ou=MOVEHERE,dc=DOMAIN,dc=com"

# REPORT MODE
# Set to True to only show list of computers
# True or False
$RunReport = "True"

# DISABLE COMPUTER ACCOUNT
# Set to True to also disable the computer account
# True or False
$DisableAccount = "False"



#-----------------------------------------------
Add-PSSnapin Quest.ActiveRoles.ADManagement
Clear-Host

If ($RunReport -eq "True") {

    #REPORT MODE
    Write-Host "Report Mode..."
    Write-Host ""
    Get-QADComputer -InactiveFor $SetInactive -SizeLimit 0 -SearchRoot $SourceOU -IncludedProperties ParentContainerDN | foreach {
    $_.ComputerName
}

} else {

    #KILL MODE
    Write-Host "Kill Mode..."
    Write-Host ""

    $objectDescription = "$(Get-TimeStamp) Account moved due to inactivity - SysAdmin"

    Get-QADComputer -InactiveFor $SetInactive -SizeLimit 0 -SearchRoot $SourceOU -IncludedProperties ParentContainerDN | foreach {

    $computer = $_.ComputerName
    $SourceOU = $_.DN

    Set-QADComputer $computer -Description $objectDescription

    If ($DisableAccount -eq "True") {Disable-QADComputer $computer}
        #Enable-QADComputer $computer

    Move-QADObject $computer -NewParentContainer $TargetOU
    "$(Get-TimeStamp) $computer" | Out-File -FilePath $ENV:UserProfile\Desktop\_ADLog.txt -Append
    Write-Host ""

    }
}

function Get-TimeStamp {
    $SetTimestamp = "[" + (Get-Date).ToShortDateString() + " " + ((Get-Date).ToLongTimeString()) + "]"
    Return $SetTimestamp
}

Windows Build Numbers

email me

Operating System Version / Build / Date
Windows 95 OEM Service Release 1 (95A) 4.00.950 A
Windows 95 OEM Service Release 2 (95B) 4.00.1111 B
Windows 95 OEM Service Release 2.1 4.03.1212-1214 B
Windows 95 OEM Service Release 2.5 C 4.03.1214 C
Windows 98 4.10.1998
Windows 98 Second Edition (SE) 4.10.2222 A
Windows Millennium Beta 4.90.2476
Windows Millennium 4.90.3000
Windows NT 3.1 3.10.528.1 (9/11/1993)
Windows NT 3.5 3.50.807 (9/21/1994)
Windows NT 3.51 3.51.1057 (5/30/1995)
Windows NT 4.00 4.00.1381 (8/24/1996)
Windows NT 5.00 (Beta 2) 5.00.1515
Windows 2000 (Beta 3) 5.00.2031
Windows 2000 (Beta 3 RC2) 5.00.2128
Windows 2000 (Beta 3) 5.00.2183
Windows 2000 5.00.2195 (2/17/2000)
Whistler Server Preview 2250
Whistler Server alpha 2257
Whistler Server interim release 2267
Whistler Server interim release 2410
Windows XP (RC 1) 5.1.2505
Windows XP 5.1.2600 (10/25/2001)
Windows XP, Service Pack 1 5.1.2600.1106 (9/9/2002)
Windows XP, Service Pack 2 5.1.2600.2180 (8/25/2004)
Windows XP, Service Pack 3 5.1.2600.5512 (4/21/2008)
Windows .NET Server interim 5.2.3541
Windows .NET Server Beta 3 5.2.3590
Windows .NET Server Release Candidate 1 (RC1) 5.2.3660
Windows .NET Server 2003 RC2 5.2.3718
Windows Server 2003 (Beta?) 5.2.3763
Windows Server 2003 5.2.3790 (4/24/2003)
Windows Server 2003, Service Pack 1 5.2.3790.1180
Windows Server 2003 5.2.3790.1218
Windows Home Server 5.2.3790 (6/16/2007)
Windows Longhorn 6.0.5048
Windows Vista, Beta 1 6.0.5112 (7/20/2005)
Windows Vista, Community Technology Preview (CTP) 6.0.5219 (8/30/2005)
Windows Vista, TAP Preview 6.0.5259 (11/17/2005)
Windows Vista, CTP (December) 6.0.5270 (12/14/2005)
Windows Vista, CTP (February) 6.0.5308 (2/17/2006)
Windows Vista, CTP (Refresh) 6.0.5342 (3/21/2006)
Windows Vista, April EWD 6.0.5365 (4/19/2006)
Windows Vista, Beta 2 Preview 6.0.5381 (5/1/2006)
Windows Vista, Beta 2 6.0.5384 (5/18/2006)
Windows Vista, Pre-RC1 6.0.5456 (6/20/2006)
Windows Vista, Pre-RC1, Build 5472 6.0.5472 (7/13/2006)
Windows Vista, Pre-RC1, Build 5536 6.0.5536 (8/21/2006)
Windows Vista, RC1 6.0.5600.16384 (8/29/2006)
Windows Vista, Pre-RC2 6.0.5700 (8/10/2006)
Windows Vista, Pre-RC2, Build 5728 6.0.5728 (9/17/2006)
Windows Vista, RC2 6.0.5744.16384 (10/3/2006)
Windows Vista, Pre-RTM, Build 5808 6.0.5808 (12.10.2006)
Windows Vista, Pre-RTM, Build 5824 6.0.5824 (10/17/2006)
Windows Vista, Pre-RTM, Build 5840 6.0.5840 (10/18/2006)
Windows Vista, RTM (Release to Manufacturing) 6.0.6000.16386 (11/1/2006)
Windows Vista 6.0.6000 (11/8/2006)
Windows Vista, Service Pack 2 6.0.6002 (2/04/2008)
Windows Server 2008 6.0.6001 (2/27/2008)
Windows 7, RTM (Release to Manufacturing) 6.1.7600.16385 (10/22/2009)
Windows 7 6.1.7600 (10/22/2009)
Windows 7, Service Pack 1 6.1.7601
Windows Server 2008 R2, RTM (Release to Manufacturing) 6.1.7600.16385 (10/22/2009)
Windows Server 2008 R2, SP1 6.1.7601
Windows Home Server 2011 6.1.8400 (4/5/2011)
Windows Server 2012 6.2.9200 (9/04/2012)
Windows 8 6.2.9200 (10/26/2012)
Windows Phone 8 6.2.10211 (10/29/2012)
Windows Server 2012 R2 6.3.9200 (10/18/2013)
Windows 8.1 6.3.9200 (10/17/2013)
Windows 8.1, Update 1 6.3.9600 (4//8/2014)
Windows 10 10.0.10240 (7/29/2015)
Windows 10 (1511) 10.0.10586 (11/10/2015)
Windows 10 (1607) 10.0.14393 (2/8/2016)
Windows 10 (1703) 10.0.15063 (04/11/2017)
Windows 10 (1709) 10.0.16299 (10/17/2017)
Windows 10 (1803) 10.0.17134 (5/8/2018)
Windows 10 (1809) 10.0.17763 (10/2/2018)
Windows 10 (1903) 10.0.18362 (05/21/2019)
Windows 10 (1909) 10.0.18363 (11/12/2019)
Windows 10 (2004) 10.0.19041 (5/27/2020)
Windows 10 (20H2) 10.0.19042 (10/20/2020)
Windows 10 (21H1) 10.0.19043 (05/18/2021)
Windows 10 (21H2) 10.0.19044 (11/16/2021)
Windows 10 (22H2) 10.0.19045 (10/18/2022)

Visual Studio – TextHighlighterExtension2015

email me

This Visual Studio extension offers syntax highlighting for the following text formats:

.bat (also offer limited intellisense)
.cmd
.ini
.Log4j.properties file
.sh Bash file (alpha)
.txt
.log
.json is now supported by Visual Studio 2015!
(see bottom for extension)

.ps1
(also see bottom for PoshTools)

 

The extension comes with default colors set for black and white background.

To change colors, check here:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\r5vacxma.cek\COLORS_DEFINITION_DARK.json

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\r5vacxma.cek\COLORS_DEFINITION_LIGHT.json

To update keywords, check here:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\r5vacxma.cek\KEYWORDS.json

To add intellisense to batch files, check here:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\r5vacxma.cek\Intellisense.json

 

Snapshot of the highlighting in Visual Studio (I love it!)

* I did have to run this as administrator for it to work, but I don’t care…still love it.

 

   

Visual Studio – Command Task Runner

email me

This Visual Studio extension adds support for command line batch files in Visual Studio 2015’s Task Runner Explorer.

Supports .exe, .cmd, .bat, .ps1 and .psm1 files.

 

Add commands

The easiest way to add a batch file to Task Runner Explorer is to right-click it in Solution Explorer and select Add to Task Runner

You can right-click supported batch files in either solution folders or from within a any project.

Doing so will create a commands.json file. If you right-clicked a batch file in a solution folder, then the commands.json file will be placed in the solution folder. If the batch file is in a project you will be prompted to select to either put it in the project or solution folder.

If a commands.json file already exist, the new batch file will be added.

 

Execute scripts

When scripts are specified, the Task Runner Explorer will show those scripts.

Each script can be executed by double-clicking the task.

 

commands.json locations

The Task Runner Explorer supports multiple task runners in the same solution. For instance, you can have commands specified for the solution and additional ones for each project in that solution.

Task Runner Explorer will try to find a commands.json file in any parent folder to either the individual projects or the solution until it hits the root of the drive.

 

Commands

Inside commands.json it is possible to add custom scripts inside the “scripts” element.

{ “commands”: { “Build”: { “FileName”: “cmd.exe”, “WorkingDirectory”: “.”, “Arguments”: “/c build\build.cmd” } }}

 

PowerShell – Change Registry Key Permissions

email me

$regPath = "HKLM:\SOFTWARE\JavaSoft"

Try  {
        Get-ItemProperty $regPath -ErrorAction Stop        
        $regACL = Get-ACL $regPath
        $regRule= New-Object System.Security.AccessControl.RegistryAccessRule("Everyone","ReadPermissions","Allow")
        #("Everyone","FullControl","Allow")
        $regACL.SetAccessRule($regRule)
        Set-Acl $regPath $regACL
        Write-Host "Success!"
      }

Catch {
            
         Write-Host "Failed!"
      }

Notes

$x = $regACL.AccessRightType.IsPublic
if ($x -eq "True" ) {write-host "Success"}

$regKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("SOFTWARE\JavaSoft",[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::ChangePermissions)
$regACL = $regKey.GetAccessControl()
$regRule = New-Object System.Security.AccessControl.RegistryAccessRule ("User","FullControl","Allow")
$regACL.SetAccessRule($regRule)
$regKey.SetAccessControl($regACL)

Script Engine Example in Batch – v2

email me

This is version two of this: I wrote this to install a ‘prepared’ package to a single computer, or to a list of computers. It’s low tech to get around the numerous problems associated with remote installation using PowerShell, VBScript, or desktop management applications.

cls
@Echo off
Title Remote Engine by Eddie Jackson
color 0a
Setlocal EnableDelayedExpansion


:: SET COMMAND
set fileName=Sequence.cmd
set fileOpt=
set workDir=c:\windows\system32
set hidden=No

Set PCList=computers.txt
:: or
Set PC=



:: INTERNAL 
:BEGIN
c:
cd "%~dp0"
set Script=False
for %%i in (%fileName%) do set cmdExt=%%~xi
set Interact=-i
if [%cmdExt%]==[.cmd] set Script=True
if [%cmdExt%]==[.CMD] set Script=True
if [%cmdExt%]==[.bat] set Script=True
if [%cmdExt%]==[.BAT] set Script=True
if [%cmdExt%]==[.vbs] goto VBS
if [%cmdExt%]==[.VBS] goto VBS
if [%hidden%]==[Yes] set Interact=

set cmdPath=%workDir%\%fileName%

:: CREATES DATE AND TIME TIMESTAMP
:: sets a static timestamp
for /F "tokens=2-4 delims=/- " %%p in ('date/T') do set mdate=%%r%%p%%q
for /F "tokens=1-2 delims=:- " %%p in ('time/T') do set mtime=%%p%%q
Set Report=logs\%mdate%_%mtime%_%report%.txt
md logs>nul
cls
if not [%PC%]==[] goto SINGLE
goto MULTI


:: PROGRAM ROUTINE
:MULTI
Echo.
Echo [Entering multi computer mode]
Echo.

if not exist "%PCList%" (
Echo Computers text file not found^^!
echo.
pause
exit
)

Set cmdRem=PAExec.exe \\%%a -s %Interact% -w %workDir% "%cmdPath%" %fileOpt%

for /f "tokens=* delims= " %%a in (%PCList%) do (

echo Contacting %%a...
ping %%a -w 250 | find "Reply">nul
if errorlevel 1 (echo %%a,Offline >>"%Report%"
) else ( 
echo %%a,Online >>"%Report%"

if %Script%==True copy /y %fileName% \\%%a\c$\windows\SysWOW64\%fileName%>nul

:: LAUNCH REMOTE COMMAND
echo Launching %cmdPath% on %%a...
%cmdRem%>nul && Echo %%a,Success >>"%Report%" || Echo %%a,Failed >>"%Report%"
echo.
)
)
goto END


:SINGLE
Echo.
Echo [Entering single computer mode]
Echo.

Set cmdRem=PAExec.exe \\%PC% -s %Interact% -w %workDir% "%cmdPath%" %fileOpt%

echo Contacting %PC%...
echo.
ping %PC% -w 250 | find "Reply">nul
if errorlevel 1 (echo %PC% is Offline^^!
) else ( 
echo %PC% is Online^^!
echo.

if %Script%==True copy /y %fileName% \\%PC%\c$\windows\SysWOW64\%fileName%>nul

:: LAUNCH REMOTE COMMAND
echo Launching %cmdPath% on %PC%...
echo.
%cmdRem%>nul && Echo Success^^! || Echo Failed^^!
echo.
goto END
)

:: EXIT
:END
Echo.
Echo Done^^!
pause
endlocal
exit /b 0


:VBS
Echo VBScripts are NOT SUPPORTED^^!
echo.
pause
exit

 

 

Notes

Run GPUpdate on List of Servers

FOR /F “tokens=*” %%A IN (C:\script\servers.txt) DO WMIC /Node:%%A Process call create “cmd.exe /c gpupdate”

$List = ‘server1′,’server2′,’server3′,’server4’
foreach ($server in $List) {psexec \\$server gpupdate}


Move to current directory

c:
cd “%~dp0”


Execute EXEs dynamically

@ECHO OFF
FOR /f “tokens=*” %%A IN (‘dir /b *.exe’) DO (
ECHO Filename: “%%A”
:: “%%A” /SILENTINSTALLOPTIONS
:: or
:: start “” “%%A”
)
pause

 

tags: Batch current directory, dir /b output, script engine, MrNetTek

LANDesk Client Elevated Repair – Proof of Concept

email me

I created a LANDesk Repair tool which can be used by any user to repair, reinstall, and fix issues related to the LANDesk client. The magic part of this is that it uses a public URL to download the LANDesk setup file, and then launches in an elevated mode using Microsoft’s SecureSubstring (the secure part was written in C#).

The advantage of having something like this, versus a package compiled with the LD setup file (172MB), is that the package is much smaller (less than a meg) and—if and when you change the LD setup—there is no need to recompile the package with the updated source file. Just drop the new source file at the URL, and anyone using the Repair Tool will automatically get the updated source file; this works for on site and off site users.

Originally, I just wanted to create a proof-of-concept prototype, but it worked so well, it was implemented.

Screenshot of my HTA

 

' ---------------------------------------------------------------' 
' Author:   Eddie Jackson
' File:     LANDesk_Repair.exe
' Purpose:  To repair or reinstall LANDesk
' Version:  1.0
' Date:     4/11/2017
'
' Usage:    Installed to C:\AFolderOfYourChoice
'           Accessed from Start Menu
' Notes
' Exit codes are 0 success, 1 no source file, 2 failed download
' ---------------------------------------------------------------' 


Option Explicit

'global declarations
Dim varHTTP, varBinaryString, setupFile, setupURL, uninstallFile, ComputerName, CurDir
Dim objShell, oldLANDesk, newLANDesk, msgFile, fso, objWMIService, cmd, colProcesses, Elevate



'Sequencing...
InitializeVariables()
CheckURL()
Download(setupFile)
Verify(setupFile)
Uninstall(oldLANDesk)
Install(newLANDesk)
ExitSequence(0)




sub InitializeVariables()
	on error resume next	
	
	'computer name
	ComputerName = "."

	CurDir = "C:\AFolderOfYourChoice"
	
	'message file
	msgFile = CurDir & "\ldmsg.dat"

	Set objShell = CreateObject("WScript.Shell")
	Set fso = CreateObject("Scripting.FileSystemObject")	
 
	Set varHTTP = CreateObject("Microsoft.XMLHTTP")
	Set varBinaryString = CreateObject("Adodb.Stream")
	
	setupFile = "Client_From_ldlogon_AdvanceAgent_Folder.exe"
	uninstallFile = "UninstallWinClient_From_LANDesk.exe"
	
        'tool I created to do elevation
        Elevate = CurDir & "\Elevate.exe -app" & " "
        'reference: http://eddiejackson.net/wp/?p=13815
	
	oldLANDesk = Elevate & chr(34) & CurDir & "\" & uninstallFile & chr(34) & " " & chr(34) & "/NOREBOOT /FORCECLEAN" & chr(34)
	newLANDesk = Elevate & chr(34) & CurDir & "\" & setupFile & chr(34)
	setupURL = "http://YourGateway_CSA_or_DMZ/" & setupFile

	varHTTP.Open "GET", setupURL, False
	varHTTP.Send
end sub


sub CheckURL()
    on error resume next
	'launch splash	
	Msg("Searching for download file...")	
	Splash()
	
	Select Case Cint(varHTTP.status)		
		Case 200, 202, 302			
			Msg("Found LANDesk download file!")			
			Exit Sub
		Case Else			
			Msg("LANDesk setup could not be found!")			
			ExitSequence(1)
	End Select
end sub


sub Download(dFile)
		on error resume next
		Msg("Downloading LANDesk file...")	
		With varBinaryString
			.Type = 1 'my type has been set to binary
			.Open
			.Write varHTTP.responseBody
			.SaveToFile ".\" & dFile, 2 'if exist, overwrite
		End With
		varBinaryString.close		
		Msg("LANDesk setup has been downloaded...")		
end sub


sub Uninstall(uCommand)
		on error resume next
		Msg("Removing old LANDesk setup...")	
		
		objShell.Run uCommand,0,True
		Wait(20)
		
		Monitor(uninstallFile)	
		Msg("LANDesk has been removed...")
end sub


sub Verify(vDownload)
	on error resume next
	Msg("Verifying file integrity...")
	
	If (fso.FileExists(CurDir & "\" & vDownload)) Then
		Msg("Download was successful!")
	Else
		Msg("Download failed!")
		ExitSequence(2)
	End If

end sub


sub Install(iCommand)
		on error resume next
		Msg("Installing LANDesk Client...")
		
		objShell.Run iCommand,0,True
		Wait(20)
		
		Monitor(setupFile)		
		Msg("LANDesk Client has been installed!")		
end sub


sub Wait(time)
	on error resume next
    time =  time * 1000
	WScript.Sleep time
end sub


sub Monitor(procName)

'secondary method to make sure wait for exit works
		Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & ComputerName & "\root\cimv2")		
		cmd = 1
		
		Do While cmd = 1			
			Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '" & procName & "'")
			If colProcesses.Count = 0 Then
				on error resume next
				'Process is not running
				cmd = 0
				Wait(4)
			Else
				'Process is running
				cmd = 1
				Wait(30)		
			End If
		Loop				
end sub


sub Msg(message)
	on error resume next
	objShell.Run "cmd /c echo " & message & ">" & msgFile,0,true
	Wait(4)
end sub


sub Splash()
	on error resume next
	'a simple animation I made (ldhta.exe is mshta.exe)
        'you'll have to create your own little animation here
	objShell.Run CurDir & "\ldhta.exe " &  CurDir & "\ldprogress.hta",9,false
	Wait(8)
end sub


sub ExitSequence(errorcode)	
	Msg("Exiting...")
	Wait(4)
	objShell.Run "taskkill /f /im ldhta.exe",0,true	
	WScript.Quit(errorcode)
end sub