Recent

Author Topic: What version of Powershell  (Read 1218 times)

dbannon

  • Hero Member
  • *****
  • Posts: 759
    • tomboy-ng, a rewrite of the classic Tomboy
What version of Powershell
« on: October 13, 2019, 12:25:03 pm »
Is there some way I can tell the Windows version (ie Vista, 8, 10 etc) at run time ?

Like a define for example ?

I need to be able to determine if Powershell is available and I know thats only Windows 8 and 10.

Davo
« Last Edit: October 14, 2019, 07:25:42 am by dbannon »
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

winni

  • Sr. Member
  • ****
  • Posts: 468
Re: What version of windows
« Reply #1 on: October 13, 2019, 01:35:13 pm »
Hi!

Use the values from sysutils:
Code: Pascal  [Select]
  1. program EchoWinVersion;
  2. uses sysutils;
  3.  
  4. begin
  5.   Writeln('Win32 Platform    : ', Win32Platform    );
  6.   Writeln('Win32 Major Version: ', Win32MajorVersion);
  7.   Writeln('Win32 Minor Version: ', Win32MinorVersion);
  8.   Writeln('Win32 Build Number : ', Win32BuildNumber );
  9.   Writeln('Win32 CSD Version  : ', Win32CSDVersion  );
  10.   readln;
  11. end.
  12.  

The documentation is at
https://wiki.freepascal.org/WindowsVersion

Winni

440bx

  • Hero Member
  • *****
  • Posts: 1205
Re: What version of windows
« Reply #2 on: October 13, 2019, 03:55:05 pm »
I need to be able to determine if Powershell is available and I know thats only Windows 8 and 10.
I believe Powershell is also included with Windows 7.  A google search seems to confirm that.
using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: What version of windows
« Reply #3 on: October 13, 2019, 04:02:28 pm »
Maybe checking the registry for the existence is a better choice...

https://stackoverflow.com/a/1825604/1037511

Quote
To determine if PowerShell is installed, you can check the registry for the existence of

HKEY_LOCAL_MACHINE\Software\Microsoft\PowerShell\1\Install
and

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3
and, if it exists, whether the value is 1 (for installed), as detailed in the blog post Check if PowerShell installed and version.

dbannon

  • Hero Member
  • *****
  • Posts: 759
    • tomboy-ng, a rewrite of the classic Tomboy
Re: What version of windows
« Reply #4 on: October 14, 2019, 01:18:04 am »
Thanks folks, as always, great help.

I think I will try rvk's approach and test for the existence of powershell itself although I think I recall reading that earlier versions of powershell did not do everything later ones did. My interest is in downloading a file to a specific location, ideally without throwing up a text window to worry the users.

I will experiment ....

Thanks for the great advise every one !

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

ASBzone

  • Sr. Member
  • ****
  • Posts: 253
  • Automation leads to relaxation...
    • BrainWaveCC Utilities
Re: What version of windows
« Reply #5 on: October 14, 2019, 02:51:39 am »
Hi!

Use the values from sysutils:
Code: Pascal  [Select]
  1. program EchoWinVersion;
  2. uses sysutils;
  3.  
  4. begin
  5.   Writeln('Win32 Platform    : ', Win32Platform    );
  6.   Writeln('Win32 Major Version: ', Win32MajorVersion);
  7.   Writeln('Win32 Minor Version: ', Win32MinorVersion);
  8.   Writeln('Win32 Build Number : ', Win32BuildNumber );
  9.   Writeln('Win32 CSD Version  : ', Win32CSDVersion  );
  10.   readln;
  11. end.
  12.  

The documentation is at
https://wiki.freepascal.org/WindowsVersion

Winni


Except that doesn't give the best Windows version info.


On my Windows 10 system, for example, it returns:



Win32 Platform    : 2
Win32 Major Version: 6
Win32 Minor Version: 2
Win32 Build Number : 9200
Win32 CSD Version  :


-ASB: https://www.BrainWaveCC.com

Lazarus v2.0.5 r62023 / FPC v3.2.0-beta-r43192 (via FpcUpDeluxe) -- Windows 64-bit install w/32-bit cross-compile
Primary System: Windows 10 Pro x64, Version 1903 (Build 18362.418)
Other Systems: Windows 10 Pro x64, Version 1903 or greater

ASBzone

  • Sr. Member
  • ****
  • Posts: 253
  • Automation leads to relaxation...
    • BrainWaveCC Utilities
Re: What version of windows
« Reply #6 on: October 14, 2019, 02:54:01 am »
Thanks folks, as always, great help.

I think I will try rvk's approach and test for the existence of powershell itself although I think I recall reading that earlier versions of powershell did not do everything later ones did. My interest is in downloading a file to a specific location, ideally without throwing up a text window to worry the users.

I will experiment ....

Thanks for the great advise every one !

Davo


For powershell version, consider the following:

https://social.technet.microsoft.com/Forums/en-US/7125f618-0c59-45a0-a954-5fd50dd1cc0c/build-numbers-for-powershellexe-vs-powershell-version?forum=winserverpowershell
-ASB: https://www.BrainWaveCC.com

