سؤال

My script

Set sh = CreateObject("WScript.Shell")
Set shortcut = sh.CreateShortcut("C:\Users\owner\Desktop\Internet Explorer.lnk")
shortcut.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe" & "www.google.com"
shortcut.Save

However this doesn't work when I run it, rather it creates a .PIF with the target being "C:\Program Files\Internet Explorer\iexplore.exewww.google.com"

I've tried it with double quotes but that didn't work.

Now I do add a space and it does the same thing. I'm starting to think that what I'm after isn't possible in script. Any help would be accepted.

هل كانت مفيدة؟

المحلول

The string concatenation in your code creates the following string:

C:\Program Files\Internet Explorer\iexplore.exewww.google.com

Since the extension .com indicates an 8-bit DOS binary a .pif shortcut is created instead of a .lnk shortcut.

You need to specify arguments to the executable via the Arguments property to make the shortcut turn out the way you want:

Set sh = CreateObject("WScript.Shell")
Set shortcut = sh.CreateShortcut("C:\Users\owner\Desktop\Internet Explorer.lnk")
shortcut.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe"
shortcut.Arguments  = "www.google.com"
shortcut.Save
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top