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

                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

                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

                May 13, 2013

                Open command window shortcut with the current/present working directory/folder

                In my previous post, I had explained about opening command prompt and auto-executing a command.
                I was thinking it would be better, if we have a shortcut to open a command prompt in the present/current working directory/folder.

                I found two options to do that.
                GUI (Windows 7 and above):
                1. Hold “Shift” keyboard key and “Right Click” your mouse button
                2. You will find an option “Open Command Window Here”, click on it
                3. It will open a command window and path would be your current directory

                Custom Shortcut:
                1. Right Click your mouse
                2. Choose “New”
                3. Select “Shortcut”
                4. Enter type the location of the item as “cmd” and click on “Next” button
                5. Enter type a name for this shortcut as your own custom name e.g. CurDirCmdWindow and click on “FInish” button
                6. It will create a shortcut with your own specified name
                7. If you run/double click the shortcut, it will open a command window with the path “C:\Windows\System32” i.e. the default command window directory
                8. Now, we have to change the default opening directory to the drive where this shortcut located
                9. I hope you are familiar with %CD% environment variable in windows, which stores the current working directory path. We are going to use this now.
                10. Select the shortcut and “Right Click” with mouse
                11. Select “Properties”
                12. Now shortcut properties windows gets opened
                13. In “Shortcut” tab, navigate to “Start in:” textbox
                14. Replace the existing “C:\Windows\system32” with %CD%
                15. Note: Don’t change the target textbox content
                16. Click on “Apply” and then on “OK” buttons
                17. If you run/double click the shortcut, it will open a command window with your current directory as path.

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

                December 24, 2011

                Customize Command Prompt in Windows 7 with your own Icon, Starting Directory and more settings ...

                Hi all,

                Are you getting bored with the same command prompt with black colored background and other settings?

                You can customize your own command prompt and you can start from the preferred location (Directory) path, choose your own icon and lot more.

                Go ahead by following the below steps ..


                Creating the shortcut icon on Destop
                1. Right click on the desktop, select "New" -> "shortcut"
                2. Browse for the command prompt executable file "cmd.exe"
                3. If you have installed your Operating System in C drive then the path might be similar to this
                4. C:\Windows\System32\cmd.exe
                5. Click on "Next"
                6. Type the name for this shortcut, something like "MyCmdPrompt"
                7. Click on "Finish"
                8. Now you can see your command prompt named of your own choice
                9. Now, you can change some properties of your command prompt

                Changing the properties of the custom command prompt

                • Right click on the newly created shortcut from the Desktop
                • Select "Shortcut" tab and change the following settings
                1. Change the starting directory: Specify your own choice of directory path in the "Start in" box.
                2. Default Start in path: C:\Windows\System32
                3. Change the icon of your own choice: Click on "Change Icon" and Click on "Browse" button and Select the "C:\Windows\System32\imageres.dll" to list all the windows installed icons.
                4. Select an icon of your own choice and Click on "Ok"
                5. Run as Administrator by default: Click "Advanced" button, Select "Run as administrator" and Click "Ok"
                • Select "Options" tab and change the following settings
                  1. Check "Quick Edit mode" to copy and paste easily
                • Select "Font" tab and change the following settings
                  1. select your desired "Font" and "Size" settings
                • Select "Layout" tab and change the following settings
                1. select your desired "Window Size"
                2. Note: To see a bigger screen, increase the "Width and Height" attributes of the "Window Size"
                3. You can preview, your settings in the left side preview
                • Select "Colors" tab, You might be bored by seeing the same black and white combination.
                1. Choose your desired colors for Background, Foreground colors for both the "Screen" and "Pop-Up screen"
                • Click on "Apply" and then "Ok" to see your own command prompt.

                Hope this post is useful to you customize your own Command Prompt in Windows 7.

                For further queries, mail to psrdotcom@gmail.com

                Featured Post

                Java Introdcution

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