Showing posts with label Command. Show all posts
Showing posts with label Command. 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

June 09, 2022

Generate Free SSL HTTPS Certificates with 90 days validity using letsencrypt

 Hi all,

As discussed in my earlier blog, Generate Free SSL Certificate using ZeroSSL where the limitation of one free certificate on ZeroSSL can be eliminated using Get HTTPS for free!

This process includes the following prerequisites and procedures.

Note: This process is not for beginners or production usage scenarios. Use this process if you are knowledgeable about certificate generation.

Prerequisites

  • OpenSSL command line
  • [Li]nix / Mac OS

Procedure

  • Open the URL https://gethttpsforfree.com
  • It has 5 steps
    • Account Info
    • Certificate Signing Request
    • Sign API Requests
    • Verify Ownership
    • Install Certificate
  • In each step, some commands or processes need to be followed to get the free SSL certificate.

  1. Account Info
    1. In this step, we will be providing the email and public key.
    2. Keep the generated private key security in your system.
      • Note: If you are unsure about the public key generation commands, click on the "how do I generate this?" link, which is available over the public key input textbox.
  2. Certificate Signing Request (CSR)
    1. Generate the CSR for the required domains
      • Note: You can generate the CSR for wildcard certificates and www subdomain with the same command
    2. Try to follow the same format, including the line feeds mentioned below.
    3. #change "/etc/ssl/openssl.cnf" as needed:
          #  Debian: /etc/ssl/openssl.cnf
          #  RHEL and CentOS: /etc/pki/tls/openssl.cnf
          #  Mac OSX: /System/Library/OpenSSL/openssl.cnf
      
          openssl req -new -sha256 -key domain.key -subj "/" \
            -reqexts SAN -config <(cat /etc/ssl/openssl.cnf \
            <(printf "\n[SAN]\nsubjectAltName=DNS:foo.com,DNS:www.foo.com")) 
  3.  Sign API Requests
    1. Sign all the requests with the private key
    • Note: You need to copy the command and execute it on your PC/Mac terminal, and the result needs to be pasted on the web page.
  4. Verify Ownership
    1. In this step, you need to prove your domain ownership
    2. You will be given 3 options
      1. Python server
      2. file-based
      3. DNS record (I've used this option)
        1. Update the DNS records with new TXT entries, and use the online dig tool to make sure the records are visible.
        2. After we verify the availability of the records, you need to click on the respective buttons on the web page.
    3. Repeat the same steps for each domain on CSR (www and any sub-domains).
  5. Install Certificate
    1. You will be able to receive your certificate in "chained.pem" format
    2. Copy and paste the first certificate section (e.g. the first "-----BEGIN CERTIFICATE-----" section) into a text file named "domain.crt".
    3. Copy and paste the second certificate section (e.g. the second "-----BEGIN CERTIFICATE-----" section) into a text file named "intermediate.pem".
    • Note: Expand the "how do I install this?" link for quick help.
Hope this will help you to generate free SSL for your websites.

Request you to send 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.

                March 03, 2020

                Run local file server with NPM http-server

                Hi folks,

                Today i'll explian the process of making your folder as a standalone file server.

                Objective

                Make my folder contents browse over http

                Procedure


                • Install Node
                • Install http-server module in node globally
                  • npm install -g http-server
                • Open terminal/command-prompt
                • Navigate to your folder
                • Run the following command to start the server
                  • http-server .
                • or simply run
                  • hs .
                • Run from anywhere with full path of the folder
                  • hs C:\FileFolder
                • Starting up http-server, serving .
                • Available on:
                  • http://10.10.6.2:8080
                  • http://127.0.0.1:8080
                  • http://youripaddress:8080
                • Hit CTRL-C to stop the server
                • You should be able to browse your file folder contents with any of the above URLs
                Hope you are able to access your file contents over the browser

                Tip: Using this approach, you can share your content over intranet/internet with full control over data as read only.

                After stopped the server, access to the folder is stopped.

                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

                November 27, 2015

                Creating Symbolic Link (Symlink) in Windows 7

                Hi friends,

                In Linux, it is easy to create symbolic link (symlink) with "ln" command.
                But what about in windows?

                I found one GUI and command for creating the symbolic links in windows.

                Pre-requisites

                1. Visual Studio 2005 redistributable
                2. Link Shell Extension
                3. Download the above executables from here based on OS and system architecture
                4. For Windows 7 64-bit, I have downloaded the following highlighted in black box

                Procedure

                • Install the Visual Studio 2005 redistributable
                • Install Link Shell Extension
                • You should be able to see an option in context menu
                • Select the file/folder
                • Right click and select the option "Pick Link Source"

                • Now, the file is been picked
                • Navigate to go the destination folder where you want to create the symbolic link
                • Right click on the empty space of the folder
                • Select Drop As and select "Hardlink or Symbolic Link" based on your requirement


                • You should be able to see the file type as .symlink


                References

                http://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/

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

                August 22, 2015

                UDPCast, udp sender and udp receiver Sharing files over LAN/Wi-Fi

                Hi admins,

                Have you ever thought of sending files/folders to all your systems which are connected over LAN?
                Have you ever thought of copying the entire partitions including OS to all your systems with same configuration which are connected over LAN in your lab?

                You might be using some proprietary tools.

                Let me share my knowledge of open source tools in Ubuntu to perform the job.

                It is UDP Case with following operations
                1. udp-sender
                2. udp-receiver

                Simple usage can be seen in References 2

                References

                https://www.udpcast.linux.lu/cmd.html
                https://www.udpcast.linux.lu/cmdlinedoc.html

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

                October 31, 2014

                Change IP Address and DNS from static to DHCP and vice versa in Windows Command Line Dynamically using Batch file script

                Hi friends,

                I was frequently changing my system network from static to dynamic.

                I was fed-up with the manual changes by entering the static IP address and changing it to dynamic.

                I though of creating a batch file, which requests user to select options and proceed further.

                 

                I found something on Internet, just modified it for my purpose and thought of sharing with you all.

                 

                • Check your network name
                  • cmd> netsh interface show interface
                • It will list all the network interfaces connected to your system
                  • Select the network which you want to change the settings
                • Modify the below code with appropriate network name, IP address, subnet, gateway and DNS server

                @echo off

                set NETWORK="Local Area Connection"
                set IP=10.9.40.95
                set SUBNET=255.255.255.0
                set GATEWAY=10.9.40.47
                set DNSSERVER=192.168.178.1

                echo Choose:
                echo [S] Set Static IP
                echo [D] Set DHCP
                echo.

                :choice
                SET /P C=[S,D]?
                for %%? in (S) do if /I "%C%"=="%%?" goto S
                for %%? in (D) do if /I "%C%"=="%%?" goto D
                goto choice

                :S
                @echo off
                echo "Setting Static IP Address, Subnet Mask and DNS Server"
                netsh interface ip set address %NETWORK% static %IP% %SUBNET% %GATEWAY% 1
                netsh interface ip set dnsservers %NETWORK% static %DNSSERVER% primary
                netsh interface ip show config
                pause
                goto end

                :D
                @echo off
                echo "Resetting IP Address, Subnet Mask and DNS server For DHCP"
                netsh interface ip set address name=%NETWORK% dhcp
                netsh interface ip set dns %NETWORK% dhcp
                ipconfig /renew

                echo "New IP Address, Subnet Mast and DNS Server for %computername%:"
                netsh interface ip show config
                pause
                goto end

                :end

                Now enjoy the feature of changing IP address with 3 clicks

                 

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

                Blogger Labels: Change,DHCP,vice,Windows,Command,Line,Batch,script,system,user,options,Internet,purpose,Check,interface,interfaces,Select,settings,Modify,gateway,server,NETWORK,Local,Area,Connection,SUBNET,DNSSERVER,Choose,Static,Mask,Mast,feedback,netsh,goto,config

                December 12, 2013

                PhoneGap Installation and running Sample Application on iOS



                Pre-requisites


                Softwares

                     iOS SDK
                     Xcode command line tools
                     Node.js
                     Cordova (Zip)

                Setup Environment Variables


                     NODEJS_HOME
                     CORDOVA_IOS

                PATH Environment Variable Update

                1) Open a terminal prompt

                2) Type sudo vi /etc/launchd.conf (note: this file might not yet exist)

                3) Put contents like the following into the file

                # Set environment variables here so they are available globally to all apps
                # (and Terminal), including those launched via Spotlight.
                #
                # After editing this file run the following command from the terminal to update
                # environment variables globally without needing to reboot.
                # NOTE: You will still need to restart the relevant application (including
                # Terminal) to pick up the changes!
                # grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
                #
                # See http://www.digitaledgesw.com/node/31
                # and http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/
                #
                # Note that you must hardcode the paths below, don't use enviroment variables.
                # You also need to surround multiple values in quotes, see MAVEN_OPTS example below.
                #

                # Nodejs Installed path. By default the path is your home directory->.npm directory path
                setenv NODEJS_HOME $HOME/.npm

                # Choose the location where you have unzipped the cordova iOS folder
                setenv CORDOVA_IOS /cordova-ios


                PATH Environment Variable Update

                create .bash_profile file in your home folder
                Enter the following content

                #!/bin/bash
                export PATH=$PATH:$NODEJS_HOME:$CORDOVA_IOS/bin

                Install phonegap

                If you are behind a proxy please set the proxy to npm (Node.js) command
                Syntax:-
                (For HTTP) $ npm config set proxy http://proxy.company.com:port
                (For HTTPS) $ npm config set https-proxy http://proxy.company.com:port

                Run the install command

                $ sudo npm install -g phonegap
                $ sudo npm install -g cordova

                Note: If you face any errors
                • Remove the .npm directory from the home folder
                • Upgrade npm (sudo npm install -g npm)
                • Clear the global npm cache (sudo npm cache clear)
                • Clear the user npm cache (npm cache clear)

                Create Project

                Syntax: phonegap create
                $ phonegap create hello com.example.hello "HelloWorld"

                By default the skeleton folder structure will be created.
                Note: if you didn’t get the default skeleton (www, js, css folders and other files), please copy from the sample-hello-world project of phonegap to your www project folder

                $ cd hello
                $ cordova platform add ios
                $ phonegap build ios



                Adding Plugins to your project

                Pre-requisites

                                       Install Git
                Tip: If you are behind a proxy then please add it your configuration
                Syntax: git config —global http.proxy http://proxyusername:proxypassword@server.company:port
                Ex: git config —global http.proxy http://abc:123@xyz.com:8081

                                       Add git\bin to your PATH environment variable
                                       You need to download the git files from https://git-wip-us.apache.org. So make sure that the above specified URL is not blocked by your firewall
                                       Navigate to your project directory in command prompt by changing the directory
                cd

                Note:
                If you have some issues download cordova zip (unzip cordova-ios zip) and copy it to your home directory-> ~/.cordova/lib/ios/cordova/3.2.0/

                Install Plugin

                Syntax: phonegap local plugin add
                Ex:- phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

                Tip: If this doesn’t run then try with cordova
                Syntax: cordova plugin add
                Ex:- cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

                Add the Feature to config.xml (Ex: Accelerometer)

                    name="Accelerometer">
                        name="ios-package" value="CDVAccelerometer" />
                   


                Remove Plugin

                Syntax: phonegap local plugin remove
                Ex:- phonegap local plugin remove https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

                Tip: If this doesn’t run then try with cordova
                Syntax: cordova plugin remove
                Ex:- cordova plugin remove https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

                Alternative
                You can install “plugman” to plug and play with plugins by following this link
                Using Plugman to Manage Plugins
                Note: plugman doesn’t take proxy

                References

                Featured Post

                Java Introdcution

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