It is currently April 20th, 2024, 4:29 pm

RunCommand with Symlink

Post reviews, recommendations and questions about other software.
User avatar
tass_co
Posts: 516
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

RunCommand with Symlink

Post by tass_co »

Hi everyone :welcome:

I have a problem.

I want to update the target address of a previously created Symlink using the RunCommand plugin.
I opened the issue here. Because I think the problem is not related to Rainmeter.

Old
Link="C:\Users\Hasan Tahsin\Desktop\akor\DDD" target=A:\DDD-01
New
Link="C:\Users\Hasan Tahsin\Desktop\akor\DDD" target=#VarPath#

Code: Select all

[MeaSymLink]
Measure=Plugin
Plugin=RunCommand
Program=cmd
Parameter="mklink.exe" /d "%123456%\DDD" "#VarPath#" ; NOT WORK
Parameter="mklink.exe" /d "C:\Users\Hasan Tahsin\Desktop\akor\DDD" "#VarPath#" ; NOT WORK
PowerShell => Parameter=New-Item -Type SymbolicLink -Path "C:\Users\Hasan Tahsin\Desktop\akor\DDD" -Target "#VarPath#" ; NOT WORK
StartInFolder="%123456%"
State=Show
OutputType=ANSI
OuptputFile=#@#Error.txt
FinishAction=[!Refresh]
UpdateDivider=-1	
DynamicVariables=1	
ps:I created "%123456%" from "Win10\System=>Environments Variables".
This did not turn out well either...
I don't know where i going from here, but i promise it won't be boring... :great:
User avatar
Brian
Developer
Posts: 2679
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: RunCommand with Symlink

Post by Brian »

I might be wrong, but this could be an issue with the quotes.

When reading an option that contains both a starting and ending quote, Rainmeter will strip them.

This means, that an option like this: "mklink.exe" /d "%123456%\DDD" "#VarPath#", will end up looking like this to Rainmeter:
mklink.exe" /d "%123456%\DDD" "#VarPath# <<- Notice the starting and ending quotes are removed.

This really doesn't affect many options, but in some cases (like the Parameter/Program options in RunCommand), you may need a starting and ending quote to remain instead of being stripped. So, you need to double quote that option. It is mentioned in the RunCommand docs here (read the "Note" below the Timeout option).

Something like this: Parameter=""mklink.exe" /d "%123456%\DDD" "#VarPath#""

This might not solve your issue, but it is worth trying.

-Brian
User avatar
tass_co
Posts: 516
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

Re: RunCommand with Symlink

Post by tass_co »

Brian wrote: August 13th, 2022, 5:38 am I might be wrong, but this could be an issue with the quotes.

When reading an option that contains both a starting and ending quote, Rainmeter will strip them.

This means, that an option like this: "mklink.exe" /d "%123456%\DDD" "#VarPath#", will end up looking like this to Rainmeter:
mklink.exe" /d "%123456%\DDD" "#VarPath# <<- Notice the starting and ending quotes are removed.

This really doesn't affect many options, but in some cases (like the Parameter/Program options in RunCommand), you may need a starting and ending quote to remain instead of being stripped. So, you need to double quote that option. It is mentioned in the RunCommand docs here (read the "Note" below the Timeout option).

Something like this: Parameter=""mklink.exe" /d "%123456%\DDD" "#VarPath#""

This might not solve your issue, but it is worth trying.

-Brian
Thank you for the answer.
After a few tries, I started to think that the problem was caused by permission. (with Powershell)

Code: Select all

Parameter=new-item -itemtype symboliclink -path "A:\1" -name "Deneme" -value "A:\Fot"
Outputfile

Code: Select all

new-item : Administrator privilege required for this operation.
At line:1 char:1
+ new-item -itemtype symboliclink -path A:\1 -name Deneme -value A:\Fot ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (A:\Fotos:String) [New-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : NewItemSymbolicLinkElevationRequired,Microsoft.PowerShell.Commands.NewItemCommand
and with cmd

Code: Select all

Parameter=""""mklink.exe" /d "A:\1" "A:\Fot""""
output

Code: Select all

Microsoft Windows [Version 10.0.19044.1889]
(c) Microsoft Corporation. Tm haklar sakldr.

A:\>More? 
Can I get around this with lua or powershell script?
But I don't know much about both scripting languages :D


UPDATE:
I found the solution.

1.gpedit.msc
2.computer configuration
3.Security...
4.local policies
5.User...
6.Creating symbolic links => (Delete Administrator and Add Everyone) then log-out :thumbup:

sorry caps Turkish
13-08-2022 17_01_29-Yerel Grup İlkesi Düzenleyicisi.png
Then I created a lua script for creating a batch file

Code: Select all

function SymbolicWrite()
	local targetLink = SKIN:GetVariable('DevDev')
	local LinkLink = SKIN:GetVariable('LinkVar1')
	local FileName = SKIN:MakePathAbsolute('SymbolicWrite.bat')
	local CreateFile = io.open(FileName, 'w')

	if not CreateFile then
		print ('could not open ' .. FileName)
	else
		-- write the line
		-- Firstly delete old Symbolic Folder then create new Symbolic Folder
		CreateFile:write('rd "', LinkLink, '"', '\nmklink.exe /d ', '"', LinkLink, '"', ' ', '"', targetLink,'"')
		-- close the file
		CreateFile:close()
	end
end
Result:

Code: Select all

rd "LinkLink"
mklink.exe /d "LinkLink" "targetLink"
:great:
You do not have the required permissions to view the files attached to this post.
I don't know where i going from here, but i promise it won't be boring... :great:
User avatar
Yincognito
Rainmeter Sage
Posts: 7137
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: RunCommand with Symlink

Post by Yincognito »

tass_co wrote: August 13th, 2022, 11:15 amAfter a few tries, I started to think that the problem was caused by permission. (with Powershell)

Code: Select all

Parameter=new-item -itemtype symboliclink -path "A:\1" -name "Deneme" -value "A:\Fot"
Outputfile

Code: Select all

new-item : Administrator privilege required for this operation.
At line:1 char:1
+ new-item -itemtype symboliclink -path A:\1 -name Deneme -value A:\Fot ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (A:\Fotos:String) [New-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : NewItemSymbolicLinkElevationRequired,Microsoft.PowerShell.Commands.NewItemCommand
and with cmd

Code: Select all

Parameter=""""mklink.exe" /d "A:\1" "A:\Fot""""
output

Code: Select all

Microsoft Windows [Version 10.0.19044.1889]
(c) Microsoft Corporation. Tm haklar sakldr.

A:\>More? 
Can I get around this with lua or powershell script?
But I don't know much about both scripting languages :D
I know you already found a solution, but yes, you can get around this - simple example of killing a process copy pasted from one of my suite skins:

Code: Select all

; PwrShell: Start-Process powershell -windowstyle Hidden -verb RunAs \"Stop-Process -Name '#ProcessToKill#' -Force; Exit\"
; TaskKill: Start-Process taskkill -windowstyle Hidden -verb RunAs '/F /FI \"IMAGENAME eq #ProcessToKill#.*\"'

[MS_RunCommand_KillProcess]
Measure=Plugin
Plugin=RunCommand
Program=powershell
Parameter=Start-Process taskkill -windowstyle Hidden -verb RunAs '/F /FI \"IMAGENAME eq #ProcessToKill#.*\"'
State=Hide
OutputType=ANSI
Timeout=5000
DynamicVariables=1
The -verb RunAs is the part that runs stuff with credentials (e.g. as administrator and such).
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth