Showing posts with label WIndows. Show all posts
Showing posts with label WIndows. Show all posts

May 23, 2023

Change default directory for Windows command prompt and Powershell when running with admin privileges

 Hi all,

It's been a while since I posted things.

Here is my previous post where the non-admin user changes the default directory for the command prompt and PowerShell.

https://psrdotcom.blogspot.com/2022/03/change-default-directory-of-windows.html

But in this post, I will be explaining about running the command prompt / powershell with admin rights and setting the default directory. Because, when you are running with admin privileges, it by default goes to the SYSTEM32 folder of Windows.

Environment

I use the command prompt and PowerShell, which are pinned to the taskbar of Windows.

Run the application with the admin rights

  • Right-click on the application icon -> click on Properties
  • Go to the "Compatibility" tab
  • Check "Run this program as administrator"

Run the shortcut with the admin rights

  • Right-click on the shortcut icon -> click on Properties
  • Go to the "Shortcut" tab
  • Click on the "Advanced" button
  • Check "Run this program as administrator"

Change the command prompt default directory

  • We need to have a .bat file with the following content
    • @echo off
    • cd <default_directory>
Now use the .bat file in the shortcut properties
  • Right-click on the shortcut icon -> click on Properties
  • Go to the "Shortcut" tab
  • In the "Target" field append the below text
    • /k "batfile_dirpath\batfile.bat"

Change the PowerShell default directory

  • Right-click on the shortcut icon -> click on Properties
  • Go to the "Shortcut" tab
  • In the "Target" field append the below context after powershell.exe
    • -NoExit -command "& {Set-Location <default_directory>}"
  • Click on "OK"

Hope, this helps you to reduce the frequent directory changes in the command prompt and PowerShell.

Feel free to provide your valuable feedback and comments to psrdotcom@gmail.com

March 14, 2022

Change default directory of Windows command prompt and Windows PowerShell

 Hi all,

Today I will explain the steps to change the default directory for Windows command prompt and Windows PowerShell.

The default directory for both the command prompt and PowerShell is the "system32" folder of the OS installed directory (By default: "C:\windows\system32").

Day in - Day out, we will open the terminals (command prompt / PowerShell) and navigate the source directory. It sometimes irritates and wastes lots of time.

I have come across this situation and want to avoid re-entry the change directory command.

Environment,

I use the command prompt and PowerShell, which are pinned to the taskbar of Windows.


Change default directory of Windows Command Prompt

  1. Right-click on the taskbar pinned Command Prompt icon
  2. Right-click on the "Command Prompt" menu
  3. Select the "Properties" item
  4. Under the "Shortcut" tab, you will find the "Start in:" label
  5. In the respective text box, enter the path you want to navigate by default.
  6. For example, "C:\Projects".

Change default directory of Windows PowerShell

  1. Open the PowerShell with administrator privileges
  2. Create a profile by using the following steps
    1. New-item -type file -force $Profile
  3. This will create a file "Microsoft.PowerShell_profile.ps1" in the current user documents PowerShell folder.
    1. Syntax
        • C:\Users\<UserName>\Documents\WindowsPowerShell
      1. Example
          • C:\Users\PSR\Documents\WindowsPowerShell
      2. Edit file
          • notepad.exe $Profile
        1. Change the default directory
          1. Syntax
              • Set-Location <Directory Path>
            1. Example
                • Set-Location C:\Projects
                  • Clear-Host # To clear the PowerShell screen
              1. Save and close the file
              2. In the PowerShell window, enter the following command to change the profile
                  • . $Profile
                1. It immediately changes from the current directory to the updated default directory.
                2. Close the PowerShell and try to open the PowerShell again to see the change in the directory.
                Hope the above information is helpful to you reduce the change directories in day-to-day life.

                Send me your valuable feedback to psrdotcom@gmail.com.

                January 27, 2021

                Windows Batch File - Embed Image (Base64 Encoded) in HTML Code

                 Hi folks,

                Today I am going to explain how we can add an image to the HTML code in without copying the images in relative path folder.

                Procedure

                • Prefix file contents.
                  • <img src="data:image/png;base64,
                •  Batch file contents.
                • Suffix file contents.
                  • " alt="PSR" />
                • Download the batch file.
                • Open command prompt in Windows.
                • Navigate to the batch file contained folder.
                • Execute the batch file image file name as parameter.
                  • > Image2Base64ImgTag.bat PSRImage.jpeg
                • You should see a file "imageTag.html".
                • Open the file to see image in a browser.
                • Open the file with notepad to see the image converted to base64 with proper HTML Image tag.


                Hope this helps you to reduce lot of efforts in maintaining the image files/folders.

                Send your feedback and comments to psrdotcom@gmail.com

                December 07, 2020

                C# get windows user app data folder path

                 Hi folks,

                Today I will explain to get the folder path of the windows user specific app data for storing any program (app) based information in C# (.NET Framework, .NET CORE, .NET 5)


                Source

                using System;

                using System.IO;

                namespace NETFrameworkConsoleApp1

                {

                    class Program

                    {

                        static void Main(string[] args)

                        {

                            string dir = Path.Combine(

                                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),

                                "FolderName"

                            );

                            Console.WriteLine("User Appdata Path: \n " + dir);

                            Console.ReadLine();

                        }

                    }

                }


                Hope this helps you to customize your requirement.

                References

                https://docs.microsoft.com/en-us/dotnet/api/system.environment?view=net-5.0

                Please share your comments and feedback to psrdotcom@gmail.com


                C++ get windows user app data folder path

                 Hi folks,

                Today we will see how we can get the folder path of the windows user specific app data for storing any program (app) based information.


                Source

                #include <iostream>

                #include <tchar.h>

                #include <shlwapi.h>

                #pragma comment(lib,"shlwapi.lib")

                #include "shlobj.h"

                using namespace std;

                int main()

                {  

                    TCHAR szPath[MAX_PATH];

                    // Get path for each computer, non-user specific and non-roaming data.

                    if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath)))

                    {

                        // Append product-specific path

                        PathAppend(szPath, _T("\\App Folder Path\\"));

                        wcout << "User AppData Roaming Folder Path: \n" << szPath << endl << endl;

                    }

                    

                    // Get path for each computer, non-user specific and non-roaming data.

                    if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, 0, szPath)))

                    {

                        wcout << "System Program Files Folder Path: \n" << szPath << endl << endl;

                    }

                    cout << "==end==";

                }


                Hope this helps you to customize your requirement.

                References

                https://docs.microsoft.com/en-us/windows/win32/shell/csidl

                Please share your comments and feedback to psrdotcom@gmail.com


                October 31, 2020

                Generate or Create ECDSA - Elliptic Curve Digital Signature Algorithm Keys using OpenSSL in Windows

                 Hi folks,

                Today we will see how we can create ECDSA (Elliptic Curve Digital Signature Algorithm) Keys


                Pre-requisites

                OpenSSL

                Add openssl bin directory to the environment PATH variable 


                Generate Keys

                Open Powershell and execute the following commands

                1. Get the ECC curves list

                openssl ecparam -list_curves
                2. Generate a private key using your chosen curve
                openssl ecparam -name prime256v1 -genkey -noout -out private-key.pem
                3. Generate public key from the private key
                openssl ec -in private-key.pem -pubout -out public-key.pem

                4. Create a self-signed certificate with 1 year validity
                openssl req -new -x509 -config "<opensslDirPath>/share/openssl.cnf" -key private-key.pem -out cert.pem -days 360

                5. Convert pem to pfx
                get-content private-key.pem, cert.pem | out-file cert-with-private-key
                openssl pkcs12 -export -inkey private-key.pem -in cert-with-private-key -out cert.pfx

                 Note: Enter the password when prompted (Optional)

                Now, you can install the PFX file and check the certificate properties and make use of it.

                Send your valuable feedback and comments to psrdotcom@gmail.com


                October 06, 2020

                Convert JSON file to CSV with Python

                 Hi folks,

                Today I will explain the code to implement the Json2CSV conversion.

                Make sure you have valid JSON file with an array of objects.

                Sample:

                "Users":[

                {"id": 1, "Name": "Suresh Raju", "Age": 35},

                {"id":2, "Name": "PSR", "Age": 34}

                ]

                I have chosen Python language to convert because of inbuilt library support for json and csv and command line execution with Notepad++ as editor.

                Source Code Snippet: GitHub Gist

                Please send your valuable feedback and comments to psrdotcom@gmail.com


                October 04, 2020

                Base 64 Encode with Powershell Script

                 Hi all,

                Today I will explain the snippet which gives you a base 64 encoded string

                $enc = [system.Text.Encoding]::UTF8

                $guid = "42f930c2-2ba2-4d5a-a102-898321122414"

                $base64encodedstring = [System.Convert]::ToBase64String($enc.GetBytes($guid))

                Write-Host "bBse64 Encoded String: $base64encodedstring"

                Hope this helps when you are planning to generate and use/store the base64 encoded value

                August 13, 2020

                Microsoft Windows Sysinternals Suite with file, disk, network, process, security utilities

                Hi Folks,

                Today, i will give an overview of Microsoft Windows Sysinternals Suite.

                This suite helps users and admins to troubleshoot the OS and devices.

                Sysinternals Suite

                The Suite is a bundling of the following selected Sysinternals Utilities: AccessChk, AccessEnum, AdExplorer, AdInsight, AdRestore, Autologon, Autoruns, BgInfo, BlueScreen, CacheSet, ClockRes, Contig, Coreinfo, Ctrl2Cap, DebugView, Desktops, Disk2vhd, DiskExt, DiskMon, DiskView, Disk Usage (DU), EFSDump, FindLinks, Handle, Hex2dec, Junction, LDMDump, ListDLLs, LiveKd, LoadOrder, LogonSessions, MoveFile, NotMyFault, NTFSInfo, PageDefrag, PendMoves, PipeList, PortMon, ProcDump, Process Explorer, Process Monitor, PsExec, PsFile, PsGetSid, PsInfo, PsKill, PsList, PsLoggedOn, PsLogList, PsPasswd, PsPing, PsService, PsShutdown, PsSuspend, PsTools, RAMMap, RegDelNull, RegHide, RegJump, Registry Usage (RU), SDelete, ShareEnum, ShellRunas, Sigcheck, Streams, Strings, Sync, Sysmon, TCPView, VMMap, VolumeID, WhoIs, WinObj, ZoomIt

                Individual Utilities

                If you want to use or explore individual utilities then please use the below links for navigation

                1. File and Disk Utilities
                2. Networking Utilities
                3. Process Utilities
                4. Security Utilities
                5. System Information
                6. Miscellaneous

                My favorites

                1. DiskMon - Disk monitor whenever read/write happens to hard disk
                2. Disk2vhd - Convert your physical harddisk to Microsoft VHD (Virtual Hard Disk) format
                3. TCPView - List the TCP and UDP ports usage with process name
                4. Active Director Explorer - Advanced Active Directory (AD) viewer and editor
                5. VMMap - Virutal and physical memory analysis utility

                Hope, these tools will help you to troubleshoot and/or make use of official Microsoft utilities to explore OS more.

                Please send your feedback and comments to psrdotcom@gmail.com

                June 24, 2020

                Connect or Mount USB Storage drives in Windows Linux Sub System

                Hi folks,

                This post will explain the process of connecting / mounting USB devices to Windows Linux Sub Systems

                Mount removable media (e.g. E:)

                $ sudo mkdir /mnt/e
                $ sudo mount -t drvfs E: /mnt/e

                Unmount

                $ sudo umount /mnt/e
                Send your comments and feedback to psrdotcom@gmail.com


                February 11, 2020

                Deploy or Host ASP.NET Core web application in IIS

                Dear folks,

                Today I am going to explain the process of deploying the ASP.NET Core web application in IIS (Internet Information Services) web server.

                Pre-requsites



                Application configuration

                To make sure the application deploys and works with IIS, you should add the following while creating the web host.

                WebHost.CreateDefaultBuilder(args)
                                   .UseKestrel()
                                   .UseIISIntegration()
                                   .UseStartup();
                 Where Kestrel hosts the application and IIS will be acting as a reverse proxy.

                Publish the application

                After doing the changes, publish the application to a folder as self-contained as you no need to bother about the server for all the application dependencies.

                Web Configuration


                • In Web.config, remove the following content
                  • hosting="In Progress"
                • Copy files to IIS location
                • Create a website folder in IIS wwwroot folder
                • Copy the publish folder to the website folder
                • Example: C:\inetpub\wwwroot\website

                IIS Application Pool


                • Create an application pool in IIS with following configuration
                  • Name:
                  • .NET CLR version: No Managed Code
                  • Managed pipeline mode: Integrated



                Website Configuration

                • Right click on the website and select "Add Application"
                • Give the following details
                  • Alias:
                  • Application Pool: Select above created application pool from list
                  • Physical path: Select the above created website path
                    • Example: C:\inetpub\wwwroot\website

                Restart IIS

                • Once you have completed all the steps, perform the following to make sure everything is in sync.
                • Open powershell in administrator mode
                • Run the following commands
                  1. net stop was /y
                  2. net start w3svc

                Test

                Browse to the URL, you should be able to get the web pages.

                Please send your valuable feedback and comments to psrdotcom@gmail.com


                December 10, 2019

                Go language install and configuration in Windows and Visual Studio Code as IDE

                Hi folks,

                Today I am going to describe you the best way to install and configure the Go language.

                Download

                From the Go language from its official web page https://golang.org/dl/

                After installation, you would be able to program and run the code from any terminal.

                What else?

                Open your .go file in Visual Studio Code, it asks you something else. What was it?

                "The "go-outline" command is not available. Run "go get -v github.com/ramya-rao-a/go-outline" to install."

                What you need to do?

                First, in Visual Studio Code set the the following in "settings.json" file.

                "go.toolsGopath": "C:\\Go"

                Note: If you are getting the following error, then click on "Install All"
                The "go-outline" command is not available. Run "go get -v github.com/ramya-rao-a/go-outline" to install.

                • Get the location, where it is installing
                • Copy the bin and pkg folder contents to your Go installed folders.
                • Delete the folder which VS Code used to download the content.

                That's all.. you should be able to code in Visual Studio Code as well without having 2 different go installed folders.

                Happy Go coding!!

                Please send your feedback and comments to psrdotcom@gmail.com

                August 08, 2019

                Truecrypt Mount and Unmount in Windows

                Hi friends,

                I would like to share the information of mounting and unmounting truecrypt in windows

                Please find the batch file here

                https://gist.github.com/psrdotcom/8350f1469a7a396a886e86b3f29ef38a#file-truecryptmountunmount-bat

                With the above batch file, you should be able to do following functionalities

                1. Mount a folder as drive
                2. Unmount the drive

                Hope, this information is useful to you.

                Please send your comments and feedback to psrdotcom@gmail.com




                Ubuntu and Windows system level utilities

                Hi friends,

                Please find the below links to customize or maintain your OS.

                Recover data in Ubuntu
                http://www.howtogeek.com/howto/15761/recover-data-like-a-forensics-expert-using-an-ubuntu-live-cd/

                Ubuntu LiveCD Customization from scratch
                https://help.ubuntu.com/community/LiveCDCustomizationFromScratch

                Boot windows7 from USB
                http://www.intowindows.com/how-to-install-windows-7vista-from-usb-drive-detailed-100-working-guide/
                http://kmwoley.com/blog/?p=345

                Windows OS Updates(SP?)
                http://www.bootdisk.com/

                Partition and Back utilities

                Backup
                http://www.todo-backup.com/products/home/free-backup-software.htm

                partition
                http://www.partition-tool.com/personal.htm

                disk to disk copy
                http://www.easeus.com/disk-copy/

                Data Recovery
                http://www.easeus.com/datarecoverywizard/free-data-recovery-software.htm

                Hope the above tools will be useful for you.

                Please send your comments and feedback to psrdotcom@gmail.com

                January 24, 2019

                bash: C:/Program: No such file or directory error solution in git bash with windows directory path having spaces

                Hi friends,

                Today, I have come across a situation where I have to execute the gitbash on windows with linux commands.

                The escape character doesn't alone solve the problem

                Problem


                Setting up an alias for bash where the path includes space

                $ alias DOCKER_HOME=C:/Program Files/Docker/Docker

                Error

                bash: C:/Program: No such file or directory

                Solution

                $ alias DOCKER_HOME=C:/"Program\ Files"/Docker/Docker

                Hope my solution helps you in resolving the issue.

                Please send your feedback and comments to psrdotcom@gmail.com

                May 24, 2017

                Prevent from WannaCry Ransome attack by disabling SMB protocol on Windows 10

                Hi friends,

                I want to share my knowledge on disabling SMB protocol on Windows 10.

                Procedure


                1. Click on Start Menu
                2. Type "Turn Windows Features On or Off"
                3. Uncheck the "SMB 1.0/CIFS File Sharing Support" as shown below
                4. Click on "OK"
                5. It will take some time to apply the changes
                6. You will be prompted with "Restart"
                7. Save your any unsaved work and restart the machine
                8. This is disable the SMB protocol, which is main reason to spread the WannaCry Ransome Attack


                Please send your review and feedback to psrdotcom@gmail.com

                April 27, 2017

                Windows: Find which port is getting used/mapped by which process/program with details from task manager

                Hi friends,

                Today, I have come across with a situation of finding the port-program mapping.

                Procedure


                • Open command prompt
                • Enter the following command
                • Syntax: netstat -aon | find ":"
                • Example: netstat -aon | find ":80"
                • Get the PID (Process Id) from the list



                • Execute the following command
                • Syntax: tasklist "PID eq "
                • Example: tasklist "PID eq 9192"


                Please send your queries and feedback to psrdotcom@gmail.com

                April 22, 2017

                Windows Oracle startup issue

                Hi friends,

                When your Oracle is unable to connect, do the following procedure

                Open command prompt
                Connect as sysdba
                cmd> sqlplus "/ as sysdba"
                sql> startup
                Once the command executed successfully, then you should be able to login to Oracle

                Please send your comments and feedback to psrdotcom@gmail.com

                January 20, 2017

                Change EOL (End Of Line) Character from Windows to Unix/Linux for all the files in current working directory

                Hi all,

                For a single file, you can do the change of EOL using notepad++.
                Reference: http://psrdotcom.blogspot.in/2017/01/change-eol-end-of-line-character-from.html

                But it would be difficult, if you want to do for multiple files in one go.

                I have found a solution to update EOL for all files in the current directory.

                Pre-requisite

                Make sure that, working directory contains only the files which you want to change EOL.

                Note: If not, copy the files to a new directory and change the EOL for all the files in that directory.

                Procedure

                1. Download dos2unix utility from sourceforge https://sourceforge.net/projects/dos2unix/
                2. Extract the zip file
                3. Tip: Make sure that the extracted path doesn't contain spaces.
                4. Keep the bin directory available in your PATH environment variables
                5. Download the customized batch file from GIST https://gist.github.com/psrdotcom/d73ff9590c3010253b5b2a886704b26b
                6. Extract if needed, and place the "dos2unixfolder.bat" in the same directory where the "dos2unix" is placed.
                7. Tip: If you place the batch file in the same folder of dos2unix.exe. You no need to add again the patch of batch file in environment PATH.
                8. Navigate to your folder, where you want all the files EOL to be changed
                9. Press "Right Click on Mouse" in empty area
                10. Select "Open Command Prompt Here"
                11. Type the batch file name "dos2unixfolder.bat"
                12. You will able to see the conversion process
                13. Once the conversion is completed, you can check the EOL coversion in notepad++.
                14. If you need to help in checking, refer to http://psrdotcom.blogspot.in/2017/01/change-eol-end-of-line-character-from.html


                Please send your comments and feedback to psrdotcom@gmail.com

                Change EOL (End Of Line) Character from Windows to Unix/Linux using Notepad++

                Hi all,

                Today I will explain about updating/converting EOL for a single file from windows format to unix/linux format.

                1. In Windows, the EOL (End-Of-Line) character is \r\n (CR LF) (Carriage Return, Line Feed)
                2. In Unix/Linux, the EOL character is \n (LF) (Line Feed)

                Check for EOL

                If you open the file in notepad++, you will be able to see the EOL character by following below steps:


                • Type the content and hit enter button on keyboard
                • Choose menu "View -> Show Symbol"
                • Check the "Show End of Line" option

                • Now, you will be able to view "CR LF" special symbols in you file at every line end as show below

                Update EOL

                To convert the EOL from Windows (CR LF) to Unix (LF), do the following

                • Click on "Edit" menu
                • Choose "EOL Conversion"
                • Select "Unix(LF)"

                • Now, you can check the update EOL character in your file. Example conversion show below

                This type of conversion useful, when you are updating file in windows and using the same file in U/Linux environment.

                Batch File Update

                For all files in one folder, you can follow my blog.
                Reference: http://psrdotcom.blogspot.in/2017/01/change-eol-end-of-line-character-from_20.html

                Send your comments and feedback to psrdotcom@gmail.com

                Featured Post

                Java Introdcution

                Please send your review and feedback to psrdotcom@gmail.com