Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-Processorbits function seems to be broken #809

Closed
SebastianK90 opened this issue Jun 17, 2016 · 12 comments
Closed

Get-Processorbits function seems to be broken #809

SebastianK90 opened this issue Jun 17, 2016 · 12 comments

Comments

@SebastianK90
Copy link

Hi there,

since I updated MPC-BE package and did a bit of testing on Win10 x64/x86 VMs I noticed that the Get-Processorbits function seems to be broken.

Code:
$bits = Get-ProcessorBits
if ($bits -eq '64')
{
Install-ChocolateyPath 'C:\Program Files\MPC-BE x64'
}
else
{
Install-ChocolateyPath 'C:\Program Files\MPC-BE'
}

This should install shims on 32-Bit machines to path 'C:\Program Files\MPC-BE' but it doesn't.
It's creating shims for 'C:\Program Files\MPC-BE x64'

@jberezanski
Copy link

As I wrote on the mailing list, the strictly correct comparison code should be:

if ($bits -eq 64)

because Get-ProcessorBits returns an int.

However, both variants work correctly on my Windows 10 x64 (build 10586), using the latest code:

C:\> $bits = Get-ProcessorBits
C:\> $bits -eq '64'
True
C:\> $bits -eq 64
True
C:\> $bits -eq '32'
False
C:\> $bits -eq 32
False

@jberezanski
Copy link

Ah, I just realized you were reporting invalid behavior on x86, not x64. Here is a test on Windows 7 x86:

PS C:\> $Env:PROCESSOR_ARCHITECTURE
x86
PS C:\> $bits = Get-ProcessorBits
PS C:\> $bits
32
PS C:\> $bits -eq 64
False
PS C:\> $bits -eq '64'
False

@jberezanski
Copy link

I just installed mpc-be on that Windows 7 system (.NET 4.0, PowerShell 2.0) and the path addition was correct:

PS C:\> cinst -dvy mpc-be -version 1.4.6
(...)
Chocolatey v0.9.10
Chocolatey is running on Windows v 6.1.7601.65536
(...)
Running 'Get-OSArchitectureWidth'
CPU is 32 bit
(...)
mpc-be has been installed.
Running 'Get-OSArchitectureWidth'
Running 'Install-ChocolateyPath' with pathToInstall:'C:\Program Files\MPC-BE'

One more issue with your code: there is no guarantee that Program Files is on C: drive (or, in fact, that it is named Program Files!). You should use $Env:ProgramFiles instead of hardcoding C:\Program Files.

@ferventcoder
Copy link
Member

ferventcoder commented Jun 17, 2016

@jberezanski Inside the PowerShell host - this could be an issue. Better to create a package that does this.

Rename this to nupkg:

test-environment.1.0.0.nupkg.zip

$bits = Get-ProcessorBits
Write-Host "Get-ProcessorBits = $bits"
Write-Host "`$bits -eq '64' = $($bits -eq '64')"
Write-Host "`$bits -eq 64 = $($bits -eq 64)"
Write-Host "`$bits -eq '32' = $($bits -eq '32')"
Write-Host "`$bits -eq 32 = $($bits -eq 32)"

@ferventcoder
Copy link
Member

Try this in 0.9.10 and see what it reports.

@ferventcoder
Copy link
Member

ferventcoder commented Jun 17, 2016

@sippi90 Thanks for finding the bug - I do agree with @jberezanski that you are not going about finding the install directory correctly. Users can override the default installation directory. A much more deterministic way to get this is to get the install location from the uninstaller registry key - https://gist.github.com/choco-bot/cc2a1764e8fc24943d1391979847a7f3#file-1-registrysnapshot-xml-L1-L9. You want to follow the code example from https://chocolatey.org/docs/helpers-get-uninstall-registry-key (source code is https://github.com/chocolatey/choco/blob/master/src/chocolatey.resources/helpers/functions/Get-UninstallRegistryKey.ps1).

@jberezanski
Copy link

Running 'C:\ProgramData\chocolatey\lib\test-environment\tools\chocolateyinstall.ps1'
TEMP=C:\Users\W732\AppData\Local\Temp\chocolatey
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\W732\AppData\Roaming
CHOCOLATEY_VERSION=0.9.10.0
CHOCOLATEY_VERSION_PRODUCT=0.9.10
ChocolateyEnvironmentDebug=true
ChocolateyEnvironmentVerbose=true
ChocolateyInstall=C:\ProgramData\chocolatey
ChocolateyLastPathUpdate=Sat Jun 18 01:17:17 2016
chocolateyPackageFolder=C:\ProgramData\chocolatey\lib\test-environment
chocolateyPackageName=test-environment
chocolateyPackageVersion=1.0.0
ChocolateyPowerShellHost=true
chocolateyRequestTimeout=30000
chocolateyResponseTimeout=2700000
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=W732-PC
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\W732
IS_ADMIN=true
IS_PROCESSELEVATED=true
LOCALAPPDATA=C:\Users\W732\AppData\Local
LOGONSERVER=\\W732-PC
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
OS_IS64BIT=false
OS_NAME=Windows 7
OS_PLATFORM=Windows
OS_VERSION=6.1.7601.65536
packageFolder=C:\ProgramData\chocolatey\lib\test-environment
packageName=test-environment
packageVersion=1.0.0
Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\
chocolatey\bin;;C:\Program Files\MPC-BE;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 23 Stepping 10, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=170a
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
PSModulePath=;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Users\W732\Documents\WindowsPowerShell\Modules;
PUBLIC=C:\Users\Public
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\W732\AppData\Local\Temp\chocolatey
TMP=C:\Users\W732\AppData\Local\Temp
USERDOMAIN=W732-PC
USERNAME=W732
USERPROFILE=C:\Users\W732
windir=C:\Windows
windows_tracing_flags=3
windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log
Running 'Get-OSArchitectureWidth'
Get-ProcessorBits = 32
$bits -eq '64' = False
$bits -eq 64 = False
$bits -eq '32' = True
$bits -eq 32 = True
ERROR: Cannot bind argument to parameter 'exitCode' because it is null.
    at System.Management.Automation.ParameterBinderBase.ValidateNullOrEmptyArgument(CommandParameterInternal parameter,
CompiledCommandParameter parameterMetadata, Type argumentType, Object parameterValue, Boolean recurseIntoCollections)
   at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommand
Parameter parameterMetadata, ParameterBindingFlags flags)
   at System.Management.Automation.CmdletParameterBinderController.BindParameter(CommandParameterInternal argument, Merg
edCompiledCommandParameter parameter, ParameterBindingFlags flags)
   at System.Management.Automation.CmdletParameterBinderController.BindParameter(UInt32 parameterSets, CommandParameterI
nternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
   at System.Management.Automation.ParameterBinderController.BindPositionalParametersInSet(UInt32 validParameterSets, Di
ctionary`2 nextPositionalParameters, CommandParameterInternal argument, ParameterBindingFlags flags, ParameterBindingExc
eption& bindingException)
   at System.Management.Automation.ParameterBinderController.BindPositionalParameters(Collection`1 unboundArguments, UIn
t32 validParameterSets, UInt32 defaultParameterSet, Boolean ignoreArgumentsThatLookLikeParameters, ParameterBindingExcep
tion& outgoingBindingException)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 ar
guments)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
   at System.Management.Automation.CommandProcessor.BindCommandLineParameters(CommandParameterInternal[] parameters)
   at System.Management.Automation.CommandProcessor.Prepare(CommandParameterInternal[] parameters)
   at System.Management.Automation.CommandProcessorBase.DoPrepare(CommandParameterInternal[] parameters)
   at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorR
esults, Boolean enumerate)
Built-in PowerShell host called with ['[System.Threading.Thread]::CurrentThread.CurrentCulture = '';[System.Threading.Th
read]::CurrentThread.CurrentUICulture = ''; & import-module -name 'C:\ProgramData\chocolatey\helpers\chocolateyInstaller
.psm1'; & 'C:\ProgramData\chocolatey\helpers\chocolateyScriptRunner.ps1' -packageScript 'C:\ProgramData\chocolatey\lib\t
est-environment\tools\chocolateyinstall.ps1' -installArguments '' -packageParameters '''] exited with '-1'.

full console output

@ferventcoder
Copy link
Member

@jberezanski I'm assuming you scrubbed the environment variables prior to posting.

Also, what is that last thing there and how did you get that to happen?

@jberezanski
Copy link

I did not alter the output in any way; this is one of my test VMs, no sensitive data there.

No idea why the package installation failed. Perhaps because it did not invoke Start-ChocolateyProcessAsAdmin (or any other install helper) and so $env:ChocolateyExitCode was never populated?

What I did, step by step, after booting the VM:

  1. Installed Chocolatey from elevated PowerShell:
Set-ExecutionPolicy RemoteSigned -Force
iex (New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')
  1. In a new elevated PowerShell:
  Id CommandLine
  -- -----------
   1 cd \
   2 cinst -dvy mpc-be
   3 cinst -dvy mpc-be -version 1.4.6
   4 $env:path
  1. Downloaded your test package to C:\Users\W732\Downloads
  2. In the same elevated PowerShell as in step 2:
   5 cinst -dvy -source C:\Users\W732\Downloads test-environment

Additional environment information: the OS is an almost completely unpatched (only 9 patches from 2013.12) Win7 Professional SP1 with only .NET 4.6.1 installed (I wrote ".NET 4.0" by mistake in a previous comment). Polish language.

@ferventcoder
Copy link
Member

Just filed #810. It's supposed to be looking at lastexitcode, but that looks like it may not return correctly in all cases. Not sure if that is a culture specific thing or not yet.

@SebastianK90
Copy link
Author

  1. I've now clean reverted a snapshot of my Win10 32-bit VM.
  2. Removed the ' ' from ($bits -eq '64') -> ($bits -eq 64).
  3. And I'm parsing Installpath from uninstallcode as suggested.
    Profit: Now everything is working!
    Many Thanks guys!

@ferventcoder
Copy link
Member

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants