• 0

Creating Shortcut with NirCmd


Question

Here are the parameters for creating a shortcut with NirCmd:

shortcut [filename] [folder] [shortcut title] {arguments} {icon file}
{icon resource number} {ShowCmd} {Start In Folder} {Hot Key}

I have a difficult problem with a script not related to NirCmd, but
I'm hoping to use NirCmd's ability to create shortcuts.

The shortcut target line (argument) must look like this:

"D:\USB Scripts\HappyScript.exe" /r "D:\OCZ Drives\RunWebApps.sc"

HappyScript.exe runs the command lines in RunWebApps.sc.

Obviously, the quotes are a problem. With NirCmd, each parameter has
a set of quotes. How can I get NirCmd to enter a target line like the
one shown above?

Link to comment
https://www.neowin.net/forum/topic/1229739-creating-shortcut-with-nircmd/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Use ~q as an embeddable quote.  The parameter part would be something along the lines of: (the whole thing, including the outer quotes)

"/r ~qD:\OCZ Drives\RunWebApps.sc~q"
The regular quotes enclose that one parameter for NirCmd, the ~q gets substituted for a quote in the shortcut itself.

More help under "Special String Sequences"

http://www.nirsoft.net/utils/nircmd2.html#using

  • 0

I didn't think anyone would reply to my post, and there doesn't seem to be a
forum dedicated to all the NirSoft apps.

Thank you Mr. Norris.

I will read the NirCmd help file again. I just finished creating a script with a
different app, so my brain is a little fried.

I understand what you mean by an embeddable quote, but the target line must be
exact. The switch /r should have a space on either side. The executable pathname
and the location of the file containing the commands need a set of quotes. If not,
my script will not run. You show a quote followed by the /r switch ("/r). That puts
the quotes in the wrong place.

I'll experiment with the special character ~q. Hopefully, I can get the target line
correct.

When (or if) I get it right, I'll return to this thread and shoot off some fireworks
for Mr. Norris!

  • 0

Actually the quotes are in the correct place, I just pointed out what you needed to do.  You need to enclose that entire parameter, spaces and all, in quotes for the NirCmd program, otherwise it treats it as different parameters for the NirCmd program. The ~q gets substituted for quotes in the shortcut that it makes. (Why NirSoft didn't use proper escape sequences is beyond me but..)  Spelled out, the full command line would be this:

NirCmd shortcut "~qD:\USB Scripts\HappyScript.exe~q" "C:\" "Shortcut Title" "/r ~qD:\OCZ Drives\RunWebAps.sc~q" "" "" "" "D:\USB Scripts"

Change C:\ to wherever you actually want to create the shortcut, and change the title and icon stuff if it suits you too.  It generates a shortcut with your exact command line.. copy/pasted from the shortcut created:

"D:\USB Scripts\HappyScript.exe" /r "D:\OCZ Drives\RunWebApps.sc"
  • 0

After studying the NirCmd examples in the help file, I opened a text editor and
created a shortcut script using ~q.

It worked the first time!

Mr. Norris, your solution was 100% correct. I've created countless scripts over
many years, but I never had any reason to build a shortcut from the command line.

The script I just completed has hundreds of command lines. It appeared to be
error free. After running the script several times I noticed one serious problem
that seemed to doom my lengthy script to the junk pile.

When I realized NirCmd could create shortcuts from the command line, I was
hoping a "patch" using the shortcut command might save my script.

Anyway, here are your fireworks!

post-41590-0-86211500-1410897537.jpg

  • 0

just tested this.  This will create a notepad shortcut on your desktop.  copy this into a text file and change the extension from txt to vbs.  no need for nircmd, this is built into windows.  you can call vbs scripts from a batch file or call it through a logon script. 

 

 

  Quote

Set oWS = WScript.CreateObject("WScript.Shell")
userProfile = oWS.ExpandEnvironmentStrings( "%userprofile%" )
sLinkFile = userProfile & "\desktop\notepad.LNK"
Set oLink = oWS.CreateShortcut(sLinkFile)
    oLink.TargetPath = "C:\windows\notepad.EXE"
 '  oLink.Arguments = ""
 '  oLink.Description = "Notepad"   
 '  oLink.HotKey = ""
 '  oLink.IconLocation = "C:\windows\notepad.exe"
 '  oLink.WindowStyle = "1"   
 '  oLink.WorkingDirectory = "C:\windows"
oLink.Save

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Just checked for updates on my Windows 11  machines and my Windows 10 machines. Windows 10 is getting the June cumulative but my Windows 11 machines aren't finding a June cumulative.  Odd.
    • Microsoft to default-block more files in New Outlook and Outlook Web by Sayan Sen Back in 2019, Microsoft announced a big change to its list of blocked file types for attachments. At the time, Microsoft stated that it was doing so to improve security by adding "file extensions to the BlockedFileTypes property of existing OwaMailboxPolicy objects." The tech giant deems such file types as no longer secure for attachments and is a good way to protect customers from potentially malicious attacks from threat actors. Over time the company has expanded the block list for Outlook for the Web and also the New Outlook for Windows app. In a new message via the Microsoft 365 Admin Center portal, the company has announced that two more such file types will be added. However, the tech giant feels this should not affect most users, as these "newly blocked file types are rarely used." It writes: "As part of our ongoing efforts to enhance security in Outlook Web and the New Outlook for Windows, we’re updating the default list of blocked file types in OwaMailboxPolicy. Starting in early July 2025, the following file types will be added to the BlockedFileTypes list: .library-ms .search-ms" For admins, Microsoft says that no action is required if their respective organisations do not rely on the aforementioned file attachments. However, if they are still in use, then admins can "add them to the AllowedFileTypes property of your users’ OwaMailboxPolicy objects before the rollout." Speaking of which, this is set as a "major change" with the rollout expected to start in early July 2025. You can find information on how to do that in the official documentation on Microsoft's website here. For those wondering, the following file types are allowed by default: ".avi, .bmp, .doc, .docm, .docx, .gif, .jpg, .mp3, .one, .pdf, .png, .ppsm, .ppsx, .ppt, .pptm, .pptx, .pub, .rpmsg, .rtf, .tif, .tiff, .txt, .vsd, .wav, .wma, .wmv, .xls, .xlsb, .xlsm, .xlsx, .zip" You can find the list of blocked file types here on this Microsoft support article on the company's official website. If you are a system admin, you can view the message on the Microsoft 365 Admin Center under ID MC1090702.
    • Thanks Nik. This card is kinda what I'm looking for. Do you know if this connects to the motherboard via the TB Header / JTBT1 Header or if this is via the PCI Express slot? I was wondering if there was just a cable I could purchase that would give me a TB connection, since the header is already on the mainboard. Thanks
    • Adobe Acrobat Reader DC 2025.001.20531 by Razvan Serea Adobe Acrobat Reader DC software is the free, trusted standard for viewing, printing, signing, and annotating PDFs. Its the only PDF viewer that can open and interact with all types of PDF content – including forms and multimedia. It’s connected to Adobe Document Cloud – so you can work with PDFs on computers and mobile devices. Adobe Document Cloud is a revolutionary, modern and efficient way to get work done with documents in the office, at home or on-the-go. At the heart of Document Cloud is the all-new Adobe Acrobat DC, which will take e-signatures mainstream by delivering free e-signing with every individual subscription. Document Cloud includes a set of integrated services that use a consistent online profile and personal document hub. With Adobe Document Cloud, people will be able to create, review, approve, sign and track documents whether on a desktop or mobile device. Businesses will be able to take advantage of Document Cloud for enterprise which provides enterprise-class document services that integrate into systems of record such as CRM, HCM, CLM, and CMS, adding speed, efficiency and transparency to getting business done with documents. Adobe Acrobat Reader DC new feature highlights: Work with PDFs from anywhere with the new, free Acrobat DC mobile app for Android or iOS. Select functionality is also available on Windows Phone. Use the new Fill & Sign tool in your desktop software to complete PDF forms fast with smart autofill. Download the free Adobe Fill & Sign mobile app to add the same option to your iPad or Android tablet device. Save money on ink and toner when printing from your Windows PC. Store and access files in Adobe Document Cloud with 5GB of free storage. Get instant access to recent files across desktop, web, and mobile devices with Mobile Link. Sync your Fill & Sign autofill collection across desktop, web, and iPad devices. Adobe PDF Pack premium features includes: Convert documents and images to PDF files. Use your mobile device camera to take a picture of a paper document or form and convert it to PDF. Turn PDFs into editable Microsoft Word, Excel, PowerPoint, or RTF files. Combine multiple files into a single PDF (web only). Get signatures from others with a complete e-signature service. Send, track, and confirm delivery of documents electronically instead of using fax or overnight services (tracking not available on mobile). Store and access files online with 20GB of storage. Download: Adobe Acrobat Reader DC 64-bit | 626.0 MB (Freeware) Download: Adobe Acrobat Reader DC 32-bit | 516.0 MB Link: Adobe Acrobat Reader DC Home Page | Release Notes | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Reacting Well
      Alan- earned a badge
      Reacting Well
    • Week One Done
      IAMFLUXX earned a badge
      Week One Done
    • One Month Later
      Æhund earned a badge
      One Month Later
    • One Month Later
      CoolRaoul earned a badge
      One Month Later
    • First Post
      Kurotama earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      494
    2. 2
      ATLien_0
      268
    3. 3
      +FloatingFatMan
      223
    4. 4
      +Edouard
      200
    5. 5
      snowy owl
      141
  • Tell a friend

    Love Neowin? Tell a friend!