Jump to content

Installing Microsoft .NET Framework 4 script issue


 Share

Recommended Posts

I learned about AutoIT from this guys post http://www.scriptingsimon.com/2010/10/installing-microsoft-net-framework-4/

I wanted to change his code so that only .NET 4 was being installed. However, when I compile the script and then run the newly created .exe, I do not get the same result as his created .exe which is located at the link above. When I run my newly created .exe, it appears as if nothing happens. I checked event viewer and did not find anything there letting me know that the installation had begun.

Because I am a complete and total noob to scripting using AutoIT, I was hoping that a more seasoned individual might be able to assist me in the compiling part of this script.

Here is the script with the author's name included in the script:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=....ImagesCSO.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         Simon McBryde

 Script Function:
 Install .NET Framework 4.0

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

#include <array.au3>

; Check to see if .NET Framework 4.0 is already installed and quit if it is
If _CheckDotNet4() = 1 Then
 ConsoleWrite('.NET Framework 4.0 Extended already installed, terminating operation' & @CRLF)
 Exit 0
EndIf

; Check to see if Windows Imaging Component is installed and install if not
If FileExists(@SystemDir & 'Windowscodecs.dll') Then
 ConsoleWrite('Windows Imaging Component present, continuing operation' & @CRLF)
Else
 ConsoleWrite('Windows Imaging Component NOT present, attempting installation' & @CRLF)
 If @OSArch = 'x86' Then
  ConsoleWrite('32-Bit architecture detected. Installing wic_x86_enu.exe' & @CRLF)
  FileInstall('wic_x86_enu.exe', @ScriptDir & '')
  _CommandExecute('"' & @ScriptDir & 'wic_x86_enu.exe" /q /norestart')
 EndIf
 If @OSArch = 'x64' Then
  ConsoleWrite('64-Bit architecture detected. Installing wic_x64_enu.exe' & @CRLF)
  FileInstall('wic_x64_enu.exe', @ScriptDir & '')
  _CommandExecute('"' & @ScriptDir & 'wic_x64_enu.exe" /q /norestart')
 EndIf
 ; Verifty installation of Windows Imaging Component and quit if not successful
 If FileExists(@SystemDir & 'Windowscodecs.dll') Then
  ConsoleWrite('Installation of Windows Imaging Component successful, continuing operation' & @CRLF)
 Else
  ConsoleWrite('Installation of Windows Imaging Component NOT successful, terminating operation' & @CRLF)
  Exit 1
 EndIf
EndIf

; Install .NET Framework 4.0
FileInstall('dotNetFx40_Full_x86_x64.exe', @ScriptDir & '')
_CommandExecute('"' & @ScriptDir & 'dotNetFx40_Full_x86_x64.exe" /q /norestart')

; Check to see if .NET Framework 4.0 installation was successful
If _CheckDotNet4() = 1 Then
 ConsoleWrite('.NET Framework 4.0 Extended installed successfully' & @CRLF)
Else
 ConsoleWrite('.NET Framework 4.0 Extended not present after attempted installation' & @CRLF)
 Exit 1
EndIf

Exit 0

Func _CommandExecute($Command)
 Local $Pid = Run(@ComSpec & ' /c ' & $Command, '', @SW_HIDE)
 ProcessWaitClose($Pid)
EndFunc   ;==>_CommandExecute

Func _CheckDotNet4()
 Local $NETInstalled
 RegRead('HKEY_LOCAL_MACHINESOFTWAREMicrosoftNET Framework SetupNDPv4Full', '')
 If @error > 0 Then
  $NETInstalled = 0
 Else
  $NETInstalled = 1
 EndIf
 Return $NETInstalled
EndFunc   ;==>_CheckDotNet4

 

I even tried just running this script as a stand alone script using AutoIT installed, the latest version. It too produces nothing... no errors... nothing happens.

So perhaps there is something wrong with the version I have installed and the version that this was originally written for? I have no idea.

I simply want to cut out this section:

; Check to see if Windows Imaging Component is installed and install if not
If FileExists(@SystemDir & 'Windowscodecs.dll') Then
 ConsoleWrite('Windows Imaging Component present, continuing operation' & @CRLF)
Else
 ConsoleWrite('Windows Imaging Component NOT present, attempting installation' & @CRLF)
 If @OSArch = 'x86' Then
  ConsoleWrite('32-Bit architecture detected. Installing wic_x86_enu.exe' & @CRLF)
  FileInstall('wic_x86_enu.exe', @ScriptDir & '')
  _CommandExecute('"' & @ScriptDir & 'wic_x86_enu.exe" /q /norestart')
 EndIf
 If @OSArch = 'x64' Then
  ConsoleWrite('64-Bit architecture detected. Installing wic_x64_enu.exe' & @CRLF)
  FileInstall('wic_x64_enu.exe', @ScriptDir & '')
  _CommandExecute('"' & @ScriptDir & 'wic_x64_enu.exe" /q /norestart')
 EndIf
 ; Verifty installation of Windows Imaging Component and quit if not successful
 If FileExists(@SystemDir & 'Windowscodecs.dll') Then
  ConsoleWrite('Installation of Windows Imaging Component successful, continuing operation' & @CRLF)
 Else
  ConsoleWrite('Installation of Windows Imaging Component NOT successful, terminating operation' & @CRLF)
  Exit 1
 EndIf
EndIf

If anyone could point me in the right direction or perhaps tell me what I need to change, I would great appreciate it!

I absolutely LOVE how a script, created in AutoLT, can be turned into an .exe with the necessary files included. That is brilliant!!

Link to comment
Share on other sites

hello MichaelSO, welcome to AutoIt and to the forum!

let's start with a quick overview: if you want to skip the dependencies, what's wrong with just running the installer with the required switches? you don't need any scripting for this, this can be done from any launcher, even at the command prompt:

dotNetFx40_Full_x86_x64.exe /q /norestart

now, when you describe your issue on a forum, saying something like "it doesn't work" is meaningless. you say:

When I run my newly created .exe, it appears as if nothing happens. I checked event viewer and did not find anything there letting me know that the installation had begun.

 

you say "nothing happens" - but have you run it at the console, so you can see the messages generated by the script? have you run it before compilation, so the SciTe output can show you what's going on? if so, what did you see?

and Event Viewer is irrelevant here. my guess is that the .NET installer was never launched - it is most likely already installed, and you just missed the console message, and the script itself does not write anything to the Windows Event Log.

now, note that the script has its own dependencies: in order to run properly, it must have the .NET installer in the same path. despite it's usage of console output to show you various messages, it ignores the case where that file is absent... somewhat poor error handling, which will definitely be needed when, for example, the script is run from a folder with read-only permissions - which is the common scenario in network deployment.

and while we're on the subject of console output, note that when you run the script from the SciTe editor - still not compiled - the console output is displayed in the lower pane.

now let's have a look at the script you included. but let's do it right - using the "Code" button at the toolbar of the post editor. you get colouring (for example, comments in green) and proper indentation that shows you exactly where each part of the script begins and ends:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\..\Images\CSO.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
    AutoIt Version: 3.3.6.1
    Author:         Simon McBryde
    Script Function:
    Install .NET Framework 4.0
#ce ----------------------------------------------------------------------------
#include <array.au3>
; Check to see if .NET Framework 4.0 is already installed and quit if it is
If _CheckDotNet4() = 1 Then
    ConsoleWrite('.NET Framework 4.0 Extended already installed, terminating operation' & @CRLF)
    Exit 0
EndIf
; Check to see if Windows Imaging Component is installed and install if not
If FileExists(@SystemDir & '\Windowscodecs.dll') Then
    ConsoleWrite('Windows Imaging Component present, continuing operation' & @CRLF)
Else
    ConsoleWrite('Windows Imaging Component NOT present, attempting installation' & @CRLF)
    If @OSArch = 'x86' Then
        ConsoleWrite('32-Bit architecture detected. Installing wic_x86_enu.exe' & @CRLF)
        FileInstall('wic_x86_enu.exe', @ScriptDir & '\')
        _CommandExecute('"' & @ScriptDir & '\wic_x86_enu.exe" /q /norestart')
    EndIf
    If @OSArch = 'x64' Then
        ConsoleWrite('64-Bit architecture detected. Installing wic_x64_enu.exe' & @CRLF)
        FileInstall('wic_x64_enu.exe', @ScriptDir & '\')
        _CommandExecute('"' & @ScriptDir & '\wic_x64_enu.exe" /q /norestart')
    EndIf
    ; Verifty installation of Windows Imaging Component and quit if not successful
    If FileExists(@SystemDir & '\Windowscodecs.dll') Then
        ConsoleWrite('Installation of Windows Imaging Component successful, continuing operation' & @CRLF)
    Else
        ConsoleWrite('Installation of Windows Imaging Component NOT successful, terminating operation' & @CRLF)
        Exit 1
    EndIf
EndIf
; Install .NET Framework 4.0
FileInstall('dotNetFx40_Full_x86_x64.exe', @ScriptDir & '\')
_CommandExecute('"' & @ScriptDir & '\dotNetFx40_Full_x86_x64.exe" /q /norestart')
; Check to see if .NET Framework 4.0 installation was successful
If _CheckDotNet4() = 1 Then
    ConsoleWrite('.NET Framework 4.0 Extended installed successfully' & @CRLF)
Else
    ConsoleWrite('.NET Framework 4.0 Extended not present after attempted installation' & @CRLF)
    Exit 1
EndIf
Exit 0
Func _CommandExecute($Command)
    Local $Pid = Run(@ComSpec & ' /c ' & $Command, '', @SW_HIDE)
    ProcessWaitClose($Pid)
EndFunc   ;==>_CommandExecute
Func _CheckDotNet4()
    Local $NETInstalled
    RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', '')
    If @error > 0 Then
        $NETInstalled = 0
    Else
        $NETInstalled = 1
    EndIf
    Return $NETInstalled
EndFunc   ;==>_CheckDotNet4

this script is exceedingly long and cumbersome, i guess it's because it is written for an older version of AutoIt. for example, it defines its own function _CommandExecute(), which is now built-in to AutoIt, going by the name of RunWait(). it also needlessly includes a bunch of functions related to array management, which bloats the script.

however, the script is still capable of running in current AutoIt version without modification (i'm using 3.3.10.2)

for non-programmers, the major advantage of AutoIt is that (for the most part) it is written in English, rather than Computerish, so it is quite easy to read and understand. the script performs 4 operations:

  1) check if .NET is already installed

  2) install dependencies

  3) install .NET

  4) verify the installation

if you want to skip step (2), and step (3) is basically the command line i suggested above, then your script is left only with steps (1), & (4), which are actually the same operation, embodied in the function _CheckDotNet4(). when you get a bit more experienced with AutoIt, you'd probably prefer to rewrite the entire thing in like 10 lines; but for now, check closely the part of the script which begins with the line:

; Check to see if Windows Imaging Component is installed and install if not 

the following part is actually a single statement of If...Else...EndIf, except that it is spread over 20 lines.

see the starting If in the following line (line 19)? find the corresponding EndIf according to indentation (hint: line 40), and this is what you need to remove.

try it, let us know if you need further assistance. you'd probably want to have better error handling and reporting, but that's for later. 

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Thank you so much for your reply! I have gleaned some good information from your post.

So, let me start with your first question as to why I am not simply running this from the command line. If one were to simply need to install and not worry about whether or not .NET 4 was already installed, then this would work wonderfully, However, if .NET 4 is already installed, by executing this again, .NET 4 will actually reinstall. This requires additional time which is not necessary.

Originally, I set out to find a VBscript to handle the task of checking to see if .NET 4 was installed and if not install it. That was fairly easy to accomplish. Yet, the VBscript didn't work out exactly the way I wanted it to... Just so you are aware, I am pretty new to scripting in general so I am sure that the script I used could have been modified to work as I wanted it to but in the end, I just didn't have the patience to try and figure it out. So, I kept searching... and then I stumbled on this wonderful script that actually has a WAITING method implemented... so the script does not complete until either .NET is installed or there is some kind of error or it finds that it is already installed. 

The fact that you can turn a AutoIT script into a .exe is wonderful! I honestly am greatly motivated to learn AutoIT just because of this reason alone.

Anyways, based on your response, I will attempt to execute the script from the command prompt and see if I can get any additional information from that.

Thank you for the tip on how to properly put CODE inside these posts. When I had posted the code I did not like how it looked as it made it much harder to read. So, when I post code, I will follow your advice on how to properly post the code to make it more legible.

Because I am so new to scripting... the only scripting I have ever done was creating .bat files... VBscripting, PowerShell scripting, and now this AutoIT scripting is all new to me but I am convinced that I need to become more proficient with all three. I can't become proficient until I actually LEARN them.

AutoIT being free and seeing how awesome it is... it just seems like a obvious win win to me to learn.

I will post back once I have dug deeper into this.

And oh yeah, when I compiled I did it with the dotNetFx40_Full_x86_x64.exe included in the directory. I figured that out simply because at first when I ran the compile, I received and error message telling me that the file was missing... along with the other files too...

If your response is an indicator of the community support behind using AutoIT, that is awesome!!

Link to comment
Share on other sites

I have run the script and it is indeed working. However, the original .exe file, that I got from the author's website, actually shows text messages correlating to the code:

ConsoleWrite('.NET Framework 4.0 Extended already installed, terminating operation' & @CRLF)

