![]() There are some additional attributes you can mangle through this object, too: Name MemberType DefinitionĪrguments Property string Arguments () You may have to explicity specify the path to PS in your file, but it should work. %PWS% -Command "$ws = New-Object -ComObject WScript.Shell $s = $ws.CreateShortcut(%SHORTCUT%) $S.TargetPath = %TARGET% $S.Save()" Set PWS=powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile Here's a similar solution using powershell (I know, you can probably re-write your whole batch file in PS, but if you just want to Get It Done™.) set TARGET='D:\Temp' SET Esc_LinkTarget=%%SYSTEMROOT%%\notepad.exeĮcho Set oWS = WScript.CreateObject^("WScript.Shell"^)Įcho sLinkFile = oWS.ExpandEnvironmentStrings^("!Esc_LinkDest!"^)Įcho Set oLink = oWS.CreateShortcut^(sLinkFile^)Įcho oLink.TargetPath = oWS.ExpandEnvironmentStrings^("!Esc_LinkTarget!"^) SET Esc_LinkDest=%%HOMEDRIVE%%%%HOMEPATH%%\Desktop\!LinkName!.lnk Here's a more complete snippet from an anonymous contributor (updated with a minor fix): off Running the above script results in a new shortcut on my desktop: For example, like so: offĮcho Set oWS = WScript.CreateObject("WScript.Shell") > CreateShortcut.vbsĮcho sLinkFile = "%HOMEDRIVE%%HOMEPATH%\Desktop\Hello.lnk" > CreateShortcut.vbsĮcho Set oLink = oWS.CreateShortcut(sLinkFile) > CreateShortcut.vbsĮcho oLink.TargetPath = "C:\Windows\notepad.exe" > CreateShortcut.vbs So, if you really must do it, then you could make your batch file write the VB script to disk, invoke it and then remove it again. ' oLink.WorkingDirectory = "C:\Program Files\MyApp" ' oLink.IconLocation = "C:\Program Files\MyApp\MyProgram.EXE, 2" OLink.TargetPath = "C:\Program Files\MyApp\MyProgram.EXE" Set oLink = oWS.CreateShortcut(sLinkFile) Optional sections in the VBscript below are commented out: Set oWS = WScript.CreateObject("WScript.Shell") Seems like there is some shortcut.exe in some resource kit which I don't have.Īs many other sites mention, there is no built-in way to do it from a batch file. There is some very useful information on this site:
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |