setup factory打包依赖.net 4.6.1和localdb

一、基本配置

1、打开setup factory,新建项目。将文件拖入其中。

2、设置会话变量、背景、使用系统等等设置。

 3、右击项目启动文件.exe,配置安装目录,快捷方式、图标等。

二、配置安装界面。

 在安装后的目录中输入检测注册表中的localdb是否安装。然后执行安装,安装后启动项目。(当然这部分也可以放在依赖中)

 

1
2
3
4
5
6
7
8
9
10
-- localdb Reg Key
    local DotNet_Key = "SOFTWARE\\Microsoft\\Microsoft SQL Server Local DB\\Installed Versions";
    --Check to see if the registry key exists
    local DotNet_Registry = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, DotNet_Key);
         
    if (DotNet_Registry == false) then
        result = Shell.Execute(SessionVar.Expand("%AppFolder%\\DBSetup\\SqlLocalDB_2016_en.msi"), "open", "", "", SW_SHOWNORMAL, true);
    else -- The key does exist
    end
result = Shell.Execute(SessionVar.Expand("%AppFolder%\\GTRAsenwarePanel.exe"), "open", "", "%AppFolder%", SW_SHOWNORMAL, false);

  

 

三、 配置依赖4.6.1

 

 先选择.net4,然后在此基础上进行修改即可。

 

 1、信息,名称随便修改

复制代码
Installs Microsoft .NET Framework 4.6.1 onto the user's system.      Includes the .NET installer in the setup executable.

Applications and controls written for the .NET Framework version 4.6.1 require the .NET Framework Redistributable Package version 4.6.1 to be installed on the computer where the application or control runs.      The .NET Framework redistributable package is available as a stand-alone executable file, NDP461-KB3102436-x86-x64-AllOS-ENU.exe.      When this dependency module is included in your setup, it detects and installs the .NET Framework redistributable.

This module is supported on both 32-bit (x86) and 64-bit (x64) architectures of the following operating systems:
Windows 7 SP1£¨x86 and x64£?
Windows 8£¨x86 and x64£?
Windows 8.1£¨x86 and x64£?
Windows 10
Windows Server 2008 R2 SP1 (x64)
Windows Server 2012 (x64)
Windows Server 2012 R2 (x64)
复制代码

2、检测

检测功能名称:isDotNet_Installed

复制代码
function isDotNet_Installed()
    -- .Net 461 Reg Key
    local DotNet_Key = "SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full";
    --Check to see if the registry key exists
    local DotNet_Registry = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, DotNet_Key);
        
    if (DotNet_Registry == false) then
        -- The registry key does not exist
        -- Run the .NET Installation script
        -- Output to the log file that .NET could not be found, so it will be installed.
        SetupData.WriteToLogFile("Info\t.NET 4 Module: No version of .NET 4.6.1 was found. .NET 4.6.1 will be installed.\r\n", true);
        return false;
    else -- The key does exist

        -- Get the .NET install success value from the registry
        local DotNet_Install_Success = Registry.GetValue(HKEY_LOCAL_MACHINE, DotNet_Key, "Install", true);

        if (DotNet_Install_Success == "1") then
            -- Check the version key.
            local DotNet_Install_Version = Registry.GetValue(HKEY_LOCAL_MACHINE, DotNet_Key, "Version", true);            
            
            -- Compare the returned value against the needed value
            Compare = String.CompareFileVersions(DotNet_Install_Version, "4.6.01055");
                            
            if (Compare == 0 or Compare == 1) then
                -- .NET version 4 is installed already
                SetupData.WriteToLogFile("Info\t.NET 4.6.1 Module: .NET version 4.6.1 is installed already\r\n", true);
                return true;
            else     
                SetupData.WriteToLogFile("Info\t.NET 4.6.1 Module: A lesser version of .NET 4.6.1 was found on the users system.\r\n", true);
                return false;
            end
        else
            -- The success value wasn't found
            -- Run the .NET Installation script
            -- Output to the log file that .NET could not be found, so it will be installed.
            SetupData.WriteToLogFile("Info\t.NET 4.6.1 Module: No version of .NET 4.6.1 was found. .NET 4.6.1 will be installed.\r\n", true);
            return false;
        end
    end
    return false;
end
复制代码

    3、installation,检测系统

检测系统后检测isDotNet_Installed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
-- Check to see if this is a valid operating system for .NET 4
function isValidDotNet4OS()
    SetupData.WriteToLogFile("Info\t.NET 4 Module: Entering compatible OS detection.\r\n",true);
 
    local tblOSInfo = System.GetOSVersionInfo();
    local strOSName = System.GetOSName();
    local b64BitOs = System.Is64BitOS();
 
     
    -- Check Windows XP SP3
    if (tblOSInfo.MajorVersion == "5") and (tblOSInfo.MinorVersion == "1") then
        -- Check service pack:
        if (tblOSInfo.ServicePackMajor < 3) then
            SetupData.WriteToLogFile("Info\t.NET 4 Module: Windows XP SP3+ required.\r\n",true);
            return false;
        else
            -- Windows XP SP3+ acceptable
            return true;
        end
    end
     
    -- Check Windows Server 2003 SP2/Windows XP Professional x64 Edition SP2
    if (tblOSInfo.MajorVersion == "5") and (tblOSInfo.MinorVersion == "2") then
        -- Check service pack:
        if (tblOSInfo.ServicePackMajor < 2) then
            SetupData.WriteToLogFile("Info\t.NET 4 Module: Windows Server 2003 SP2+/Windows XP Professional x64 Edition SP2+ required.\r\n",true);
            return false;
        else
            -- Windows Server 2003 SP2+/Windows XP Professional x64 Edition SP2+ acceptable
            return true;
        end
    end
     
    -- Check Windows Vista SP1
    if ((tblOSInfo.MajorVersion == "6") and (tblOSInfo.MinorVersion == "0") and (tblOSInfo.ProductType == 1)) then
        -- Check service pack:
        if (tblOSInfo.ServicePackMajor < 1) then
            SetupData.WriteToLogFile("Info\t.NET 4 Module: Windows Vista SP1+ required.\r\n",true);
            return false;
        else
            -- Windows Vista SP1+ acceptable
            return true;
        end
    end
     
    -- Check Windows Server 2008
    if ((tblOSInfo.MajorVersion == "6") and (tblOSInfo.MinorVersion == "0") and (tblOSInfo.ProductType ~= 1)) then
        return true;
    end
     
    -- Check Windows 7 / Windows Server 2008 R2
    if ((tblOSInfo.MajorVersion == "6") and (tblOSInfo.MinorVersion == "1")) then
        return true;
    end
         
    return false;
end
 
 
if(not isDotNet_Installed())then
    -- Variables used in the installation actions:
    local strMessage = [[Setup has detected that your Microsoft .NET run-time files are out of date.
Click OK to install this technology now or Cancel to abort the setup.]];
    local strDialogTitle = "Technology Required";
    local bShowUserPrompt = true; -- set this to true to ask user whether to install the module
    local bRunInstallFile = true; -- The default of whether or not to run the setup
    local bRequirementFail = false;
    local tbRequirementFailStrings = {};
    local strAbortQuestion = [[
 
Due to this requirement failure, it is recommended that you abort the install.
 
Click OK to abort the setup, or Cancel to continue with the application install.]];
    local strRequirementString = [[.NET 4 cannot be installed due to the following requirements:
 
]];
    local strRuntimeSupportFolder = SessionVar.Expand("%TempLaunchFolder%\\dotnet461");
    local strExtractInstallerToPath = strRuntimeSupportFolder.."\\NDP461-KB3102436-x86-x64-AllOS-ENU.exe";
    local strMessageFail = "";
    local _NeedsReboot = false;
    local strCmdArgs = "";
    local bSilentMode = false; -- Should this be silent?;
    local bVital = true; -- Is .Net 4 vital?
     
    -- Output to the log that the .NET installation script has started.
    SetupData.WriteToLogFile("Success\t.NET 4 Module: Installation script started.\r\n", true);
     
    ------------------------------------------------------------------------------------------------------------
    ---- Requires Internet Explorer 6.0 SP1 or greater  (6.00.2800.1106)                                    ----
    ------------------------------------------------------------------------------------------------------------   
     
    -- Read the version of Internet Explorer (if installed).
    strIEVersion = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Internet Explorer", "Version", false);
     
    -- If Internet Explorer Version is less than 6.00.2800.1106 , or cannot be found,
    -- set the failure variable and failure string table.
    if ((String.CompareFileVersions(strIEVersion, "6.00.2800.1106")== -1) or (strIEVersion == "")) then
        bRequirementFail = true;
        strTemp = "- .NET 4 requires Internet Explorer version 6.0 SP1 or greater.";
        Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
    end
     
    ------------------------------------------------------------------------------------------------------------
    ---- Requires Admin permissions                                                                         ----
    ------------------------------------------------------------------------------------------------------------
     
    -- Check if the user is logged in with administrative permissions.
    -- If the user doesn't have admin permissions, set the failure variable
    -- and failure string table.
    tbUserInfo = System.GetUserInfo();
    if (tbUserInfo ~= nil) then
        if (not tbUserInfo.IsAdmin) then
            bRequirementFail = true;
            strTemp ="- You do not have the required administrative permissions to install .NET 4.";
            Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
        end
    end
     
    ------------------------------------------------------------------------------------------------------------
    ---- Requires MSI 3.1                                                               ----
    ------------------------------------------------------------------------------------------------------------
    -- Get the operating system name.
    local strOSName = System.GetOSName();
     
    local strMSIVersion = MSI.GetMSIVersion();
     
 
    -- need MSI 3.1
    if (String.CompareFileVersions(strMSIVersion,"3.1.4000.2435") == -1) or (not strMSIVersion) then
        -- MSI 3.1 is not installed
        bRequirementFail = true;
        strTemp = "- The .NET 4 runtime module requires Windows Installer 3.1. Please install this technology then run the setup again.";
        Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
    end
     
    ------------------------------------------------------------------------------------------------------------
    ---- Operating System Check       
    --Windows Server 2003;  (SP2)
    --Windows XP            (SP3) 
    --Windows Vista         (SP1)
    --Windows Server 2008
    --Windows 7
    --Windows Server 2008 R2                                                
    ------------------------------------------------------------------------------------------------------------
     
    -- Check if OS is valid.
    if (not isValidDotNet4OS()) then
        bRequirementFail = true;
        --.NET 4 isn't supported on the OS that was detected.
        strTemp = "- .NET 4 cannot be installed on this operating system. Requires Windows XP SP3, Windows Server 2003 SP2, Windows XP Professional x64 Edition SP2, Windows Server 2008, Windows Vista SP1, Windows Server 2008 R2 or Windows 7.";
        Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
    end
 
     
    -- Check if the dialog should be displayed asking whether or not they want to install the module.
    if(bShowUserPrompt)then
        local nDialogResult = Dialog.Message(strDialogTitle,strMessage,MB_OKCANCEL,MB_ICONEXCLAMATION);
        if(nDialogResult == IDOK)then
            -- The user chose to install the module.
            bRunInstallFile = true;
        else
            -- The user chose not to install the module.
            bRunInstallFile = false;
        end
    end
     
    if (not bRequirementFail) then
        -- Check if the user wants to install the runtime.
        if(bRunInstallFile)then
            -- The following are command line options that can be used when launching the install file dotNetFx40_Full_x86_x64.exe.
            -- /q  - Sets quiet mode.
            -- /norestart - Prevents the Setup program from rebooting automatically. (Redistributable installer returns ERROR_SUCCESS_REBOOT_REQUIRED (3010) if a reboot is required.)
            -- /repair - Repairs all .NET Framework 4 components that are installed.
            -- /LCID - Installs the language pack specified by lcid and forces the displayed UI to be shown in that language (unless in quiet mode).
            -- /passive - Displays the progress bar to indicate that installation is in progress, but does not display any prompts or errors to the user. Error handling must be handled by the setup program.
            -- /showfinalerror - Sets passive mode, but displays errors if the installation is not successful. This option requires user interaction if the installation is not successful.
            -- /promptrestart - In passive mode, if the setup program requires a reboot to complete, it prompts the user. This option requires user interaction if a reboot is required.
            -- /CEIPConsent - Overwrites the default behavior and sends anonymous feedback to Microsoft to improve future deployment experiences. This option can be used only if the application Setup program prompts for consent and if the user grants permission to send anonymous feedback to Microsoft.
            -- /chainingpackagePackageName - Specifies the name of the executable that is doing the chaining. This information is sent to Microsoft as anonymous feedback to help improve future deployment experiences. If the package name includes spaces, use double quotation marks as delimiters; for example: /chainingpackage "Chaining Product". For an example of a chaining package, see Getting Progress Information from an Installation Package in the MSDN Library.
            --/? - Displays this list of options.
 
 
            if (bSilentMode) then
                -- Passing quite mode, and no restart.
                strCmdArgs = strCmdArgs.."/q /norestart ";
            else
                -- Passing no restart.
                strCmdArgs = strCmdArgs.."/norestart ";
            end
 
            -- Output to the log that the .NET installation is being launched.
            SetupData.WriteToLogFile("Info\t.NET 4 Module: .NET 4 installation file "..strExtractInstallerToPath.." is being launched.\r\n");
            local nResult = File.Run(strExtractInstallerToPath, strCmdArgs, "", SW_SHOWNORMAL, true);
                if ((nResult == 3010) or (nResult == 1614)) then
                    -- .NET install indicated that it needs reboot to be complete
                    -- Set Setup Factory's reboot variable so that the reboot is just
                    -- performed at the end of the install.
                    _NeedsReboot = true;
                elseif (nResult == 1602) then
                    -- The user canceled the setup program.
                    strMessageFail = [[You have cancelled the installation for .NET 4. It is not recommended that you continue with the setup.
 
Click OK to abort the setup, or Cancel to continue with the application install.]];
                elseif (nResult == 1603) then
                    -- A fatal error occurred during installation.
                    strMessageFail = [[A fatal error occurred during installation of the .NET 4 runtime. It is not recommended that you continue with the setup.
 
Click OK to abort the setup, or Cancel to continue with the application install.]];
                elseif (nResult == 5100) then
                    -- The user's computer does not meet system requirements.
                    strMessageFail = [[This computer does not meet the system requirements for the .NET 4 installation. It is not recommended that you continue with the setup.
 
Click OK to abort the setup, or Cancel to continue with the application install.]];
                elseif (nResult == 5101) then
                    -- Internal state failure.
                    strMessageFail = [[An internal state failure occurred in the .NET 4 installation. It is not recommended that you continue with the setup.
                     
Click OK to abort the setup, or Cancel to continue with the application install.]];
                elseif (nResult == 0) then
                    -- The .NET setup was successful, so do nothing.
                else
                    -- The .NET setup program was not completed successfully.
                    strMessageFail = [[An unknown error occurred during the installation of the .NET 4 runtime. It is not recommended that you continue with the setup.
 
Click OK to abort the setup, or Cancel to continue with the application install.]];
                end
 
                -- Check to see if an error message was generated.
                if (strMessageFail ~= "") then
                    -- Display the error notification dialog.
                     
                    -- Output to the log .NET error message.
                    SetupData.WriteToLogFile("Error\t.NET 4 Module: Dialog error shown- "..strMessageFail..".\r\n");
                     
                    if (bShowUserPrompt) then
                        nDialogResult = Dialog.Message(".NET 4 Installation" ,strMessageFail,MB_OKCANCEL,MB_ICONEXCLAMATION);
                        if (nDialogResult == IDOK) then
                            bAbortInstall = true;
                        end
                    end
                end
         
            -- Delete the run time installer file and remove the temp folder
            File.Delete(strExtractInstallerToPath);
            Folder.Delete(strRuntimeSupportFolder);
             
            -- If the user chose to abort the install after the failure of .NET install, exit the setup.
            if (bAbortInstall) then
                -- Output to the log that the user chose to abort the setup after .NET failure.
                SetupData.WriteToLogFile("Error\t.NET 4 Module: User chose to abort setup after .NET failure. Exiting setup.\r\n");
                Application.Exit(EXIT_REASON_USER_ABORTED);
            end
             
        else
            -- The user chose not to install the runtime so delete the run time installer file,
            -- remove the temp folder and then exit the setup.
             
            -- Output to the log that the user chose to abort the setup.
            SetupData.WriteToLogFile("Error\t.NET 4 Module: User chose to abort setup. Exiting setup.\r\n");
             
            File.Delete(strExtractInstallerToPath);
            Folder.Delete(strRuntimeSupportFolder);
            if bVital then
                Application.Exit(EXIT_REASON_USER_ABORTED);
            else
                Application.ExitScript();
            end
        end
    else
    -- A requirement failed
     
        -- If the user didn't cancel...
        if (bRunInstallFile) then
            -- One or more of the requirements failed. Notify the user and ask if they wish
            -- to abort the installation.
            strFullErrorString = Table.Concat(tbRequirementFailStrings, "\r\n", 1, TABLE_ALL);
            nDialogResult = Dialog.Message("Notice", strRequirementString..strFullErrorString..strAbortQuestion, MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1);
             
            -- Output the requirement failure string to the log.
            SetupData.WriteToLogFile("Error\t.NET 4 Module: Requirement failure dialog: "..strFullErrorString.."\r\n");
             
            -- Delete the runtime installer file and remove the temp folder
            File.Delete(strExtractInstallerToPath);
            Folder.Delete(strRuntimeSupportFolder);
             
            -- The user chose to abort the install due to the requirement failure of .NET.
            if (nDialogResult == IDOK) then
             
                -- Output to the log that the user chose to abort the install due to requirement failure.
                SetupData.WriteToLogFile("Error\t.NET 4 Module: User aborted setup due to requirement failure. Exiting setup.\r\n");
             
                -- Abort the install.
                Application.Exit(EXIT_REASON_USER_ABORTED);
            end
        else
            -- The user chose not to install the runtime so delete the run time installer file,
            -- remove the temp folder and then exit the setup.
             
            -- Output to the log that the user chose to abort the setup.
            SetupData.WriteToLogFile("Error\t.NET 4 Module: User chose to abort setup. Exiting setup.\r\n");
             
            File.Delete(strExtractInstallerToPath);
            Folder.Delete(strRuntimeSupportFolder);
             
            if bVital then
                Application.Exit(EXIT_REASON_USER_ABORTED);
            else
                Application.ExitScript();
            end
         
        end
    end
     
    -- If a reboot was needed by .NET, notify the user that they must reboot
    -- before continuing with the install
     
    -- NOTE: If you would always like to force the user to reboot, comment out the "if (_NeedsReboot) then" condition below.
     
    local strRebootMessage = [[A reboot is required to continue with the installation. After rebooting, re-run the installation.
 
Click OK to reboot now, or Cancel to reboot later.]];
    if (_NeedsReboot) then
        nDialogResult = Dialog.Message("Notice", strRebootMessage, MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1);
         
        -- Output to the log that a reboot is required by the .NET setup.
        SetupData.WriteToLogFile("Info\t.NET 4 Module: .NET 4 detected that a reboot is required.\r\n");
        -- Check if the uer wanted to reboot now.
        if (nDialogResult == IDOK) then
         
            -- NOTE:  If you would not like the install to relaunch itself after the reboot,
            -- uncomment the following block of code.
            -- Re-run the installation after the reboot.
             
            -- File.RunOnReboot(_SourceFilename, "");
         
            -- Output to the log that a reboot will be performed.
            SetupData.WriteToLogFile("Info\t.NET 4 Module: A reboot will be performed.\r\n");
            -- Reboot the user's system.
            System.Reboot();
        else
            -- Output to the log that the user chose to reboot later and abort the setup.
            SetupData.WriteToLogFile("Info\t.NET 4 Module: User chose to reboot later. Exiting setup.\r\n");
            -- Abort the install.
            Application.Exit(EXIT_REASON_USER_ABORTED);
        end
    end
    -- Output to the log that the installation script has finished.
    SetupData.WriteToLogFile("Success\t.NET 4 Module: Installation script finished.\r\n");
end
 
-- Check to see if this is a valid operating system for .NET 4
function isValidDotNet4OS()
    SetupData.WriteToLogFile("Info\t.NET 4 Module: Entering compatible OS detection.\r\n",true);
 
    local tblOSInfo = System.GetOSVersionInfo();
    local strOSName = System.GetOSName();
    local b64BitOs = System.Is64BitOS();
 
     
    -- Check Windows XP SP3
    if (tblOSInfo.MajorVersion == "5") and (tblOSInfo.MinorVersion == "1") then
        -- Check service pack:
        if (tblOSInfo.ServicePackMajor < 3) then
            SetupData.WriteToLogFile("Info\t.NET 4 Module: Windows XP SP3+ required.\r\n",true);
            return false;
        else
            -- Windows XP SP3+ acceptable
            return true;
        end
    end
     
    -- Check Windows Server 2003 SP2/Windows XP Professional x64 Edition SP2
    if (tblOSInfo.MajorVersion == "5") and (tblOSInfo.MinorVersion == "2") then
        -- Check service pack:
        if (tblOSInfo.ServicePackMajor < 2) then
            SetupData.WriteToLogFile("Info\t.NET 4 Module: Windows Server 2003 SP2+/Windows XP Professional x64 Edition SP2+ required.\r\n",true);
            return false;
        else
            -- Windows Server 2003 SP2+/Windows XP Professional x64 Edition SP2+ acceptable
            return true;
        end
    end
     
    -- Check Windows Vista SP1
    if ((tblOSInfo.MajorVersion == "6") and (tblOSInfo.MinorVersion == "0") and (tblOSInfo.ProductType == 1)) then
        -- Check service pack:
        if (tblOSInfo.ServicePackMajor < 1) then
            SetupData.WriteToLogFile("Info\t.NET 4 Module: Windows Vista SP1+ required.\r\n",true);
            return false;
        else
            -- Windows Vista SP1+ acceptable
            return true;
        end
    end
     
    -- Check Windows Server 2008
    if ((tblOSInfo.MajorVersion == "6") and (tblOSInfo.MinorVersion == "0") and (tblOSInfo.ProductType ~= 1)) then
        return true;
    end
     
    -- Check Windows 7 / Windows Server 2008 R2
    if ((tblOSInfo.MajorVersion == "6") and (tblOSInfo.MinorVersion == "1")) then
        return true;
    end
         
    return false;
end
 
 
if(not isDotNet_Installed())then
    -- Variables used in the installation actions:
    local strMessage = [[Setup has detected that your Microsoft .NET run-time files are out of date.
Click OK to install this technology now or Cancel to abort the setup.]];
    local strDialogTitle = "Technology Required";
    local bShowUserPrompt = true; -- set this to true to ask user whether to install the module
    local bRunInstallFile = true; -- The default of whether or not to run the setup
    local bRequirementFail = false;
    local tbRequirementFailStrings = {};
    local strAbortQuestion = [[
 
Due to this requirement failure, it is recommended that you abort the install.
 
Click OK to abort the setup, or Cancel to continue with the application install.]];
    local strRequirementString = [[.NET 4 cannot be installed due to the following requirements:
 
]];
    local strRuntimeSupportFolder = SessionVar.Expand("%TempLaunchFolder%\\dotnet461");
    local strExtractInstallerToPath = strRuntimeSupportFolder.."\\NDP461-KB3102436-x86-x64-AllOS-ENU.exe";
    local strMessageFail = "";
    local _NeedsReboot = false;
    local strCmdArgs = "";
    local bSilentMode = false; -- Should this be silent?;
    local bVital = true; -- Is .Net 4 vital?
     
    -- Output to the log that the .NET installation script has started.
    SetupData.WriteToLogFile("Success\t.NET 4 Module: Installation script started.\r\n", true);
     
    ------------------------------------------------------------------------------------------------------------
    ---- Requires Internet Explorer 6.0 SP1 or greater  (6.00.2800.1106)                                    ----
    ------------------------------------------------------------------------------------------------------------   
     
    -- Read the version of Internet Explorer (if installed).
    strIEVersion = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Internet Explorer", "Version", false);
     
    -- If Internet Explorer Version is less than 6.00.2800.1106 , or cannot be found,
    -- set the failure variable and failure string table.
    if ((String.CompareFileVersions(strIEVersion, "6.00.2800.1106")== -1) or (strIEVersion == "")) then
        bRequirementFail = true;
        strTemp = "- .NET 4 requires Internet Explorer version 6.0 SP1 or greater.";
        Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
    end
     
    ------------------------------------------------------------------------------------------------------------
    ---- Requires Admin permissions                                                                         ----
    ------------------------------------------------------------------------------------------------------------
     
    -- Check if the user is logged in with administrative permissions.
    -- If the user doesn't have admin permissions, set the failure variable
    -- and failure string table.
    tbUserInfo = System.GetUserInfo();
    if (tbUserInfo ~= nil) then
        if (not tbUserInfo.IsAdmin) then
            bRequirementFail = true;
            strTemp ="- You do not have the required administrative permissions to install .NET 4.";
            Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
        end
    end
     
    ------------------------------------------------------------------------------------------------------------
    ---- Requires MSI 3.1                                                               ----
    ------------------------------------------------------------------------------------------------------------
    -- Get the operating system name.
    local strOSName = System.GetOSName();
     
    local strMSIVersion = MSI.GetMSIVersion();
     
 
    -- need MSI 3.1
    if (String.CompareFileVersions(strMSIVersion,"3.1.4000.2435") == -1) or (not strMSIVersion) then
        -- MSI 3.1 is not installed
        bRequirementFail = true;
        strTemp = "- The .NET 4 runtime module requires Windows Installer 3.1. Please install this technology then run the setup again.";
        Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
    end
     
    ------------------------------------------------------------------------------------------------------------
    ---- Operating System Check       
    --Windows Server 2003;  (SP2)
    --Windows XP            (SP3) 
    --Windows Vista         (SP1)
    --Windows Server 2008
    --Windows 7
    --Windows Server 2008 R2                                                
    ------------------------------------------------------------------------------------------------------------
     
    -- Check if OS is valid.
    if (not isValidDotNet4OS()) then
        bRequirementFail = true;
        --.NET 4 isn't supported on the OS that was detected.
        strTemp = "- .NET 4 cannot be installed on this operating system. Requires Windows XP SP3, Windows Server 2003 SP2, Windows XP Professional x64 Edition SP2, Windows Server 2008, Windows Vista SP1, Windows Server 2008 R2 or Windows 7.";
        Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
    end
 
     
    -- Check if the dialog should be displayed asking whether or not they want to install the module.
    if(bShowUserPrompt)then
        local nDialogResult = Dialog.Message(strDialogTitle,strMessage,MB_OKCANCEL,MB_ICONEXCLAMATION);
        if(nDialogResult == IDOK)then
            -- The user chose to install the module.
            bRunInstallFile = true;
        else
            -- The user chose not to install the module.
            bRunInstallFile = false;
        end
    end
     
    if (not bRequirementFail) then
        -- Check if the user wants to install the runtime.
        if(bRunInstallFile)then
            -- The following are command line options that can be used when launching the install file dotNetFx40_Full_x86_x64.exe.
            -- /q  - Sets quiet mode.
            -- /norestart - Prevents the Setup program from rebooting automatically. (Redistributable installer returns ERROR_SUCCESS_REBOOT_REQUIRED (3010) if a reboot is required.)
            -- /repair - Repairs all .NET Framework 4 components that are installed.
            -- /LCID - Installs the language pack specified by lcid and forces the displayed UI to be shown in that language (unless in quiet mode).
            -- /passive - Displays the progress bar to indicate that installation is in progress, but does not display any prompts or errors to the user. Error handling must be handled by the setup program.
            -- /showfinalerror - Sets passive mode, but displays errors if the installation is not successful. This option requires user interaction if the installation is not successful.
            -- /promptrestart - In passive mode, if the setup program requires a reboot to complete, it prompts the user. This option requires user interaction if a reboot is required.
            -- /CEIPConsent - Overwrites the default behavior and sends anonymous feedback to Microsoft to improve future deployment experiences. This option can be used only if the application Setup program prompts for consent and if the user grants permission to send anonymous feedback to Microsoft.
            -- /chainingpackagePackageName - Specifies the name of the executable that is doing the chaining. This information is sent to Microsoft as anonymous feedback to help improve future deployment experiences. If the package name includes spaces, use double quotation marks as delimiters; for example: /chainingpackage "Chaining Product". For an example of a chaining package, see Getting Progress Information from an Installation Package in the MSDN Library.
            --/? - Displays this list of options.
 
 
            if (bSilentMode) then
                -- Passing quite mode, and no restart.
                strCmdArgs = strCmdArgs.."/q /norestart ";
            else
                -- Passing no restart.
                strCmdArgs = strCmdArgs.."/norestart ";
            end
 
            -- Output to the log that the .NET installation is being launched.
            SetupData.WriteToLogFile("Info\t.NET 4 Module: .NET 4 installation file "..strExtractInstallerToPath.." is being launched.\r\n");
            local nResult = File.Run(strExtractInstallerToPath, strCmdArgs, "", SW_SHOWNORMAL, true);
                if ((nResult == 3010) or (nResult == 1614)) then
                    -- .NET install indicated that it needs reboot to be complete
                    -- Set Setup Factory's reboot variable so that the reboot is just
                    -- performed at the end of the install.
                    _NeedsReboot = true;
                elseif (nResult == 1602) then
                    -- The user canceled the setup program.
                    strMessageFail = [[You have cancelled the installation for .NET 4. It is not recommended that you continue with the setup.
 
Click OK to abort the setup, or Cancel to continue with the application install.]];
                elseif (nResult == 1603) then
                    -- A fatal error occurred during installation.
                    strMessageFail = [[A fatal error occurred during installation of the .NET 4 runtime. It is not recommended that you continue with the setup.
 
Click OK to abort the setup, or Cancel to continue with the application install.]];
                elseif (nResult == 5100) then
                    -- The user's computer does not meet system requirements.
                    strMessageFail = [[This computer does not meet the system requirements for the .NET 4 installation. It is not recommended that you continue with the setup.
 
Click OK to abort the setup, or Cancel to continue with the application install.]];
                elseif (nResult == 5101) then
                    -- Internal state failure.
                    strMessageFail = [[An internal state failure occurred in the .NET 4 installation. It is not recommended that you continue with the setup.
                     
Click OK to abort the setup, or Cancel to continue with the application install.]];
                elseif (nResult == 0) then
                    -- The .NET setup was successful, so do nothing.
                else
                    -- The .NET setup program was not completed successfully.
                    strMessageFail = [[An unknown error occurred during the installation of the .NET 4 runtime. It is not recommended that you continue with the setup.
 
Click OK to abort the setup, or Cancel to continue with the application install.]];
                end
 
                -- Check to see if an error message was generated.
                if (strMessageFail ~= "") then
                    -- Display the error notification dialog.
                     
                    -- Output to the log .NET error message.
                    SetupData.WriteToLogFile("Error\t.NET 4 Module: Dialog error shown- "..strMessageFail..".\r\n");
                     
                    if (bShowUserPrompt) then
                        nDialogResult = Dialog.Message(".NET 4 Installation" ,strMessageFail,MB_OKCANCEL,MB_ICONEXCLAMATION);
                        if (nDialogResult == IDOK) then
                            bAbortInstall = true;
                        end
                    end
                end
         
            -- Delete the run time installer file and remove the temp folder
            File.Delete(strExtractInstallerToPath);
            Folder.Delete(strRuntimeSupportFolder);
             
            -- If the user chose to abort the install after the failure of .NET install, exit the setup.
            if (bAbortInstall) then
                -- Output to the log that the user chose to abort the setup after .NET failure.
                SetupData.WriteToLogFile("Error\t.NET 4 Module: User chose to abort setup after .NET failure. Exiting setup.\r\n");
                Application.Exit(EXIT_REASON_USER_ABORTED);
            end
             
        else
            -- The user chose not to install the runtime so delete the run time installer file,
            -- remove the temp folder and then exit the setup.
             
            -- Output to the log that the user chose to abort the setup.
            SetupData.WriteToLogFile("Error\t.NET 4 Module: User chose to abort setup. Exiting setup.\r\n");
             
            File.Delete(strExtractInstallerToPath);
            Folder.Delete(strRuntimeSupportFolder);
            if bVital then
                Application.Exit(EXIT_REASON_USER_ABORTED);
            else
                Application.ExitScript();
            end
        end
    else
    -- A requirement failed
     
        -- If the user didn't cancel...
        if (bRunInstallFile) then
            -- One or more of the requirements failed. Notify the user and ask if they wish
            -- to abort the installation.
            strFullErrorString = Table.Concat(tbRequirementFailStrings, "\r\n", 1, TABLE_ALL);
            nDialogResult = Dialog.Message("Notice", strRequirementString..strFullErrorString..strAbortQuestion, MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1);
             
            -- Output the requirement failure string to the log.
            SetupData.WriteToLogFile("Error\t.NET 4 Module: Requirement failure dialog: "..strFullErrorString.."\r\n");
             
            -- Delete the runtime installer file and remove the temp folder
            File.Delete(strExtractInstallerToPath);
            Folder.Delete(strRuntimeSupportFolder);
             
            -- The user chose to abort the install due to the requirement failure of .NET.
            if (nDialogResult == IDOK) then
             
                -- Output to the log that the user chose to abort the install due to requirement failure.
                SetupData.WriteToLogFile("Error\t.NET 4 Module: User aborted setup due to requirement failure. Exiting setup.\r\n");
             
                -- Abort the install.
                Application.Exit(EXIT_REASON_USER_ABORTED);
            end
        else
            -- The user chose not to install the runtime so delete the run time installer file,
            -- remove the temp folder and then exit the setup.
             
            -- Output to the log that the user chose to abort the setup.
            SetupData.WriteToLogFile("Error\t.NET 4 Module: User chose to abort setup. Exiting setup.\r\n");
             
            File.Delete(strExtractInstallerToPath);
            Folder.Delete(strRuntimeSupportFolder);
             
            if bVital then
                Application.Exit(EXIT_REASON_USER_ABORTED);
            else
                Application.ExitScript();
            end
         
        end
    end
     
    -- If a reboot was needed by .NET, notify the user that they must reboot
    -- before continuing with the install
     
    -- NOTE: If you would always like to force the user to reboot, comment out the "if (_NeedsReboot) then" condition below.
     
    local strRebootMessage = [[A reboot is required to continue with the installation. After rebooting, re-run the installation.
 
Click OK to reboot now, or Cancel to reboot later.]];
    if (_NeedsReboot) then
        nDialogResult = Dialog.Message("Notice", strRebootMessage, MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1);
         
        -- Output to the log that a reboot is required by the .NET setup.
        SetupData.WriteToLogFile("Info\t.NET 4 Module: .NET 4 detected that a reboot is required.\r\n");
        -- Check if the uer wanted to reboot now.
        if (nDialogResult == IDOK) then
         
            -- NOTE:  If you would not like the install to relaunch itself after the reboot,
            -- uncomment the following block of code.
            -- Re-run the installation after the reboot.
             
            -- File.RunOnReboot(_SourceFilename, "");
         
            -- Output to the log that a reboot will be performed.
            SetupData.WriteToLogFile("Info\t.NET 4 Module: A reboot will be performed.\r\n");
            -- Reboot the user's system.
            System.Reboot();
        else
            -- Output to the log that the user chose to reboot later and abort the setup.
            SetupData.WriteToLogFile("Info\t.NET 4 Module: User chose to reboot later. Exiting setup.\r\n");
            -- Abort the install.
            Application.Exit(EXIT_REASON_USER_ABORTED);
        end
    end
    -- Output to the log that the installation script has finished.
    SetupData.WriteToLogFile("Success\t.NET 4 Module: Installation script finished.\r\n");
end

  4、依赖包位置

 将依赖包建个文件夹放在,setup  factory安装目录下的Dependencies中。或者选择个你喜欢的目录,比如D:\李二狗\461安装包\NDP461.exe

 

 

 最后,配置好后直接生成测试

 

 

posted @   兮去  阅读(463)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
点击右上角即可分享
微信分享提示