-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchoc_install.ps1
More file actions
857 lines (717 loc) · 45.1 KB
/
Copy pathchoc_install.ps1
File metadata and controls
857 lines (717 loc) · 45.1 KB
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
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
###################################################################################################################
# #
# Miscellaneous registry keys, a few from mscoree manifest so we can skip dotnet40 install #
# #
###################################################################################################################
@'
REGEDIT4
[HKEY_CURRENT_USER\Software\Wine\DllOverrides]
"mscoree"="native"
"d3dcompiler_47"="native"
"d3dcompiler_43"="native"
;"wusa.exe"="native"
"mscorsvw.exe"=""
"schtasks.exe"="native"
"setx.exe"="native"
;"taskschd"="native"
"robocopy.exe"="native"
"wmic.exe"="native"
"ngen.exe"="builtin"
;"MicrosoftEdgeUpdate.exe"="native"
"version"="native,builtin" ;Bug 29678
"shdocvw"="native,builtin" ;Bug 20777
"riched20"="native,builtin" ;Bug 14980
"winhttp"="native,builtin" ;Bug 47053
"packager"="native,builtin" ;Bug 43472
"d3d8"="native,builtin" ;Bug 47120
"msi"="native"
"wintypes"="native"
"icuuc"="native,builtin"
"concrt140"="native,builtin"
"mscorsvc"=""
"msvcp140"="native,builtin"
"msvcp140_1"="native,builtin"
"msvcp140_2"="native,builtin"
"msvcp140_atomic_wait"="native,builtin"
"msvcp140_codecvt_ids"="native,builtin"
"msvcr140"="native,builtin"
"ucrtbase"="native,builtin"
"vcomp"="native,builtin"
"vcomp140"="native,builtin"
"vcruntime140"="native,builtin"
"vcruntime140_1"="native,builtin"
"vccorlib140"="native,builtin"
"msvcr100"="native,builtin"
"msvcp100"="native,builtin"
"msvcr110"="native,builtin"
"msvcp110"="native,builtin"
"msvcr120"="native,builtin"
"msvcp120"="native,builtin"
[HKEY_CURRENT_USER\Software\Wine]
"HideWineExports"="Y"
[HKEY_CURRENT_USER\Software\Wine\Fonts\Replacements]
"Segoe UI"="Arial"
"Verdana"="Arial"
"Consolas"="Arial"
"Consolas Bold"="Arial"
"Consolas Bold Italic"="Arial"
"Consolas Italic"="Arial"
"Segoe UI Bold"="Arial"
"Segoe UI Bold Italic"="Arial"
"Segoe UI Italic"="Arial"
"Segoe UI Light"="Arial"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\conemu64.exe]
"Version"="win81"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\msedgewebview2.exe]
"Version"="win7"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\conemu64.exe\DllOverrides]
"dwmapi"=""
"user32"="native, builtin"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\pwsh.exe]
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\pwsh.exe\DllOverrides]
"amsi"=""
"dwmapi"=""
"rpcrt4"="native,builtin"
;[HKEY_CURRENT_USER\Software\Wine\AppDefaults\MicrosoftEdgeUpdate.exe\DllOverrides]
;"kernel32"=""
[HKEY_CURRENT_USER\Software\ConEmu\.Vanilla]
"BackColorIdx"=hex:10
"CmdLine"="%ProgramFiles%\\Powershell\\7\\pwsh.exe"
"ColorTable00"=dword:00562401
"ColorTable01"=dword:00423607
"ColorTable02"=dword:00808000
"ColorTable03"=dword:00a48231
"ColorTable04"=dword:00164bcb
"ColorTable05"=dword:00b6369c
"ColorTable06"=dword:00009985
"ColorTable07"=dword:00d5e8ee
"ColorTable08"=dword:00a1a193
"ColorTable09"=dword:00d28b26
"ColorTable10"=dword:0036b64f
"ColorTable11"=dword:0098a12a
"ColorTable12"=dword:002f32dc
"ColorTable13"=dword:008236d3
"ColorTable14"=dword:0000ffff
"ColorTable15"=dword:00e3f6fd
"FontSize"=dword:0000000e
"FontUseDpi"=hex:01
"FontUseUnits"=hex:01
"KeyboardHooks"=hex:01
"PopBackColorIdx"=hex:10
"PopTextColorIdx"=hex:10
"QuakeStyle"=hex:00
"SingleInstance"=hex:00
"StartFarEditors"=hex:00
"StartFarFolders"=hex:00
"StartTasksFile"=""
"StartTasksName"=""
"StartType"=hex:00
"StatusFontHeight"=dword:0000000c
"TabFontHeight"=dword:0000000d
"TextColorIdx"=hex:10
"Update.CheckHourly"=hex:01
"Update.CheckOnStartup"=hex:01
"Update.ConfirmDownload"=hex:01
"Update.UseBuilds"=hex:01
"UseInjects"=hex:01
[HKEY_CURRENT_USER\Software\ConEmu\.Vanilla\HotKeys]
"MinimizeRestore"=dword:000011c0
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\{DE293FDE-C181-46C0-8DCC-1F75EA35833D}]
"DisplayName"="ConEmu 230724.x64"
"DisplayVersion"="11.230.7240"
"Publisher"="ConEmu-Maximus5"
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip]
"DisplayName"="7-Zip (console only) 26.00 (x64)"
"DisplayVersion"="26.00"
"Publisher"="Igor Pavlov"
[HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework]
"OnlyUseLatestCLR"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\Policy\v2.0]
"50727"="50727-50727"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0]
"Install"=dword:0x00000001
"SP"=dword:0x00000002
"Version"="3.2.30729"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup]
"InstallSuccess"=dword:0x00000001
"Version"="3.2.30729"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5]
"Install"=dword:0x00000001
"SP"=dword:0x00000001
"Version"="3.5.30729.4926"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\1033]
"Install"=dword:0x00000001
[HKEY_CURRENT_USER\Software\Microsoft\Avalon.Graphics]
"DisableHWAcceleration"=dword:00000000
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{0A29FF9E-7F9C-4437-8B11-F424491E3931}\InprocServer32]
@="C:\\Windows\\System32\\mscoree.dll"
"ThreadingModel"="Both"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{0A29FF9E-7F9C-4437-8B11-F424491E3931}]
@="NDP SymBinder"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{0A29FF9E-7F9C-4437-8B11-F424491E3931}\ProgID]
@="CorSymBinder_SxS"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{0A29FF9E-7F9C-4437-8B11-F424491E3931}\Server]
@="diasymreader.dll"
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts]
"Arial (TrueType)"="arial.ttf"
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Fonts]
"Arial (TrueType)"="arial.ttf"
[HKEY_CURRENT_USER\Software\Wine\Debug]
"RelayExclude"="user32.CharNextA;KERNEL32.GetProcessHeap;KERNEL32.GetCurrentThreadId;KERNEL32.TlsGetValue;KERNEL32.GetCurrentThreadId;KERNEL32.TlsSetValue;KERNEL32.TlsGetValue;KERNEL32.FlsGetValue;KERNEL32.InterlockedDecrement;KERNEL32.InterlockedCompareExchange;KERNEL32.InitializeCriticalSection;KERNEL32.InterlockedExchange;KERNEL32.InterlockedIncrement;KERNEL32.LocalFree;Kernel32.LocalAlloc;KERNEL32.VirtualAlloc;Kernel32.VirtualFree;Kernel32.HeapFree;KERNEL32.QueryPerformanceCounter;KERNEL32.QueryThreadCycleTime;KERNEL32.GetTickCount;ntdll.*;kernelbase.*"
"RelayFromExclude"="winex11.drv;user32;gdi32;advapi32;kernel32"
[HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{937C1A34-151D-4610-9CA6-A8CC9BDB5D83}\TypeLib]
@="{7D868ACD-1A5D-4a47-A247-F39741353012}"
[HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{7B40792D-05FF-44C4-9058-F440C71F17D4}\InprocServer32]
@="C:\\windows\\system32\\tdh.dll"
"ThreadingModel"="Both"
'@ | Out-File $env:TEMP\\misc.reg
<# FIXME these keys are different from regular winetricks dotnet48 install????
[HKEY_CLASSES_ROOT\CLSID\{E5CB7A31-7512-11D2-89CE-0080C792E5D8}]
"MasterVersion"=dword:0x00000002
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\.NET Runtime]
"TypesSupported"=dword:0x00000007 #>
<# additional mono registry keys #>
@'
REGEDIT4
[HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\policy\v1.0]
[HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\policy\v1.1]
[HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\policy\v3.0]
[HKEY_LOCAL_MACHINE\Software\Microsoft\NET Framework Setup\NDP\v1.1.4322]
"Install"=dword:1
"SP"=dword:1
[HKEY_LOCAL_MACHINE\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727]
"Install"=dword:1
"SP"=dword:2
"OCM"=dword:1
"Version"="2.2.50727.4927"
[HKEY_LOCAL_MACHINE\Software\Microsoft\NET Framework Setup\NDP\v3.0]
"Install"=dword:1
"SP"=dword:2
[HKEY_LOCAL_MACHINE\Software\Microsoft\NET Framework Setup\NDP\v3.0\Setup]
"InstallSuccess"=dword:1
[HKEY_LOCAL_MACHINE\Software\Microsoft\NET Framework Setup\NDP\v3.5]
"Install"=dword:1
"SP"=dword:1
[HKEY_LOCAL_MACHINE\Software\Microsoft\NET Framework Setup\NDP\v3.5\1033]
"Install"=dword:1
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{7131646D-CD3C-40F4-97B9-CD9E4E6262EF}]
@=".NET Framework"
"ComponentID"=".NETFramework"
"Locale"=""
"Version"="2,0,50727,0"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{CB2F7EDD-9D1F-43C1-90FC-4F52EAE172A1}]
@=".NET Framework"
"ComponentID"=".NETFramework"
"Locale"=""
"Version"="1,0,4322,1"
[HKEY_LOCAL_MACHINE\Software\Classes\Installer\Products\1F3B805BA42A0C233B0158879691FE82]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\1F3B805BA42A0C233B0158879691FE82\InstallProperties]
"WindowsInstaller"=dword:1
[HKEY_LOCAL_MACHINE\Software\Classes\Installer\Products\DC3BF90CC0D3D2F398A9A6D1762F70F3]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{7131646D-CD3C-40F4-97B9-CD9E4E6262EF}]
@=".NET Framework"
"ComponentID"=".NETFramework"
"Locale"=""
"Version"="2,0,50727,0"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{CB2F7EDD-9D1F-43C1-90FC-4F52EAE172A1}]
@=".NET Framework"
"ComponentID"=".NETFramework"
"Locale"=""
"Version"="1,0,4322,1"
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\DC3BF90CC0D3D2F398A9A6D1762F70F3\InstallProperties]
WindowsInstaller=dword:1
".NET CLR 2.0.50727"=""
".NET CLR 3.0.30729"=""
".NET CLR 3.5.30729"=""
".NET4.0C"=""
".NET4.0E"=""
[HKEY_LOCAL_MACHINE\Software\Microsoft\XNA\Framework\v4.0]
"Installed"=dword:1
"ProductVersion"="4.0.20823.0"
"Installed"=dword:1
"ProductVersion"="4.0.20823.0"
'@ | Out-File $env:TEMP\\mono.reg
###################################################################################################################
# #
# profile.ps1: Put workarounds/hacks here. It goes into c:\\Program Files\\Powershell\\7\\profile.ps1 #
# #
###################################################################################################################
@'
#Put workarounds/hacks here.../Adjust to your own needs. It goes into c:\\Program Files\\Powershell\\7\\profile.ps1
$host.ui.RawUI.WindowTitle = 'This is Powershell Core (pwsh.exe), not (!) powershell.exe'
$profile = "$env:ProgramFiles\PowerShell\7\profile.ps1"
. "$env:ProgramData\\Chocolatey-for-wine\\profile_essentials.ps1"
'@ | Out-File ( New-Item -Path $(Join-Path $(Split-Path -Path (Get-Process -Id $pid).Path) "profile.ps1") -Force)<# Write profile.ps1 to Powershell directory #>
################################################################################################################################
# #
# profile_essentials_ps1: essential functions/settings for Chocolatey-for-wine to work properly #
# #
################################################################################################################################
@'
<# This contains essential functions/settings for Chocolatey-for-wine to work properly, do not remove or change #>
cd c:\;
$env:DXVK_CONFIG_FILE=("$env:WINECONFIGDIR" + "\" + "drive_c" + "\" + ($env:ProgramData |split-path -leaf) + "\" + "dxvk.conf").substring(6) -replace "\\","/"
# Enable Chocolatey profile
#$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
$ChocolateyProfile = "$env:ProgramData\\Chocolatey\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
<# if wineprefix is updated by running another wine version we have to update the hack for ConEmu bug https://bugs.winehq.org/show_bug.cgi?id=48761 #>
if( !( (Get-FileHash C:\windows\system32\user32.dll).Hash -eq (Get-FileHash C:\ConEmu\user32dummy.dll).Hash) ) {
Copy-item $env:SystemDrive\windows\system32\user32.dll $env:SystemDrive\ConEmu\user32dummy.dll -force -erroraction silentlycontinue
}
<# if powershell is started without args let's start conemu, but not if redirected or from pipe ( like 'powershell < a.ps1' or '"echo hello" | powershell') #>
$MethodDefinition = @"
public enum FSINFOCLASS { FileFsDeviceInformation = 4, }
[StructLayout(LayoutKind.Sequential, Pack = 0)] //https://stackoverflow.com/questions/69192954/how-to-add-and-use-a-c-sharp-struct-in-powershell
public struct FILE_FS_DEVICE_INFORMATION {
public uint DeviceType;
public ulong Characteristics;
// construct ahead
public FILE_FS_DEVICE_INFORMATION(uint dev, ulong chr) {
this.DeviceType = dev;
this.Characteristics = chr;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 0)]
public struct IO_STATUS_BLOCK {
public uint status;
public IntPtr information;
// construct ahead
public IO_STATUS_BLOCK(uint stat, IntPtr inf) {
this.status = stat;
this.information = inf;
}
}
[DllImport("ntdll.dll", SetLastError=true)] public static extern long NtQueryVolumeInformationFile(IntPtr FileHandle, ref IO_STATUS_BLOCK IoStatusBlock,ref FILE_FS_DEVICE_INFORMATION FsInformation, UInt32 Length, FSINFOCLASS FsInformationClass);
[DllImport("ntdll.dll")] public static extern int NtQuerySystemInformation( int SystemInformationClass, IntPtr SystemInformation, int SystemInformationLength, ref int ReturnLength);
"@
$ntdll = Add-Type -MemberDefinition $MethodDefinition -Namespace '' -name 'ntdll' -PassThru
$MethodDefinition2 = @"
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] public static extern string GetCommandLineW();
[DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr GetStdHandle(int nStdHandle);
"@
$kernel32 = Add-Type -MemberDefinition $MethodDefinition2 -Namespace '' -Name 'kernel32' -PassThru
$h=[kernel32]::GetStdHandle(-10) <# (DWORD)-10 is STD_INPUT_HANDLE #>
$io = [ntdll+IO_STATUS_BLOCK]::new(0,0)
$info =[ntdll+FILE_FS_DEVICE_INFORMATION]::new(0,0)
$null=[ntdll]::NtQueryVolumeInformationFile($h,[ref]$io,[ref]$info,[System.Runtime.InteropServices.Marshal]::SizeOf($info),[ntdll+FSINFOCLASS]::FileFsDeviceInformation.value__ )
$parent = [System.Diagnostics.Process]::GetCurrentProcess().Parent
if(($parent.processname -eq 'powershell') -and ( $kernel32::GetCommandLineW() -eq 'pwsh') -and ($info.DeviceType -eq 80) ) {
Start-Process c:\\ConEmu\\conemu64 |Out-Null
#Stop-process -id $parent.Id
Stop-process -id ([System.Diagnostics.Process]::GetCurrentProcess()).Id
} <# end start ConEmu #>
<# get the wine-version string (https://github.com/FuzzySecurity/PowerShell-Suite/blob/master/Get-SystemProcessInformation.ps1) #>
[IntPtr]$BuffPtr = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(256)
$null = [ntdll]::NtQuerySystemInformation(1000, $BuffPtr, 256, [ref][Int]$SystemInformationLength)
$wine_version = [System.Runtime.InteropServices.Marshal]::PtrToStringAnsi($BuffPtr,256)
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($BuffPtr)
<# end get wine-version #>
if($([System.Diagnostics.Process]::GetCurrentProcess().Parent.processname) -eq 'ConEmuC64' ) {Write-Host "";Write-Host -Foregroundcolor yellow Running Power Shell Core $PSVersionTable.PSVersion.ToString() on $wine_version.Split("`0",5)[1]"`nHost:" $wine_version.Split("`0",5)[2] $wine_version.Split("`0",5)[3]; Write-Host "";[system.console]::ForegroundColor='white'}
#Easy access to the C# compiler
Set-Alias csc c:\windows\Microsoft.NET\Framework\v4.0.30319\csc.exe
Set-Alias gwmi Get-WmiObject
Set-Alias Get-CIMInstance Get-CIMInstance_replacement
<# winetricks: to support auto-tabcompletion only a comma seperated is supported when calling winetricks with multiple arguments, e.g. 'winetricks gdiplus,riched20' #>
[array]$Qenu = iex "$([IO.File]::Readalltext("$env:ProgramData\\Chocolatey-for-wine\\winetricks.ps1").Split('marker line!!!',3)[1])"
<# https://stackoverflow.com/questions/67356762/couldnt-use-predefined-array-inside-validateset-powershell #>
for ( $j = 0; $j -lt $Qenu.count; $j+=3) { [string[]]$verblist += $Qenu[$j+1] }
function winetricks {
[CmdletBinding()]
param(
#[Parameter(Mandatory)]
# Tab-complete based on array $verblist
[ArgumentCompleter({
param($cmd, $param, $wordToComplete) $verblist -like "$wordToComplete*"
})]
# Validate based on array $verblist.
# NOTE: If validation fails, the (default) error message is unhelpful.
# You can work around that in *Windows PowerShell* with `throw`, and in
# PowerShell (Core) 7+, you can add an `ErrorMessage` property:
# [ValidateScript({ $_ -in $verblist }, ErrorMessage = 'Unknown value: {0}')]
[ValidateScript({
if ($_ -in $verblist) { return $true }
throw "'$_' is not in the set of the supported values: $($verblist -join ', ')"
})]
$Arg
)
if (!([System.IO.File]::Exists("$env:ProgramData\\Chocolatey-for-wine\\winetricks.ps1"))){
Add-Type -AssemblyName PresentationCore,PresentationFramework;
[System.Windows.MessageBox]::Show("winetricks script is missing`nplease reinstall it in c:\\ProgramData\\Chocolatey-for-wine",'Congrats','ok','exclamation')
}
. $([System.IO.Path]::Combine("$env:ProgramData","Chocolatey-for-wine", "winetricks.ps1")) $($arg -join ',')
}
#Remove ~/Documents/Powershell/Modules from modulepath; it becomes a mess because it`s not removed when one deletes the wineprefix...
$path = $env:PSModulePath -split ';'
$env:PSModulePath = ( $path | Select-Object -Skip 1 | Sort-Object -Unique) -join ';'
Remove-Variable MethodDefinition2,MethodDefinition,BuffPtr, info,io,j -erroraction silentlycontinue
'@ | Out-File ( New-Item -Path $env:ProgramData\\Chocolatey-for-wine\\profile_essentials.ps1 -Force)
################################################################################################################################
# #
# Install dotnet48, ConEmu, Chocolatey, 7z, d3dcompiler_47 and a few extras (wine robocopy + wine taskschd) #
# #
################################################################################################################################
foreach($i in $(Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*)) {
if($i.DisplayName -match 'Mono') { Remove-Item -force $i.PSPath -recurse }
}
<# Import reg keys: keys from mscoree manifest files, tweaks to advertise compability with lower .Net versions, and set some native dlls #>
reg.exe IMPORT $env:TMP\\misc.reg /reg:64
reg.exe IMPORT $env:TMP\\misc.reg /reg:32
mkdir "$env:ProgramFiles\7-zip"
Copy-Item $(Join-Path $args[0] '7z.*') "$env:ProgramFiles\7-zip\"
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
if([Environment]::GetEnvironmentVariable('CFW_CACHE')) { $cachedir = [System.IO.Path]::Combine( [Environment]::GetEnvironmentVariable('CFW_CACHE'), "choc_install_files" )}
else { $cachedir = [System.IO.Path]::Combine( "$([Environment]::GetFolderPath('mydocuments'))", "Chocolatey-for-wine", "choc_install_files" );}
$setupcache = "$env:SystemRoot\\Microsoft.NET\\Framework64\\v4.0.30319\\SetupCache"
if (([System.IO.File]::Exists("$cachedir\\windows6.1-kb958488-v6001-x64_a137e4f328f01146dfa75d7b5a576090dee948dc.msu"))) {
$cab_path = "$cachedir" }
else {
$cab_path = "$env:SystemRoot\\Microsoft.NET\\Framework64\\v4.0.30319\\SetupCache" }
iex "& ""wusa.exe"" ""$cab_path\\windows6.1-kb958488-v6001-x64_a137e4f328f01146dfa75d7b5a576090dee948dc.msu"""
if (([System.IO.File]::Exists("$cachedir\ConEmuPack.230724.7z"))) {
$cab_path = "$cachedir" }
else {
$cab_path = "$env:SystemRoot\\Microsoft.NET\\Framework64\\v4.0.30319\\SetupCache" }
iex "& ""$(Join-Path $args[0] '7z.exe')"" x ""$cab_path\ConEmuPack.230724.7z"" ""-o$env:SystemDrive\ConEmu""";
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{DE293FDE-C181-46C0-8DCC-1F75EA35833D}" -Name "InstallDate" -Value "$(Get-Date -Format FileDate)" -PropertyType 'String' -force
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\7-zip" -Name "InstallDate" -Value "$(Get-Date -Format FileDate)" -PropertyType 'String' -force
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\7-zip" -Name "InstallDate" -Value "$(Get-Date -Format FileDate)" -PropertyType 'String' -force
[System.IO.File]::Copy("$env:SystemDrive\windows\system32\user32.dll","$env:SystemDrive\ConEmu\user32dummy.dll",$true)
[System.Environment]::SetEnvironmentVariable("POWERSHELL_UPDATECHECK", 'Off','Machine')
# Add-Type -AssemblyName PresentationCore,PresentationFramework; [System.Windows.MessageBox]::Show('Chocolatey installed','Congrats','ok','exclamation')
<# fix up the 'highlight selection'-hack for ConEmu #>
$bytes = [System.IO.File]::ReadAllBytes("$env:systemdrive\Conemu\conemu64.exe")
$bytes[1968524]='0x5f' <# rename 'USER32.dll to allow loading it from non-system directory (find exact position with 'grep -oba "USER32.dll")' #>
[System.IO.File]::WriteAllBytes("$env:systemdrive\Conemu\conemu64.exe",$bytes)
<# setup chocolatey #>
Move-Item "$env:ProgramData\\tools\\ChocolateyInstall" "$env:ProgramData\\chocolatey"
mkdir "$env:ProgramData\\chocolatey\\bin"
Copy-Item "$env:ProgramData\\chocolatey\\redirects\\choco.exe" "$env:ProgramData\\chocolatey\\bin\\choco.exe"
if (([System.IO.File]::Exists("$cachedir\windowsserver2003-kb968930-x64-eng_8ba702aa016e4c5aed581814647f4d55635eff5c.exe"))) {
$cab_path = "$cachedir" }
else {
$cab_path = "$env:SystemRoot\\Microsoft.NET\\Framework64\\v4.0.30319\\SetupCache" }
iex "& ""$(Join-Path $args[0] '7z.exe')"" x -x!""*resources.dll"" ""$cab_path\\windowsserver2003-kb968930-x64-eng_8ba702aa016e4c5aed581814647f4d55635eff5c.exe"" ""Microsoft.Powershell*.dll"" ""Microsoft.WSman*.dll"" ""system.management.automation.dll"" ""-o$env:ProgramData\chocolatey"""
Import-Module "$env:ProgramData\chocolatey\helpers\chocolateyProfile.psm1"
[Environment]::SetEnvironmentVariable('PATH',[Environment]::GetEnvironmentVariable('PATH', 'Machine') + ";$env:ProgramData\chocolatey\bin\", 'Machine')
[Environment]::SetEnvironmentVariable('ChocolateyInstall',"$env:ProgramData\chocolatey", 'Machine')
iex 'refreshenv'
# Get-Process '7z' -ErrorAction:SilentlyContinue | Foreach-Object { $_.WaitForExit()}
Move-Item -Path "$env:systemdrive\Conemu\user32.dll" -Destination "$env:systemdrive\Conemu\_ser32.dll"
if(!($args[1] -eq '/q') -and !($args[2] -eq '/q')) {
Start-Process "c:\conemu\conemu64" -ArgumentList " -NoUpdate -LoadRegistry -run %ProgramFiles%\\Powershell\\7\\pwsh.exe -noe -c Write-Host Installed Software: ;
`$ps = (gci `$env:ProgramFiles\PowerShell\7\pwsh.exe)
`$7z = (gci `$env:ProgramFiles\7-zip\7z.exe)
`$choco = (gci `$env:ProgramData\chocolatey\choco.exe)
`$inf = @();
`$inf += [PSCustomObject]@{DisplayName='7-Zip (Console only)';DisplayVersion=`$7z.VersionInfo.ProductVersionRaw;Publisher='Igor Pavlov';InstallDate=`$(Get-Date -Format FileDate)};
`$inf += [PSCustomObject]@{DisplayName='Microsoft .NET Framework 4.8';DisplayVersion='4.8.03761';Publisher='Microsoft Corporation';InstallDate=`$(Get-Date -Format FileDate)};
`$inf += [PSCustomObject]@{DisplayName='PowerShell 7-x64';DisplayVersion=`$ps.VersionInfo.ProductVersionRaw;Publisher='Microsoft Corporation';InstallDate=`$(Get-Date -Format FileDate)};
`$inf += [PSCustomObject]@{DisplayName='Chocolatey';DisplayVersion=`$choco.VersionInfo.ProductVersionRaw;Publisher='Chocolatey Software, Inc.';InstallDate=`$(Get-Date -Format FileDate)};
`$inf += [PSCustomObject]@{DisplayName='ConEmu 230724.x64';DisplayVersion='11.230.7240';Publisher='ConEmu-Maximus5';InstallDate=`$(Get-Date -Format FileDate)};`$inf"}
# Start-Process "c:\conemu\conemu64" -ArgumentList " -NoUpdate -LoadRegistry -run %ProgramFiles%\\Powershell\\7\\pwsh.exe -noe -c iex -command ""$inf = @(); $inf += [PSCustomObject]@{DisplayName='7-Zip (console only) 26.00 (x64)';DisplayVersion='26.00';Publisher='Igor Pavlov';InstallDate='$(Get-Date -Format FileDate)'}; $inf += [PSCustomObject]@{DisplayName='Microsoft .NET Framework 4.8';DisplayVersion='4.8.03761';Publisher='Microsoft Corporation';InstallDate='$(Get-Date -Format FileDate)'};
# $inf += [PSCustomObject]@{DisplayName='PowerShell 7-x64';DisplayVersion='7.6.3.0';Publisher='Microsoft Corporation';InstallDate='$(Get-Date -Format FileDate)'}; $inf += [PSCustomObject]@{DisplayName='ConEmu 230724.x64';DisplayVersion='11.230.7240';Publisher='ConEmu-Maximus5';InstallDate='$(Get-Date -Format FileDate)'};Write-Host Installed Software: '$inf';"""}
###################################################################################################################
# #
# Finish installation and some app specific tweaks #
# #
###################################################################################################################
# while (![Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine',0).OpenSubKey('Software\Microsoft\Windows\CurrentVersion\Uninstall\{16735AF7-1D8D-3681-94A5-C578A61EC832}')) {Sleep 0.25}
<# do not use chocolatey's builtin powershell host #>
# while(!(Test-path "$env:systemroot\\system32\\ucrtbase_clr0400.dll") ) {start-Sleep 0.25}
# cd c:\; c:\\ProgramData\\chocolatey\\choco.exe feature disable --name=powershellHost; winecfg /v win10
# c:\\ProgramData\\chocolatey\\choco.exe feature enable -n allowGlobalConfirmation <# to confirm automatically (no -y needed) #>
# mkdir "$env:ProgramFiles\7-zip"
# Copy-Item $(Join-Path $args[0] '7z.*') "$env:ProgramFiles\7-zip\"
#Remove-Item -force -recurse "$env:systemroot\mono";
if( [System.IO.Directory]::Exists("$env:systemroot\mono") ) { [System.IO.Directory]::Delete("$env:systemroot\mono",'true') }
else {
reg.exe IMPORT $env:TMP\\mono.reg /reg:64
reg.exe IMPORT $env:TMP\\mono.reg /reg:32
foreach ($i in 'Framework64', 'Framework') {
[System.IO.Directory]::CreateDirectory("$env:systemroot\Microsoft.NET\$i\v2.0.50727\")
[System.IO.Directory]::CreateDirectory("$env:systemroot\Microsoft.NET\$i\v3.0\windows communication foundation\")
# [System.IO.Directory]::CreateDirectory("$env:systemroot\Microsoft.NET\$i\v3.0\wpf\")
[System.IO.Directory]::CreateDirectory("$env:systemroot\Microsoft.NET\$i\v3.5\")
[System.IO.File]::Copy("$env:systemroot\Microsoft.NET\$i\v4.0.30319\msbuild.exe", "$env:systemroot\Microsoft.NET\$i\v3.5\msbuild.exe", $true);
[System.IO.File]::Copy("$env:systemroot\Microsoft.NET\$i\v4.0.30319\msbuild.exe", "$env:systemroot\Microsoft.NET\$i\v2.0.50727\msbuild.exe", $true);
[System.IO.File]::Copy("$env:systemroot\Microsoft.NET\$i\v4.0.30319\installutil.exe", "$env:systemroot\Microsoft.NET\$i\v2.0.50727\installutil.exe", $true);
}
}
[System.IO.Directory]::CreateDirectory("$env:systemroot\assembly\")
if (([System.IO.File]::Exists("$cachedir\\d3dcompiler_47_32.dll"))) {
$cab_path = "$cachedir" }
else {
$cab_path = "$env:SystemRoot\\Microsoft.NET\\Framework64\\v4.0.30319\\SetupCache" }
Copy-Item -Path "$cab_path\\d3dcompiler_47_32.dll" -Destination "$env:SystemRoot\\SysWOW64\\d3dcompiler_47.dll" -Force
Copy-Item -Path "$cab_path\\d3dcompiler_47_32.dll" -Destination "$env:SystemRoot\\SysWOW64\\d3dcompiler_43.dll" -Force
if (([System.IO.File]::Exists("$cachedir\\d3dcompiler_47.dll"))) {
$cab_path = "$cachedir" }
else {
$cab_path = "$env:SystemRoot\\Microsoft.NET\\Framework64\\v4.0.30319\\SetupCache" }
Copy-Item -Path "$cab_path\\d3dcompiler_47.dll" -Destination "$env:SystemRoot\\System32\\d3dcompiler_47.dll" -Force
Copy-Item -Path "$cab_path\\d3dcompiler_47.dll" -Destination "$env:SystemRoot\\System32\\d3dcompiler_43.dll" -Force
<# Backup files if wanted #>
if(($args[1] -eq '/s') -or ($args[2] -eq '/s')) {
[System.IO.Directory]::CreateDirectory("$cachedir")
foreach($i in ((gci $setupcache\\PowerShell-*-win-x64.msi)).name, 'd3dcompiler_47.dll', 'd3dcompiler_47_32.dll', 'windows6.1-kb958488-v6001-x64_a137e4f328f01146dfa75d7b5a576090dee948dc.msu', 'ConEmuPack.230724.7z', 'windowsserver2003-kb968930-x64-eng_8ba702aa016e4c5aed581814647f4d55635eff5c.exe', ((gci $setupcache\\chocolatey.*.nupkg)).name) {
Move-Item -Path "$setupcache\\$i" -Destination "$cachedir" -force -ErrorAction SilentlyContinue}
Move-Item -path "$setupcache\\v4.8.03761" -destination "$cachedir" -ErrorAction SilentlyContinue;
}
<# Replace some system programs by functions; This also makes wusa a dummy program: we don`t want windows updates and it doesn`t work anyway #>
ForEach ($file in "wusa","schtasks","getmac","setx","wbem\\wmic", "ie4uinit", "openfiles","MicrosoftEdgeUpdate") {
Move-Item -Path "$env:windir\\SysWOW64\\$($file + '.exe')" -Destination "$env:windir\\SysWOW64\\$($file + '.back.exe')" -Force -ErrorAction SilentlyContinue
Move-Item -Path "$env:winsysdir\\$($file + '.exe')" -Destination "$env:winsysdir\\$($file + '.back.exe')" -Force -ErrorAction SilentlyContinue
Copy-Item -Path "$env:windir\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe" -Destination "$env:windir\\SysWOW64\\$($file + '.exe')" -Force
Copy-Item -Path "$env:winsysdir\\WindowsPowerShell\\v1.0\\powershell.exe" -Destination "$env:winsysdir\\$($file + '.exe')" -Force}
<# Native Access needs this dir #>
New-Item -Path "$env:Public" -Name "Downloads" -ItemType "directory" -ErrorAction SilentlyContinue
<# make wusa noop #>
New-ItemProperty -Path "HKCU:\Software\Wine\DllOverrides" -Name "wusa.exe" -Value "native" -PropertyType 'String' -force
<# clean up #>
Get-Process 'msiexec' -ErrorAction:SilentlyContinue | Foreach-Object { $_.WaitForExit()}; [System.IO.Directory]::Delete($setupcache,'true')
New-ItemProperty -Path HKLM:\Software\Microsoft\.NETFramework -Name ETWEnabled -Value 0 -PropertyType "DWord" -force
while (![Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine',0).OpenSubKey('Software\Microsoft\Windows\CurrentVersion\Uninstall\{16735AF7-1D8D-3681-94A5-C578A61EC832}')) {Sleep 0.25}
Remove-Item "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{92FB6C44-E685-45AD-9B20-CADF4CABA132} - 1033" -recurse -force
while (![Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine',0).OpenSubKey('Software\Microsoft\Windows\CurrentVersion\Uninstall\{16735AF7-1D8D-3681-94A5-C578A61EC832}')) {Sleep 0.25}
<# do not use chocolatey's builtin powershell host #>
# while(!(Test-path "$env:systemroot\\system32\\ucrtbase_clr0400.dll") ) {start-Sleep 0.25}
cd c:\; c:\\ProgramData\\chocolatey\\choco.exe feature disable --name=powershellHost; winecfg /v win10
c:\\ProgramData\\chocolatey\\choco.exe feature enable -n allowGlobalConfirmation <# to confirm automatically (no -y needed) #>
<# easy access to 7z #>
iex "$env:ProgramData\\chocolatey\\tools\\shimgen.exe --output=`"$env:ProgramData`"\\chocolatey\\bin\\7z.exe --path=`"$env:ProgramW6432`"\\7-zip\\7z.exe"
<# This makes Astro Photography Tool happy #>
foreach($i in 'regasm.exe') {
Copy-Item -Path $env:systemroot\\Microsoft.NET\\Framework\\v4.0.30319\\$i -Destination $env:systemroot\\Microsoft.NET\\Framework\\v2.0.50727\\$i
Copy-Item -Path $env:systemroot\\Microsoft.NET\\Framework64\\v4.0.30319\\$i -Destination $env:systemroot\\Microsoft.NET\\Framework64\\v2.0.50727\\$i
}
<# dxvk (if installed) doesn't work well with WPF, add workaround from dxvk site #>
#####################################################################################################
@"
[pwsh.exe]
d3d9.shaderModel = 1
[ps51.exe]
d3d9.shaderModel = 1
"@ | Out-File -FilePath $env:ProgramData\\dxvk.conf
@'
Function Get-WmiObject([parameter(mandatory=$true, position = 0, parametersetname = 'class')] [string]$class, `
[parameter( position = 1, parametersetname = 'class')][string[]]$property="*", `
[string]$computername = "localhost", [string]$namespace = "root\cimv2", `
[string]$filter, [parameter(parametersetname = 'query')] [string]$query)
{ <# Do not remove or change, it will break Chocolatey #>
if(!$query) {
$query = "SELECT " + $($property | Join-String -Separator ",") + " FROM " + $class + (($filter) ? (' where ' + $filter ) : ('')) }
$searcher = [wmisearcher]$query
$searcher.scope.path = "\\" + $computername + "\" + $namespace
return [System.Management.ManagementObjectCollection]$searcher.get()
}
'@ | Out-File ( New-Item -Path $env:ProgramFiles\Powershell\7\Modules\Get-WmiObject\Get-WmiObject.psm1 -Force )
@'
Function Get-CIMInstance_replacement ( [parameter(mandatory)] [string]$classname, [string[]]$property="*", [string]$filter)
{
Get-WMIObject $classname -property $property -filter $filter
}
'@ | Out-File ( New-Item -Path $env:ProgramFiles\Powershell\7\Modules\Get-CIMInstance_replacement\Get-CIMInstance_replacement.psm1 -Force )
@'
function QPR.wusa { <# wusa.exe replacement, Query program replacement for wusa.exe; Do not remove or change, it will break Chocolatey #>
Write-Host "This is wusa dummy doing nothing..."
exit 0;
}
'@ | Out-File ( New-Item -Path $env:ProgramFiles\Powershell\7\Modules\QPR.wusa\QPR.wusa.psm1 -Force )
@'
function QPR.MicrosoftEdgeUpdate { <# MicrosoftEdgeUpdate.exe replacement #>
Write-Host "This is MicrosoftEdgeUpdate.exe dummy doing nothing..."
exit 0;
}
'@ | Out-File ( New-Item -Path $env:ProgramFiles\Powershell\7\Modules\QPR.MicrosoftEdgeUpdate\QPR.MicrosoftEdgeUpdate.psm1 -Force )
@'
function QPR.schtasks { <# schtasks.exe replacement #>
$MethodDefinition2 = @"
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] public static extern string GetCommandLineW();
[DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr GetStdHandle(int nStdHandle);
"@
$kernel32 = Add-Type -MemberDefinition $MethodDefinition2 -Namespace '' -Name 'kernel32' -PassThru
$cmdline = $($([kernel32]::GetCommandLineW()).Split(" ",5)[4]) #.SubString($env:QPRCMDLINE.IndexOf(" "), $env:QPRCMDLINE.Length - $env:QPRCMDLINE.IndexOf(" "))
$cmdline = $cmdline -replace '/create', '-create' -replace '/tn', '-tn' -replace "/tr", "-tr" <#-replace "'", "'`"'"#> <# escape quotes (??) #> `
-replace "/sc", "-sc" -replace "/run", "-run" -replace "/delete", "-delete"
$cmdline
iex -Command ('QPR_schtasks ' + $cmdline)
}
function QPR_schtasks { <# schtasks replacement #>
# [CmdletBinding()]
Param([switch]$create, [string]$tn, [string]$tr, [string]$sc, [switch]$run, [switch]$delete,
[parameter(ValueFromRemainingArguments=$true)]$vargs)
if($create) {$tr -replace "'" -replace "/silent"
iex -command $($tr -replace "'" -replace "/silent") } <# hack for spotify #>
else {
$cmdline = $cmdline -replace "^[^ ]+" <# remove everything up yo 1st space #> -replace "-","/"
$cmdline
Start-Process -NoNewWindow schtasks.back.exe -argumentlist "$cmdline" }
}
'@ | Out-File ( New-Item -Path $env:ProgramFiles\Powershell\7\Modules\QPR.schtasks\QPR.schtasks.psm1 -Force )
@'
<# hack for installing adobereader #>
function Unregister-ScheduledTask { Write-Host 'cmdlet Unregister-ScheduledTask not available in PS 7, doing nothing...'; return}
<# needed for Amazon Music #>
function QPR.ie4uinit { <# ie4uinit.exe replacement #>
Write-Host "This is ie4uinit dummy doing nothing..."
exit 0;
}
'@ | Out-File ( New-Item -Path $env:ProgramFiles\Powershell\7\Modules\QPR.ie4uinit\QPR.ie4uinit.psm1 -Force )
@'
function QPR.openfiles { <# openfiles.exe replacement for install of mpv #>
Write-Host "This is openfiles dummy doing nothing..."
exit 0;
}
'@ | Out-File ( New-Item -Path $env:ProgramFiles\Powershell\7\Modules\QPR.openfiles\QPR.openfiles.psm1 -Force )
@'
# Note: Visual Studio calls this, not sure if this is really needed by it...
function QPR.getmac { <# getmac.exe replacement #>
Get-WmiObject win32_networkadapterconfiguration | Format-Table @{L=’Physical address’;E={$_.macaddress}}
}
'@ | Out-File ( New-Item -Path $env:ProgramFiles\Powershell\7\Modules\QPR.getmac\QPR.getmac.psm1 -Force )
@'
function QPR.setx { <# setx.exe replacement #>
<# FIXME, only setting env. variable handled atm. #>
<# https://stackoverflow.com/questions/50368246/splitting-a-string-on-spaces-but-ignore-section-between-double-quotes #>
#$argv = ($env:QPRCMDLINE| select-string '("[^"]*"|\S)+' -AllMatches | % matches | % value) -replace '"'
$MethodDefinition2 = @"
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] public static extern string GetCommandLineW();
[DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr GetStdHandle(int nStdHandle);
"@
$kernel32 = Add-Type -MemberDefinition $MethodDefinition2 -Namespace '' -Name 'kernel32' -PassThru
$argv = CommandLineToArgvW $($([kernel32]::GetCommandLineW()).Split(" ",4)[3])
New-ItemProperty -Path 'HKLM:\\System\\CurrentControlSet\\Control\\Session Manager\\Environment' -force -Name $argv[1] -Value $argv[2] -PropertyType 'String'
New-ItemProperty -Path 'HKCU:\\Environment' -force -Name $argv[1] -Value $argv[2] -PropertyType 'String'
exit 0
}
'@ | Out-File ( New-Item -Path $env:ProgramFiles\Powershell\7\Modules\QPR.setx\QPR.setx.psm1 -Force )
@'
<#
.Synopsis
Parse command-line arguments using Win32 API CommandLineToArgvW function.
.Link
http://edgylogic.com/blog/powershell-and-external-commands-done-right/
.Description
This is the Cmdlet version of the code from the article http://edgylogic.com/blog/powershell-and-external-commands-done-right.
It can parse command-line arguments using Win32 API function CommandLineToArgvW .
#>
function CommandLineToArgvW
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$false, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)]
[ValidateNotNullOrEmpty()]
[string]$CommandLine
)
Begin
{
$Kernel32Definition = @"
[DllImport("kernel32")]
public static extern IntPtr GetCommandLineW();
[DllImport("kernel32")]
public static extern IntPtr LocalFree(IntPtr hMem);
"@
$Kernel32 = Add-Type -MemberDefinition $Kernel32Definition -Name 'Kernel32' -Namespace 'Win32' -PassThru
$Shell32Definition = @"
[DllImport("shell32.dll", SetLastError = true)]
public static extern IntPtr CommandLineToArgvW(
[MarshalAs(UnmanagedType.LPWStr)] string lpCmdLine,
out int pNumArgs);
"@
$Shell32 = Add-Type -MemberDefinition $Shell32Definition -Name 'Shell32' -Namespace 'Win32' -PassThru
if(!$CommandLine)
{
$CommandLine = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Kernel32::GetCommandLineW())
}
}
Process
{
$ParsedArgCount = 0
$ParsedArgsPtr = $Shell32::CommandLineToArgvW($CommandLine, [ref]$ParsedArgCount)
Try
{
$ParsedArgs = @();
0..$ParsedArgCount | ForEach-Object {
$ParsedArgs += [System.Runtime.InteropServices.Marshal]::PtrToStringUni(
[System.Runtime.InteropServices.Marshal]::ReadIntPtr($ParsedArgsPtr, $_ * [IntPtr]::Size)
)
}
}
Finally
{
$Kernel32::LocalFree($ParsedArgsPtr) | Out-Null
}
$ret = @()
# -lt to skip the last item, which is a NULL ptr
for ($i = 0; $i -lt $ParsedArgCount; $i += 1) {
$ret += $ParsedArgs[$i]
}
return $ret
}
}
'@ | Out-File ( New-Item -Path $env:ProgramFiles\Powershell\7\Modules\CommandLineToArgvW\CommandLineToArgvW.psm1 -Force )
@'
function QPR.wmic { <# wmic replacement, this part only rebuilds the arguments #>
if ( $(Get-Process wmic).Parent.name -eq 'pwsh') { <# check whether cmd is ran from PS-console #>
$cmd = $(cat (Get-PSReadlineOption).HistorySavePath -tail 1).Trim(' ')
$cmdline = $cmd.Substring($cmd.IndexOf(' ')+1).Trim(' ') + ' ' }
else {
$MethodDefinition2 = @"
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] public static extern string GetCommandLineW();
[DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr GetStdHandle(int nStdHandle);
"@
$kernel32 = Add-Type -MemberDefinition $MethodDefinition2 -Namespace '' -Name 'kernel32' -PassThru
$cmdline = $($([kernel32]::GetCommandLineW()).Split(" ",5)[4]) }
$hash = @{
"path" = "-class "
'os' = "-class win32_operatingsystem"
'memorychip' = "-class Win32_PhysicalMemory"
'cpu' = "-class win32_processor"
'nic' = "-class win32_NetworkAdapter"
'csproduct' = "-class Win32_ComputerSystemProduct"} <# etc. etc. #>
$class= $cmdline.SubString(0, $cmdline.IndexOf(" "))
$remainder= $cmdline.SubString( $cmdline.IndexOf(" ")) -replace '\bget\b', '-property' -replace '\bwhere\b', ' -where '' WHERE '' -filter '
foreach ($key in $hash.keys) {
if( $class -eq $key ) { $class = $hash[$key]; $found = 1; break } }
if(-not $found) {$class = $('win32_' + $class)}
iex -Command ('QPR_wmic ' + $class + $remainder)
}
function QPR_wmic { <# wmic replacement #>
[CmdletBinding()]
Param([parameter(Position=0)][string]$class, [string[]]$property="*",[string]$where, [string]$filter, [parameter(ValueFromRemainingArguments=$true)]$vargs)
if($property -eq '*'){ <# 'get-wmiobject $class | select *' does not work because of wine-bug, so need a workaround: #>
Get-WmiObject $class ($($(Get-WmiObject $class |Get-Member) |where {$_.membertype -eq 'property'}).name -join ',') }
else { #handle e.g. wmic logicaldisk where "deviceid='C:'" get freespace or wmic logicaldisk get size, freespace, caption
([wmisearcher]$("SELECT " + ($property -join ",") + " FROM " + $class + $where + $filter)).get() |ft ($property |sort) -autosize |Out-string -Stream | Select -skipindex (2)| ?{$_.trim() -ne ""}}
}
'@ | Out-File ( New-Item -Path $env:ProgramFiles\Powershell\7\Modules\QPR.wmic\QPR.wmic.psm1 -Force )
# Add certificate to fix dotnet build errors; https://digicert.tbs-certificates.co.uk/vsign-universal-root.crt
# openssl x509 -in vsign-universal-root.crt -outform PEM -out verisign.crt
@'
-----BEGIN CERTIFICATE-----
MIIEuTCCA6GgAwIBAgIQQBrEZCGzEyEDDrvkEhrFHTANBgkqhkiG9w0BAQsFADCBvTELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwOCBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MTgwNgYDVQQDEy9W
ZXJpU2lnbiBVbml2ZXJzYWwgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wODA0MDIwMDAwMDBaFw0zNzEyMDEyMzU5NTlaMIG9MQswCQYDVQQGEwJVUzEX
MBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0IE5ldHdvcmsxOjA4BgNVBAsTMShjKSAyMDA4IFZlcmlTaWduLCBJbmMuIC0gRm9y
IGF1dGhvcml6ZWQgdXNlIG9ubHkxODA2BgNVBAMTL1ZlcmlTaWduIFVuaXZlcnNhbCBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEF
AAOCAQ8AMIIBCgKCAQEAx2E3XrEBNNti1xWb/1hajCMj1mCOkdeQmIN65lgZOIzF9uVkhbSicfvtvbnazU0AtMgtc6XHaXGVHzk8skQHnOgO+k1KxCHfKWGPMiJhgsWH
H26MfF8WIFFE0XBPV+rjHOPMee5Y2A7Cs0WTwCznmhcrewA3ekEzeOEz4vMQGn+HLL729fdC4uW/h2KJXwBL38Xd5HVEMkE6HnFuacsLdUYI0crSK5XQz/u5QGtkjFdN
/BMReYTtXlT2NJ8IAfMQJQYXStrxHXpma5hgZqTZ79IugvHw7wnqRMkVauIDbjPTrJ9VAMf2CGqUuV/c4DPxhGD5WycRtPwW8rtWaoAljQIDAQABo4GyMIGvMA8GA1Ud
EwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMG0GCCsGAQUFBwEMBGEwX6FdoFswWTBXMFUWCWltYWdlL2dpZjAhMB8wBwYFKw4DAhoEFI/l0xqGrI2Oa8PPgGrUSBgs
exkuMCUWI2h0dHA6Ly9sb2dvLnZlcmlzaWduLmNvbS92c2xvZ28uZ2lmMB0GA1UdDgQWBBS2d/ppSEefUxLVwuoHMnYH0ZcHGTANBgkqhkiG9w0BAQsFAAOCAQEASvj4
sAPmLGd75JR3Y8xuTPl9Dg3cyLk1uXBPY/ok+myDjEedO2Pzmvl2MpWRsXe8rJq+seQxIcaBlVZaDrHC1LGmWazxY8u4TB1ZkErvkBYoH1quEPuBUDgMbMzxPcP1Y+Oz
4yHJJDnp/RVmRvQbEdBNc6N9Rvk97ahfYtTxP/jgdFcrGJ2BtMQo2pSXpXDrrB2+BxHw1dvd5Yzw1TKwg+ZX4o+/vqGqvz0dtdQ46tewXDpPaj+PwGZsY6rp2aQW9IHR
lRQOfc2VNNnSj3BzgXucfr2YYdhFh5iQxeuGMMY1v/D/w1WIg0vvBZIGcfK4mJO37M2CYfE45k+XmCpajQ==
-----END CERTIFICATE-----
'@ | Out-File "$env:ProgramData\Chocolatey-for-wine\verisign.crt"
$C = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new("$env:ProgramData\Chocolatey-for-wine\verisign.crt"); $C
$store=[System.Security.Cryptography.X509Certificates.X509Store]::new('Root', 'LocalMachine'); $store
$store.Open('ReadWrite')
$store.Add($C)
$store.Close()
# Start-Process $env:systemroot\Microsoft.NET\Framework64\v4.0.30319\ngen.exe -NoNewWindow -Wait -ArgumentList "eqi"
# Start-Process $env:systemroot\Microsoft.NET\Framework\v4.0.30319\ngen.exe -NoNewWindow -Wait -ArgumentList "eqi"