Lazarus v2.0.5 r62023 / FPC v3.2.0-beta-r43192 (via FpcUpDeluxe) -- Windows 64-bit install w/32-bit cross-compile
Primary System: Windows 10 Pro x64, Version 1903 (Build 18362.418)
Other Systems: Windows 10 Pro x64, Version 1903 or greater

dbannon

  • Hero Member
  • *****
  • Posts: 759
    • tomboy-ng, a rewrite of the classic Tomboy
Re: What version of windows
« Reply #7 on: October 14, 2019, 07:25:13 am »
OK, only have access to two windows platforms, Windows 10 on her ladyship's pc and an arcane Vista on a discarded laptop of mine. Honestly, I believe anyone using Vista has more problems than getting buggy software from me.

 I have done something like this -

Code: Pascal  [Select]
  1. {$ifdef WINDOWS}
  2. function TForm1.WeHavePowershell(const Version : char) : boolean;
  3. var
  4.     Registry : TRegistry;
  5. begin
  6.     Registry := TRegistry.Create;
  7.     try
  8.       Registry.RootKey := HKEY_LOCAL_MACHINE;
  9.       if Registry.OpenKeyReadOnly('\Software\Microsoft\PowerShell\' + Version ) then
  10.           exit(Registry.ReadInteger('Install') = 1)
  11.       else
  12.             exit(false);
  13.     finally
  14.       Registry.Free;
  15.     end;
  16. end;
  17. {$endif}

Windows 10 says it has both Powershell 1 and Powershell 3. I expect later versions of Windows will also claim to have 3. I  have found that even Vista has Powershell but its version 1.  I have not been able to obtain a list of functionality but it does seem that syntax has changed. My powershell download code fails but I don't think Vista is worth the effort really of working out why. So, in my case I will say -

Code: Pascal  [Select]
  1. if WeHavePowershell('3') then
  2.       DoSomething();
  3. else TellUserBadLuck();

I guess if the later Powershell (ie Power Core ??) becomes widespread, I may need to set an option to it to emulate version 3, thats easy.

Thanks for your help folks.

(I'll change the title of this thread to reflect what it became and what I should have entitled it at the start.)

Davo


 
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

Thaddy

  • Hero Member
  • *****
  • Posts: 9194
Re: What version of windows
« Reply #8 on: October 14, 2019, 07:27:28 am »
I need to be able to determine if Powershell is available and I know thats only Windows 8 and 10.
I believe Powershell is also included with Windows 7.  A google search seems to confirm that.
Powershell can be installed on any windows version above and including XP, if you want. It is also cross-platform (I am running Powershell on a Raspberry Pi combined with Mono on Raspbian Buster)
See https://github.com/powershell/powershell Microsoft put it in the public domain with its own open source license.
« Last Edit: October 14, 2019, 07:30:25 am by Thaddy »
also related to equus asinus.

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: What version of windows
« Reply #9 on: October 14, 2019, 08:57:09 am »
My interest is in downloading a file to a specific location, ideally without throwing up a text window to worry the users.
Wait... You want to use Powershell to download something?
Why not download it directly in FPC?

Thaddy

  • Hero Member
  • *****
  • Posts: 9194
Re: What version of Powershell
« Reply #10 on: October 14, 2019, 09:03:51 am »
I missed that, but indeed, that is not a very good reason to use powershell. Better do that from pure Pascal: more lightweight and easier to hide from the user.
also related to equus asinus.

440bx

  • Hero Member
  • *****
  • Posts: 1205
Re: What version of windows
« Reply #11 on: October 14, 2019, 10:11:21 am »
Powershell can be installed on any windows version above and including XP, if you want.
Correct.  My comment was only to point out that Powershell is installed as part of the OS starting with Windows 7, not Win8 and above.
using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

dbannon

  • Hero Member
  • *****
  • Posts: 759
    • tomboy-ng, a rewrite of the classic Tomboy
Re: What version of Powershell
« Reply #12 on: October 14, 2019, 10:11:33 am »
'cos windows users don't have the necessary ssl available, at least when using FPC 3.0.4.  And they get quite worried when you tell them to go and get it from 'somewhere'.

And powershell does it quite well on Windows 10 as it turns out.

Davo

Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

Thaddy

  • Hero Member
  • *****
  • Posts: 9194
Re: What version of Powershell
« Reply #13 on: October 14, 2019, 10:19:28 am »
recent powershell, as per my link, has always proper ssl support. Current fpc 3.2.0 and trunk also have current ssl support.
also related to equus asinus.

dbannon

  • Hero Member
  • *****
  • Posts: 759
    • tomboy-ng, a rewrite of the classic Tomboy
Re: What version of Powershell
« Reply #14 on: October 14, 2019, 10:26:54 am »
Yeah, I understand that (or think I do) but I need to stick to the release version of FPC if at all possible. As I am trying to not introduce any run time dependencies as I go.

When the next FPC release is made I reckon I will be able to simplify my code there and them !

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng