New
#21
What is your application?
What is your application?
Your application does not recognize environment variables.
It is able to put environment variables in path for other scripts, and they work. It only doesn't work when I try to use an environment variable in place of username, when I'm defining a path for a shortcut.
var: //string BatFileShtCut("C:\Users\%username%\Desktop\PosnPushAlert.lnk"); string BatFileShtCut("C:\Users\Stan\Desktop\PosnPushAlert.lnk");
The above will not work if I use the version with the environment variable in place of the actual user name.
When I run this from EasyLanguage:
//TESTThis works where I'm writing %username% to a .bat file and then running the .bat file, but if I try to invoke the shortcut using an environment variable in the path instead of the username, it does not work, so you are right!!!Code:method void OnButtonClick2(Object sender, EventArgs args ) begin BatFile1 = FilePath+"PosnPushAlert"+".bat"; FileDelete(BatFile1); Bat1Text = "Powershell.exe -executionpolicy remotesigned -File C:\Users\%UserName%\Desktop\PushOverPS.ps1 "; Bat1Text += doublequote+DTS()+" This is a test. "+doublequote; FileWrite(BatFile1,Bat1Text); if Elsystem.io.File.Exists(BatFile1) then environment.start(BatFileShtCut); Textbox1.Text = "OK"; end;
Thanks.
- - - Updated - - -
I apologize for sending everyone on a wild goose chase here. I now see what was happening. End of story.
Thanks to all.
So, just a p.s. on this. I just moved the shortcut to a path that does not have username in it and... problem solved!!!
What a simple solution!
If you create a shortcut with the Create Shortcut wizard, any environmental variables in theTarget
path will be evaluated when the shortcut is created, leaving you with a staticTarget
.
To create a shortcut with environmental variables that are evaluated when the shortcut is launched, you have to create the shortcut programatically.
PowerShell:
Properties of MyTest.lnk after creation:Code:$wshell = New-Object -ComObject wscript.shell $sc = $wshell.CreateShortcut("c:\Users\Keith\mytest.lnk") $sc.targetPath = '%USERPROFILE%\Sandbox' $sc.save()
![]()
Last edited by KeithM; 08 Mar 2021 at 14:51.