Create Symlinks?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Create Symlinks?

Post by Phil Pendlebury » Tue Apr 25, 2017 1:54 pm

Greetings,

I have been working on a script that creates a bunch of SymLinks - it uses command line like this:

Code: Select all

Run>cmd.exe /c mklink /D  "%source%" "%target%"
I need to create about 27 Symlinks and the way I have the script so far I am having to pass 27 command lines.

This is slightly problematic as if the user has not run the script as admin he has to accept the UAC dialog for every command.

I can force to run as admin but still you see multiple separate command windows on the screen (albeit briefly).

Does MSched have any native way to create symlinks? Like "CreateDir>"

Can anyone suggest a smooth way to get 27 commands to run silently?

TIA. P :-)
Phil Pendlebury - Linktree

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Create Symlinks?

Post by JRL » Tue Apr 25, 2017 3:02 pm

Hi Phil,
...but still you see multiple separate command windows on the screen...
I don't off hand know the rest, but the popup command windows can be eliminated by setting the MS system variable RP_Windowmode to 0 prior to the Run>cmd.exe line.

Code: Select all

Let>RP_Windowmode=0
Run>cmd.exe /c mklink /D  "%source%" "%target%"

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Create Symlinks?

Post by Phil Pendlebury » Wed Apr 26, 2017 7:10 am

JRL wrote:Hi Phil,
...but still you see multiple separate command windows on the screen...
I don't off hand know the rest, but the popup command windows can be eliminated by setting the MS system variable RP_Windowmode to 0 prior to the Run>cmd.exe line.

Code: Select all

Let>RP_Windowmode=0
Run>cmd.exe /c mklink /D  "%source%" "%target%"
Thanks buddy that will be very useful. :-)
Phil Pendlebury - Linktree

zabros2020
Pro Scripter
Posts: 70
Joined: Sun May 03, 2009 11:49 pm
Location: AU

Re: Create Symlinks?

Post by zabros2020 » Fri Apr 28, 2017 5:45 am

Hi Phil....There is a way to do this...here is the code:

Code: Select all


'--------------------------
'RUN COMMAND PROMPT HIDDEN
'[RP_WINDOWMODE=0]
'By setting the RP_WINDOWMODE variable programs can be executed minimized, maximised, hidden or normal.
'RP_WINDOWMODE can be one of the following
'0: Hidden 1: Normal (default)  2: Minimized 3: Maximized
'[&]
'Use to separate multiple commands on one command line.
'Cmd.exe runs the first command, and then the second command.
'& [...]  command1 & command2
Let>amp=&
Let>symLinks=
Let>numLinks=27
ArrayDim>sourceArr,%numLinks%
ArrayDim>targetArr,%numLinks%
Let>i=0
Repeat>i
  Add>i,1
  'you can remove the need to use array and other vars to remove the need for Unnecessary code...
  'this is just to ellustrate the function of & in cmd with vars as  sourceArr_1 targetArr_1 etc
  Let>sourceArr_%i%=%DESKTOP_DIR%\sl_%i%
  Let>targetArr_%i%=C:\Temp\
  Let>source=sourceArr_%i%
  Let>target=targetArr_%i%
  Let>cmdLine=mklink /D %source% %target%
  'form the command to execute in one execution
  ConCat>%symLinks%,%cmdLine%
  'dont append ampersand to last cmd
  If>i<>%numLinks%
    'append & for next cmd
    ConCat>%symLinks%,%SPACE%%amp%%SPACE%
  EndIf
Until>i=%numLinks%

Let>RP_Windowmode=0
'ONE CMD LINE EXECUTION! OF HOW EVER LINES YOU WANT! :)
Run>cmd.exe /c %symLinks%

'same as doing it by defining each var like this:
'Run>cmd.exe /c mklink /D "%sourceArr_1%" "%targetArr_1%" & mklink /D "%sourceArr_2%" "%targetArr_2%" & mklink /D "%sourceArr_3%" "%targetArr_3%"
Loving MS's Capabilities!!!

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Create Symlinks?

Post by Phil Pendlebury » Fri Apr 28, 2017 8:31 am

Thanks Zabros. So basically join the commands with SPACE & SPACE. Very cool I had no idea. Thanks again. :-)

I also found some further info on this:
You can use the special characters listed in the following table to pass multiple commands.

Code: Select all

& [...]  command1 & command2
Use to separate multiple commands on one command line. Cmd.exe runs the first command, and then the second command.

&& [...]  command1 && command2
Use to run the command following && only if the command preceding the symbol is successful. Cmd.exe runs the first command, and then runs the second command only if the first command completed successfully.

|| [...]  command1 || command2
Use to run the command following || only if the command preceding || fails. Cmd.exe runs the first command, and then runs the second command only if the first command did not complete successfully (receives an error code greater than zero).

( ) [...]  (command1 & command2)
Use to group or nest multiple commands.
Phil Pendlebury - Linktree

zabros2020
Pro Scripter
Posts: 70
Joined: Sun May 03, 2009 11:49 pm
Location: AU

Re: Create Symlinks?

Post by zabros2020 » Fri Apr 28, 2017 11:40 am

Welcome!
Yes, so simple yet so powerful.
Love how Macro Scheduler surprises us all with its powerful integration for Windows
Loving MS's Capabilities!!!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts