ConfusedAboutCPP
ConfusedAboutCPP

Reputation: 603

How to make a command prompt shortcut run a script on starting?

I can make a customized command prompt shortcut on my desktop to start in a particular directory and have some specified dimensions etc.

Now i have a script that sets some environment variables for the prompt and want to run it as soon as this shortcut is clicked.

How do i tell cmd or powershell to run this script in the current shell window and then show the shell ?

Upvotes: 0

Views: 2881

Answers (2)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200233

For cmd change the shortcut target to

%COMSPEC% /k C:\PATH\TO\your.cmd

and set the environment variables in your.cmd:

@echo off

set FOO=23
set BAR=42

Upvotes: 1

Frode F.
Frode F.

Reputation: 54881

Change the properties of the shortcut to include the file(scriptpath) and the noexit(to not close when done) parameter in the target-path. Example for target-path:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -file "c:\users\graimer\desktop\testscript.ps1"

Upvotes: 1

Related Questions