Yet, when I run the script, these console writes are not occurring... So, the script executes and basically completes without having the 'waiting' that the original .exe has in it... along with the ConsoleWrite messages appearing...

Maybe the author added some additional coding and forgot to include that in the .au3 script?

Any idea or advice on how to get the ConsoleWrite to actually work?

Thanks in advance,

Michael

Link to comment
Share on other sites

i compiled the script to exe with all the includes, run it from the command prompt (not by double-click the exe), and i get the console message:

post-47848-0-32225700-1410633738_thumb.p

i advise you run the script from SciTe before compilation, and see that you get the console message (in the bottom pane).

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

I did as you say and ran the script from SciTe and I do in fact receive the read out:

 

>"C:Program Files (x86)AutoIt3SciTE..autoit3.exe" /ErrorStdOut "C:dotNetFx4 (3)dotNetFx4.au3"    

.NET Framework 4.0 Extended already installed, terminating operation
>Exit code: 0    Time: 0.06196

 

However, when I Compile the script and run the .exe from the command prompt, the program runs but again, I am not getting the messages, ".NET Framework 4.0 Extended already installed, terminating operation"

Maybe I am missing something when compiling? While having SciTE-Lite open and the script dotNetFx4.au3 open, and the required file present dotNetFx40_Full_x86_x64.exe, I then click Tools >> Compile which then creates the dotNetFx4.exe file. I then run same file at the command prompt and again, I receive no output messages as in the ConsoleWrite messages...

I did edit the original script to include only the .NET 4 portion. This is what I am using:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\..\Images\CSO.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.6.1
    Author:         Simon McBryde

    Script Function:
    Install .NET Framework 4.0

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

#include <array.au3>

; Check to see if .NET Framework 4.0 is already installed and quit if it is
If _CheckDotNet4() = 1 Then
    ConsoleWrite('.NET Framework 4.0 Extended already installed, terminating operation' & @CRLF)
    Exit 0
EndIf

; Install .NET Framework 4.0
FileInstall('dotNetFx40_Full_x86_x64.exe', @ScriptDir & '\')
_CommandExecute('"' & @ScriptDir & '\dotNetFx40_Full_x86_x64.exe" /q /norestart')

; Check to see if .NET Framework 4.0 installation was successful
If _CheckDotNet4() = 1 Then
    ConsoleWrite('.NET Framework 4.0 Extended installed successfully' & @CRLF)
Else
    ConsoleWrite('.NET Framework 4.0 Extended not present after attempted installation' & @CRLF)
    Exit 1
EndIf

Exit 0

Func _CommandExecute($Command)
    Local $Pid = Run(@ComSpec & ' /c ' & $Command, '', @SW_HIDE)
    ProcessWaitClose($Pid)
EndFunc   ;==>_CommandExecute

Func _CheckDotNet4()
    Local $NETInstalled
    RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', '')
    If @error > 0 Then
        $NETInstalled = 0
    Else
        $NETInstalled = 1
    EndIf
    Return $NETInstalled
EndFunc   ;==>_CheckDotNet4

Any additional thoughts on what I might be doing wrong?

Thank you in advance,

MichaelSO

Link to comment
Share on other sites

here is a quick error checking - change the 1st part of the script to this, and see what happens:

; Check to see if .NET Framework 4.0 is already installed and quit if it is
If _CheckDotNet4() = 1 Then
    $nCount=ConsoleWrite('.NET Framework 4.0 Extended already installed, terminating operation' & @CRLF)
    MsgBox(0,'Hi!','I just wrote to the console '&$nCount&' characters.')
    Exit 0
EndIf

this checks the result of ConsoleWrite - see the help file for what it means. and it displays a message box accordingly.

it may be the console message is not produced because when compiled, the function - for some obscure reason - does not detect properly the registry value indicating that .NET is already installed, and tries to continue the script, and fails later without indication. to check that, see this:

; Check to see if .NET Framework 4.0 is already installed and quit if it is
If _CheckDotNet4() = 1 Then
    $nCount=ConsoleWrite('.NET Framework 4.0 Extended already installed, terminating operation' & @CRLF)
    MsgBox(0,'Hi!','I just wrote to the console '&$nCount&' characters.')
    Exit 0
Else
    $nCount=ConsoleWrite('.NET Framework 4.0 Extended is NOT already installed, operation will proceed' & @CRLF)
    MsgBox(0,'Hi!','I just wrote to the console '&$nCount&' characters.')
EndIf

as i said earlier, AutoIt is English, so it's quite easy to understand that piece of code. anyway, ask if something is not clear enough.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

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...