IT Nota

  • Home
  • How To
  • .NET
  • WordPress
  • Contact

How to Check Installed .NET Framework Version

This is a quick way to check an installed version of .NET Framework (as opposed to .NET Core). This works for any .NET Framework 4.5 or later.

We’re doing this by using a PowerShell script to get the value from the registry and a Python script to quickly match the release number to the associated .NET Framework version. This has been used so many times to get the value quickly on production servers, but use it at your own risk.

Steps

  1. On the server where you want to check the .NET Framework version, open a PowerShell window and run the following script:

    (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full").Release
    
  2. Once you see the value, you can check it using the following Python script to see what version of .NET Framework that number corresponds to.

    #! python3
    # Check .NET version based on the release number
    # Reference https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
    
    releaseVersion = input("\nEnter .NET release number: ")
    
    def checkVersion(release):
    
        relNo = int(release)
    
        if relNo >= 528040:
            print('.NET Framework 4.8')
        elif relNo >= 461808:
            print('.NET Framework 4.7.2')
        elif relNo >= 461308:
            print('.NET Framework 4.7.1')
        elif relNo >= 460798:
            print('.NET Framework 4.7')
        elif relNo >= 394802:
            print('.NET Framework 4.6.2')
        elif relNo >= 394254:
            print('.NET Framework 4.6.1')
        elif relNo >= 393295:
            print('.NET Framework 4.6')
        elif relNo >= 379893:
            print('.NET Framework 4.5.2')
        elif relNo >= 378675:
            print('.NET Framework 4.5.1')
        elif relNo >= 378389:
            print('.NET Framework 4.5')
        else:
            print('No match')
    
    checkVersion(releaseVersion)
    

I’m sure there’s a more elegant way to do this by just running one script to do all these things but this is provided as it is.

Further Reading

How to Check Installed .NET Core Version
How to: Determine which .NET Framework versions are installed
How to Install Python on Windows Server

April 12, 2022 Filed Under: How To Tagged With: .NET, PowerShell, Python

How to Use Python to Connect to SQL Server

Can Python work with SQL Server database? Some may argue that SQL Server is not the best SQL database for Python, but in most cases it actually does not matter. In my corporate experience, SQL Server may be the easiest database to use with Python. Besides, in the workplace often times we just have to use what’s available to solve our business problems.

One of the advantages of Python language is the short development time that makes it very suitable to use as a simple tool to query a database.

The easiest way to access a SQL Server database with Python is by using pyodbc. From its project description, pyodbc is an open source Python module that makes accessing ODBC databases simple.

There is another driver called pymssql, but I have not tested it and it looks like even Microsoft themselves recommend pyodbc over pymssql although try to remain somewhat neutral.

There are several python SQL drivers available. However, Microsoft places its testing efforts and its confidence in pyodbc driver.

Source: Python SQL Driver: Getting Started.

You can install it by running the pip command in the Command Prompt (Windows) or Terminal (macOS):

pip install pyodbc

Once installed, create a new python file (e.g., hrquery.py) and import the pyodbc.

Example

hrquery.py

#!python3
# hr.py - Look for HR record based on last name.
#         If no argument is passed, return total count of records.

import sys, pyodbc

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=DB_SERVER_NAME;'
                      'Database=DATABASE_NAME;'
                      'UID=SQLID_OR_NTID;'
                      'PWD=PASSWORD;'
                      'Trusted_Connection=no;')

cursor = conn.cursor()

# Check if there is a passed argument (last name)
# If yes, search by last name, in parameterized query
# otherwise, give total count of records from HR table.

if len(sys.argv) > 1:
    lastName = sys.argv[1]

    cursor.execute('SELECT * FROM dbo.HR WHERE [Last name] = ?', lastName)
    for i in cursor:
        print(i)
else:
    totalCount = cursor.execute('SELECT COUNT(*) FROM dbo.').fetchval()
    print(f"\nTotal count in HR table: {totalCount} records\n")

Other than Driver and Trusted_Connection, you need to substitute the values of all the parameters with your own (Server, Database, UID, and PWD).

To run your program, you can launch Command Prompt or Terminal and type the following:

C:\> python.exe hrquery.py lastname

OR

C:\> python.exe hrquery.py

Using Windows Authentication

If you use your NTID or a Windows Service Account (Windows Authentication) to login to the database, then there’s a slight difference in how you setup the connection string. This is the preferred way nowadays since you don’t store your password as a clear text in your code.

You just need to remove the PWD and set the Trusted_Connection to yes so it will look like the following:

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=DB_SERVER_NAME;'
                      'Database=DATABASE_NAME;'
                      'UID=NTID_OR_SVCACCT;'
                      'Trusted_Connection=yes;')

That’s all there is in using Python to connect to SQL Server and the program will work the same way.

Further Reading

How to Install Python on Windows Server
pyodbc
Python SQL Driver

January 12, 2022 Filed Under: How To Tagged With: Microsoft SQL Server, Python, SQL Server

How to Install Python on Windows Server

Python is an excellent general purpose language that can be used for batch processing and other tasks on your server.

To install Python on Windows Server operating system, you just need to run the installer and use the simplest configuration.

Steps to Install Python on Windows Server Operating System

  1. Download the installer (full as opposed to the web sintaller) and save it to your temp folder.

    Python installer in Windows Temp folder

  2. Right-click on the file and select Run as administrator.

    Run Python installer as administrator

  3. You’ll see a User Account Control popup window with a question, “Do you want to allow the following program to make changes to this computer?” Just click on Yes.

  4. Check the Add Python 3.7 to PATH checkbox at the bottom of the window (or whatever the latest version you’re installing).

    Install Python setup screen

  5. If you don’t care where the program is installed, you can just clik on the Install Now, there’s nothing wrong with the setup and Python will run and this is generally fine for desktop installation.

    For server installation, you should be more mindful with the program location better location rather than the default installation under a specific user folder who ran the installer. So it’s better to choose Customize installation.

  6. In Optional Features screen, make sure you at least check the following: pip, py launcher, and for all users. Click Next.

    Python customize installation optional features

  7. On the next screen, Advanced Options, make sure you check Install for all users which then will change the value of Customize install location, just accept the default installation in C:\Program Files unless you have a reason to install it somewhere else. Click Install.

    Python customize installation advanced options for all users

  8. Once you see Setup was successful just click the Close button.

  9. Make sure that C:\Program Files\Python37 and C:\Program Files\Python37\Scripts are in the Path of your System variables.

    Python added to path in Windows Environment Variables

    If you’re able to click on Edit button, you can see all the path entries in each line which is easier to read and edit. In this case, the button is greyed out due to the group policy.

As a final check, you can open Programs and Features and check if Python and Python Launcher are shown.

Programs and Features

That’s all there is to have your server running Python scripts.

If you work mostly with Microsoft stack and need to connect to a SQL Server database using Python, then check this post about Python SQL Server Driver.

Further Reading

How to Activate Built-in Web Server
How to Use Python to Connect to SQL Server

Download

Python Download

May 22, 2019 Filed Under: How To Tagged With: Microsoft, Python, Windows Server

Buy me a coffee Support this site
Buy Me a Coffee?

Categories

  • .NET
  • Coding
  • Cybersecurity
  • Database
  • How To
  • Internet
  • Multimedia
  • Photography
  • Programming
  • Resources
  • Review
  • Tips and Tricks
  • Uncategorized
  • Use Case
  • WordPress
  • Writing

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Tags

.NET .NET Core AdSense ASP.NET Cdonts Dll Classic ASP Code Editor ETL FSharp Genesis Framework Git Google HP Asset Manager HTML5 Hugo IIS Information Security Internet Internet Information Services iOS JAMStack Linux macOS Microsoft Microsoft SQL Server MVC PHP PowerShell Python Simple Mail Transfer Protocol Smtp Server SQL SQL Server SSIS SSMS SSRS Sublime Text Visual Studio Visual Studio Code VPN Windows Windows 8 Windows 10 Windows 2012 Windows Server

Copyright © 2011-2025 IT Nota. All rights reserved. Terms of Use | Privacy Policy | Disclosure