创建使用Unicode字符的快捷方式 [英] Create shortcut with Unicode character

查看:260
本文介绍了创建使用Unicode字符的快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用IWshRuntimeLibrary创建用C#快捷方式。快捷方式文件名在印地文नमस्ते。



我用下面的代码我剪断创建快捷方式,其中 shortcutName =नमस्ते。 LNK

  WshShellClass的WshShell =新WshShellClass(); 
IWshRuntimeLibrary.IWshShortcut快捷;

=快捷方式(IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(destPath +\\+ shortcutName);

shortcut.TargetPath = SOURCEPATH;
shortcut.Save();

shortcut.Save()我m到处以下异常。

 文件名,目录名或卷标语法不正确。 (从HRESULT异常:0x8007007B)


解决方案

您可以告诉出错的调试器。检查快捷方式,在调试器和注意,您的印地文的名字已被取代的问号。其产生无效的文件名,并触发异常。



您使用的是古老的脚本支持库,只是没有能力处理字符串。你需要使用一些更先进的日期。项目+添加引用,浏览选项卡,选择C:\windows\system32\shell32.dll。这增加了SHELL32命名空间到你的项目有几个接口做外壳相关的工作。刚好够得到这个打算,在ShellLinkObject界面让你修改.lnk文件的属性。需要一招,它不必从头开始创建一个新的.lnk文件的能力。您解决通过创建一个空的.lnk文件。这种行之有效:

 字符串destPath = @C:\temp 
串shortcutName = @नमस्तेLNK。

//创建空的.lnk文件
路径字符串= System.IO.Path.Combine(destPath,shortcutName);
System.IO.File.WriteAllBytes(路径,新字节[0]);
//创建一个ShellLinkObject引用.lnk文件
Shell32.Shell SHL =新Shell32.Shell();
Shell32.Folder DIR = shl.NameSpace(destPath);
Shell32.FolderItem ITM = dir.Items()项目(shortcutName);
Shell32.ShellLinkObject LNK =(Shell32.ShellLinkObject)itm.GetLink;
//设置.lnk文件的属性
lnk.Path = Environment.GetFolderPath(Environment.SpecialFolder.System)+ @\\\
otepad.exe
lnk.Description =nobugz在这里;
lnk.Arguments =sample.txt的;
lnk.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
lnk.Save(路径);


I'm using IWshRuntimeLibrary to create shortcut with c#. the shortcut file name is in Hindi "नमस्ते".

I'm using following code my snip to create shortcut, where shortcutName = "नमस्ते.lnk"

 WshShellClass wshShell = new WshShellClass();
 IWshRuntimeLibrary.IWshShortcut shortcut;

shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(destPath + "\\" + shortcutName);

 shortcut.TargetPath = sourcePath;
 shortcut.Save();

on shortcut.Save() I'm getting following exception.

The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B)

解决方案

You can tell what goes wrong with the debugger. Inspect "shortcut" in the debugger and note that your Hindi name has been replaced by question marks. Which produces an invalid filename and triggers the exception.

You are using an ancient scripting support library that's just not capable of handling the string. You'll need to use something more up-to-date. Project + Add Reference, Browse tab and select c:\windows\system32\shell32.dll. That adds the Shell32 namespace to your project with a few interfaces to do shell related work. Just enough to get this going, the ShellLinkObject interface lets you modify properties of a .lnk file. One trick is needed, it doesn't have the ability to create a new .lnk file from scratch. You solve that by creating an empty .lnk file. This worked well:

    string destPath = @"c:\temp";
    string shortcutName = @"नमस्ते.lnk";

    // Create empty .lnk file
    string path = System.IO.Path.Combine(destPath, shortcutName);
    System.IO.File.WriteAllBytes(path, new byte[0]);
    // Create a ShellLinkObject that references the .lnk file
    Shell32.Shell shl = new Shell32.Shell();
    Shell32.Folder dir = shl.NameSpace(destPath);
    Shell32.FolderItem itm = dir.Items().Item(shortcutName);
    Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink;
    // Set the .lnk file properties
    lnk.Path = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe";
    lnk.Description = "nobugz was here";
    lnk.Arguments = "sample.txt";
    lnk.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    lnk.Save(path);

这篇关于创建使用Unicode字符的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