Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can't create shortcut whose name contains Unicode?

408 views
Skip to first unread message

Cat

unread,
May 6, 2008, 6:40:59 AM5/6/08
to
var oShellLink = WshShell.CreateShortcut( path+ "\\Some Asian
characters.lnk");
...
ShellLink.Save();

I created a simple wsf script using NotePad. I even saved it in UTF-8
encoding. But the code above fails because the scripting engine cannot
understand the Asian characters.

Error : Unable to save shortcut ".....??????.lnk".
Code 8007007B

Is there any way to create a shortcut in Unicode using WSH? If it is
impossible, please tell me also, then I can start finding another way.
Thank you.

Cat

unread,
May 6, 2008, 6:42:47 AM5/6/08
to

James Whitlow

unread,
May 6, 2008, 9:39:05 AM5/6/08
to
"Cat" <typi...@gmail.com> wrote in message
news:c21c8d96-cc6a-48cc...@w8g2000prd.googlegroups.com...

You stated that this is a wsf (and not a vbs) script correct? If so, did
you specify the coding in your opening xml tag? Something like:

<?xml version="1.0" encoding="ISO-8859-1" ?>


Cat

unread,
May 6, 2008, 7:28:31 PM5/6/08
to
Thanks for the reply but it didn't help.
<?xml version="1.0" encoding="UTF-8" ?>
<job id="ShortcutMaker">
<script language="JScript">
<![CDATA[
var WshShell = WScript.CreateObject("WScript.Shell");
var oShellLink = WshShell.CreateShortcut("C:\\馬鹿な.lnk");
//var oShellLink = WshShell.CreateShortcut("C:\\This works.lnk");
oShellLink.TargetPath = "C:\\Windows\\Notepad.exe";
oShellLink.IconLocation = "Notepad.exe, 0";
oShellLink.Save();
]]>
</script>
</job>

On May 6, 10:39 pm, "James Whitlow" <jwhitlow.60372...@bloglines.com>
wrote:
> "Cat" <typing...@gmail.com> wrote in message

Paul Randall

unread,
May 6, 2008, 11:52:42 PM5/6/08
to
My Compaq US-English Vista computer came with a few files with Unicode
characters in their file name. These file names are strange by US
standards. I assume that the file name characters are encoded in
16-bit Unicode and not UTF-8 or other variable-byte-length character
encoding. I don't see how the file system could cope with multiple
encodings in file names.

Of course, maybe my problem with accessing these files is that the
scripting File System Object isn't showing me the actual characters in
the file names. If the partition were Fat32, I could use my Norton
Utilities to view the sector containing the directory entry for these
files. As far as I know, I don't have a tool that can view NTFS
directory sectors. Does anyone know of a tool, preferably free, that
can display NTFS directory sectors? Perhaps if we can find out what
Unicode file names actually look like on the hard drive then we can
figure out how to create one.

-Paul Randall


"Cat" <typi...@gmail.com> wrote in message

news:3875407d-65b7-4bee...@z24g2000prf.googlegroups.com...

Alex K. Angelopoulos at

unread,
May 7, 2008, 4:22:27 PM5/7/08
to
Found a fix. From running this in Dependency Walker, it appears that the
problem is the Save() method in WshShell's shortcut object. It appears that
it explicitly uses ANSI functions in OleAut32.dll to create the file, thus
choking on the wide characters.

Although you can't create the shortcut with the name you want, you can still
create the shortcut and then rename it. I didn't try using the
Scripting.FileSystemObject, but using cmd.exe's rename command worked fine.
Below is my example; since I'm using one of the Latin ISO sets in news, your
filename may be mangled, but I think you get the picture. I included a brief
wait in the script to ensure that the filename is available before I try the
rename operation; this might not be necessary in practice.

<?xml version="1.0" encoding="UTF-8" ?>
<job id="ShortcutMaker">
<script language="JScript">
<![CDATA[
var WshShell = WScript.CreateObject("WScript.Shell");

var oShellLink = WshShell.CreateShortcut("C:\\This works.lnk");


oShellLink.TargetPath = "C:\\Windows\\Notepad.exe";
oShellLink.IconLocation = "Notepad.exe, 0";
oShellLink.Save();

WScript.Sleep(3000);
WshShell.Run('cmd /c rename "C:\\This works.lnk" 馬鹿な.lnk');
]]>
</script>
</job>

"Cat" <typi...@gmail.com> wrote in message

news:c21c8d96-cc6a-48cc...@w8g2000prd.googlegroups.com...

0 new messages