以上就是给各位分享在节点上访问Windows快捷方式,其中也会对.lnk数据进行解释,同时本文还将给你拓展ApacheHttpServer在htdocs下建立的windows快捷方式无效、delphi
以上就是给各位分享在节点上访问Windows快捷方式,其中也会对.lnk数据进行解释,同时本文还将给你拓展Apache Http Server在htdocs下建立的windows快捷方式无效、delphi – 如何在Windows桌面上创建文件快捷方式(* .lnk文件)?、Java中的Windows快捷方式(.lnk)解析器?、Perl 创建 Windows 下的快捷方式等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- 在节点上访问Windows快捷方式(.lnk)数据(访问节点的设备)
- Apache Http Server在htdocs下建立的windows快捷方式无效
- delphi – 如何在Windows桌面上创建文件快捷方式(* .lnk文件)?
- Java中的Windows快捷方式(.lnk)解析器?
- Perl 创建 Windows 下的快捷方式
在节点上访问Windows快捷方式(.lnk)数据(访问节点的设备)
有什么方法可以解析Node中.lnk文件中的快捷方式数据(例如,主要是它指向的路径)?
答案1
小编典典您可以使用npm包 windows-shortcuts
https://www.npmjs.com/package/windows-
shortcuts
例:
ws.query("C:/ProgramData/Microsoft/Windows/Start Menu/Windows Update.lnk", console.log);/* From console:null { expanded: { args: ''startmenu'', workingDir: ''C:\\Windows\\system32'', icon: ''C:\\Windows\\system32\\wucltux.dll'' }, target: ''%windir%\\system32\\wuapp.exe'', args: ''startmenu'', workingDir: ''%windir%\\system32'', runStyle: 1, icon: ''%windir%\\system32\\wucltux.dll'', iconIndex: ''0'', hotkey: 0, desc: ''Delivers software updates and drivers, and provides automatic updating options.'' }*/
Apache Http Server在htdocs下建立的windows快捷方式无效
我在本机安装了Apache2.2,并且成功启动。
http://localhost:8090/index.html
可以访问,显示:It works!
我在<Apache_home>/htdocs/
下面建立了自己的test.html,也可以通过
http://localhost:8090/test .html
访问到我自己新建的 <Apache_home>/htdocs/test .html 。
但是,我在<Apache_home>/htdocs/ 下面建立了一个windows的快捷方式,指向另外一个静态文件目录,发现无法通过URL访问到这个静态文件。
例如:
快捷方式<Apache_home>/htdocs/mywork/
指向我的D:/mywork/
但是通过url: http://localhost:8090/mywork/test .html 访问不到 D:/mywork/test .html,
Apache的日志提示:
127.0.0.1 - - [06/Apr/2012:16:47:33 +0800] "GET /mywork/test.html HTTP/1.1" 404 207
我想问下,apache不支持这种通过windows快捷方式访问静态资源么?还是说,需要配置才能支持?请指导一下。
(印象中,之前我在linux下面是可以使用link来指向静态资源的。)
delphi – 如何在Windows桌面上创建文件快捷方式(* .lnk文件)?
function GetDesktopFolder: string; var buf: array[0..MAX_PATH] of Char; pidList: PItemIDList; begin Result := StrNoDesktopFolderFo; SHGetSpecialFolderLocation(Application.Handle,CSIDL_DESKTOP,pidList); if (pidList <> nil) then if (SHGetPathFromIDList(pidList,buf)) then Result := buf; end; procedure p; var i: Integer; IObject: IUnkNown; ISLink: IShellLink; IPFile: IPersistFile; PIDL: PItemIDList; InFolder: array[0..MAX_PATH] of Char; TargetName: string; LinkName: string; begin TargetName := 'c:\folder\exeFile.exe';//hardcoded example IObject := CreateComObject(CLSID_ShellLink) ; ISLink := IObject as IShellLink; IPFile := IObject as IPersistFile; with ISLink do begin SetDescription('what ever'); SetPath(pChar(TargetName)) ; SetWorkingDirectory(pChar(ExtractFilePath(TargetName))) ; end; SHGetSpecialFolderLocation(0,CSIDL_DESKTOPDIRECTORY,PIDL) ; SHGetPathFromIDList(PIDL,InFolder) ; LinkName := getDesktopFolder+'\'; i := ; LinkName:= linkname+ExtractFileName(TargetName)+'.lnk'; if LinkName = StrNoDesktopFolderFo then Exit; if not FileExists(LinkName) then IPFile.Save(PWChar(LinkName),False); Application.Terminate; end;
上面的代码在Delphi中导致很多错误,不能运行两次……
有任何想法吗 ?
顺便说一句.来源不是我的,它是从网上的地方拿起来的.
解决方法
uses ShlObj,ComObj,ActiveX; function GetDesktopFolder: string; var PIDList: PItemIDList; Buffer: array [0..MAX_PATH-1] of Char; begin Result := ''; SHGetSpecialFolderLocation(Application.Handle,PIDList); if Assigned(PIDList) then if SHGetPathFromIDList(PIDList,Buffer) then Result := Buffer; end; function CreateDesktopShellLink(const TargetName: string): Boolean; var IObject: IUnkNown; ISLink: IShellLink; IPFile: IPersistFile; PIDL: PItemIDList; LinkName: string; InFolder: array [0..MAX_PATH-1] of Char; begin Result := False; IObject := CreateComObject(CLSID_ShellLink); ISLink := IObject as IShellLink; IPFile := IObject as IPersistFile; with ISLink do begin SetDescription('Description ...'); SetPath(PChar(TargetName)); SetWorkingDirectory(PChar(ExtractFilePath(TargetName))); end; SHGetSpecialFolderLocation(0,PIDL); SHGetPathFromIDList(PIDL,InFolder) ; LinkName := IncludeTrailingBackslash(GetDesktopFolder); LinkName := LinkName + ExtractFileName(TargetName) + '.lnk'; if not FileExists(LinkName) then if IPFile.Save(PWideChar(LinkName),False) = S_OK then Result := True; end; procedure TForm1.Button1Click(Sender: TObject); begin if CreateDesktopShellLink('C:\Folder\ExeFile.exe') then ShowMessage('Link has been created ...'); end;
Java中的Windows快捷方式(.lnk)解析器?
我目前正在使用Win32ShellFolderManager2
并ShellFolder.getLinkLocation
解析Java中的Windows快捷方式。不幸的是,如果Java程序在Vista下作为服务运行getLinkLocation
,则无法使用。具体来说,我得到一个异常,指出“无法获取外壳文件夹ID列表”。
搜索网络确实会提及此错误消息,但始终与关联JFileChooser
。我没有使用JFileChooser
,我只需要将.lnk文件解析到其目的地即可。
有人知道.lnk
我可以使用用Java编写的文件的第三方解析器吗?
此后,我在这里找到了.lnk
格式的非官方文档,但是如果有人以前做过,我宁愿不必做这项工作,因为该格式相当可怕。
答案1
小编典典添加了注释(到目前为止有一些说明以及对每个贡献者的感谢),对文件魔术的附加检查,快速测试以查看给定文件是否可能是有效链接(不读取所有字节),进行了抛出的修复如果文件太小,则使用适当的消息而不是ArrayIndexOutOfBoundsException的ParseException进行一些常规清理。
在此处提供源代码(如果有任何更改,请将其直接推到GitHub repo / project。
package org.stackoverflowusers.file;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.text.ParseException;/** * Represents a Windows shortcut (typically visible to Java only as a ''.lnk'' file). * * Retrieved 2011-09-23 from http://stackoverflow.com/questions/309495/windows-shortcut-lnk-parser-in-java/672775#672775 * Originally called LnkParser * * Written by: (the stack overflow users, obviously!) * Apache Commons VFS dependency removed by crysxd (why were we using that!?) https://github.com/crysxd * Headerified, refactored and commented by Code Bling http://stackoverflow.com/users/675721/code-bling * Network file support added by Stefan Cordes http://stackoverflow.com/users/81330/stefan-cordes * Adapted by Sam Brightman http://stackoverflow.com/users/2492/sam-brightman * Based on information in ''The Windows Shortcut File Format'' by Jesse Hager <jessehager@iname.com> * And somewhat based on code from the book ''Swing Hacks: Tips and Tools for Killer GUIs'' * by Joshua Marinacci and Chris Adamson * ISBN: 0-596-00907-0 * http://www.oreilly.com/catalog/swinghks/ */public class WindowsShortcut{ private boolean isDirectory; private boolean isLocal; private String real_file; /** * Provides a quick test to see if this could be a valid link ! * If you try to instantiate a new WindowShortcut and the link is not valid, * Exceptions may be thrown and Exceptions are extremely slow to generate, * therefore any code needing to loop through several files should first check this. * * @param file the potential link * @return true if may be a link, false otherwise * @throws IOException if an IOException is thrown while reading from the file */ public static boolean isPotentialValidLink(File file) throws IOException { final int minimum_length = 0x64; InputStream fis = new FileInputStream(file); boolean isPotentiallyValid = false; try { isPotentiallyValid = file.isFile() && file.getName().toLowerCase().endsWith(".lnk") && fis.available() >= minimum_length && isMagicPresent(getBytes(fis, 32)); } finally { fis.close(); } return isPotentiallyValid; } public WindowsShortcut(File file) throws IOException, ParseException { InputStream in = new FileInputStream(file); try { parseLink(getBytes(in)); } finally { in.close(); } } /** * @return the name of the filesystem object pointed to by this shortcut */ public String getRealFilename() { return real_file; } /** * Tests if the shortcut points to a local resource. * @return true if the ''local'' bit is set in this shortcut, false otherwise */ public boolean isLocal() { return isLocal; } /** * Tests if the shortcut points to a directory. * @return true if the ''directory'' bit is set in this shortcut, false otherwise */ public boolean isDirectory() { return isDirectory; } /** * Gets all the bytes from an InputStream * @param in the InputStream from which to read bytes * @return array of all the bytes contained in ''in'' * @throws IOException if an IOException is encountered while reading the data from the InputStream */ private static byte[] getBytes(InputStream in) throws IOException { return getBytes(in, null); } /** * Gets up to max bytes from an InputStream * @param in the InputStream from which to read bytes * @param max maximum number of bytes to read * @return array of all the bytes contained in ''in'' * @throws IOException if an IOException is encountered while reading the data from the InputStream */ private static byte[] getBytes(InputStream in, Integer max) throws IOException { // read the entire file into a byte buffer ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] buff = new byte[256]; while (max == null || max > 0) { int n = in.read(buff); if (n == -1) { break; } bout.write(buff, 0, n); if (max != null) max -= n; } in.close(); return bout.toByteArray(); } private static boolean isMagicPresent(byte[] link) { final int magic = 0x0000004C; final int magic_offset = 0x00; return link.length >= 32 && bytesToDword(link, magic_offset) == magic; } /** * Gobbles up link data by parsing it and storing info in member fields * @param link all the bytes from the .lnk file */ private void parseLink(byte[] link) throws ParseException { try { if (!isMagicPresent(link)) throw new ParseException("Invalid shortcut; magic is missing", 0); // get the flags byte byte flags = link[0x14]; // get the file attributes byte final int file_atts_offset = 0x18; byte file_atts = link[file_atts_offset]; byte is_dir_mask = (byte)0x10; if ((file_atts & is_dir_mask) > 0) { isDirectory = true; } else { isDirectory = false; } // if the shell settings are present, skip them final int shell_offset = 0x4c; final byte has_shell_mask = (byte)0x01; int shell_len = 0; if ((flags & has_shell_mask) > 0) { // the plus 2 accounts for the length marker itself shell_len = bytesToWord(link, shell_offset) + 2; } // get to the file settings int file_start = 0x4c + shell_len; final int file_location_info_flag_offset_offset = 0x08; int file_location_info_flag = link[file_start + file_location_info_flag_offset_offset]; isLocal = (file_location_info_flag & 2) == 0; // get the local volume and local system values //final int localVolumeTable_offset_offset = 0x0C; final int basename_offset_offset = 0x10; final int networkVolumeTable_offset_offset = 0x14; final int finalname_offset_offset = 0x18; int finalname_offset = link[file_start + finalname_offset_offset] + file_start; String finalname = getNullDelimitedString(link, finalname_offset); if (isLocal) { int basename_offset = link[file_start + basename_offset_offset] + file_start; String basename = getNullDelimitedString(link, basename_offset); real_file = basename + finalname; } else { int networkVolumeTable_offset = link[file_start + networkVolumeTable_offset_offset] + file_start; int shareName_offset_offset = 0x08; int shareName_offset = link[networkVolumeTable_offset + shareName_offset_offset] + networkVolumeTable_offset; String shareName = getNullDelimitedString(link, shareName_offset); real_file = shareName + "\\" + finalname; } } catch (ArrayIndexOutOfBoundsException e) { throw new ParseException("Could not be parsed, probably not a valid WindowsShortcut", 0); } } private static String getNullDelimitedString(byte[] bytes, int off) { int len = 0; // count bytes until the null character (0) while (true) { if (bytes[off + len] == 0) { break; } len++; } return new String(bytes, off, len); } /* * convert two bytes into a short note, this is little endian because it''s * for an Intel only OS. */ private static int bytesToWord(byte[] bytes, int off) { return ((bytes[off + 1] & 0xff) << 8) | (bytes[off] & 0xff); } private static int bytesToDword(byte[] bytes, int off) { return (bytesToWord(bytes, off + 2) << 16) | bytesToWord(bytes, off); }}
Perl 创建 Windows 下的快捷方式
下面是小编 jb51.cc 通过网络收集整理的代码片段。
小编小编现在分享给大家,也给大家做个参考。
#!/usr/bin/perl -w use Win32::Shortcut; $ApplicationName = 'c:/winnt/system32/notepad.exe'; $BaseName = 'Notepad'; $lnk = new Win32::Shortcut(); $lnk->{'Path'} = $ApplicationName; $lnk->{'Arguments'} = ""; $lnk->{'WorkingDirectory'} = "."; $lnk->{'Description'} = "Launches application"; $lnk->{'ShowCmd'} = SW_SHOWnorMAL; $lnk->Save( $BaseName . ".lnk" ); $lnk->Close();
以上是小编(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给程序员好友。
今天关于在节点上访问Windows快捷方式和.lnk数据的分享就到这里,希望大家有所收获,若想了解更多关于Apache Http Server在htdocs下建立的windows快捷方式无效、delphi – 如何在Windows桌面上创建文件快捷方式(* .lnk文件)?、Java中的Windows快捷方式(.lnk)解析器?、Perl 创建 Windows 下的快捷方式等相关知识,可以在本站进行查询。
本文标签: