通过运行生成的临时 VBS 脚本,可以在桌面创建快捷方式。

VBS 脚本

Set WshShell = WScript.CreateObject("WScript.Shell")
                strDesktop = WshShell.SpecialFolders("Desktop")
                set oShellLink = WshShell.CreateShortcut(strDesktop & "\KKPlayer.lnk")
                oShellLink.TargetPath = "C:\Users\hk\Desktop\KKPlayer\KKPlayer.exe"
                oShellLink.WindowStyle = 1
                oShellLink.IconLocation = "C:\Users\hk\Desktop\KKPlayer\KKPlayer.exe,0"
                oShellLink.WorkingDirectory =  "C:\Users\hk\Desktop\KKPlayer"
                oShellLink.Save
                

C++ 代码

void CLiteSetupUIDlg::CreateShortcut()
                {
                	fstream f;
                	f.open("shortcut.vbs", ios::out);
                
                	string cmd;
                	f << "Set WshShell = WScript.CreateObject(\"WScript.Shell\")" << endl;
                	f << "strDesktop = WshShell.SpecialFolders(\"Desktop\")" << endl;
                
                	cmd = "set oShellLink = WshShell.CreateShortcut(strDesktop & \"\\";
                	cmd += const_for_exe::_shortcut_name;
                	cmd += ".lnk\")";
                	f << cmd << endl;
                
                
                
                	cmd = "oShellLink.TargetPath = \"";
                	cmd += Utils::toAscii(path1.GetBuffer(0));
                	cmd += "\\";
                	cmd += const_for_exe::_shortcut_exe_name;
                	cmd += "\"";
                
                	f << cmd << endl;
                
                
                	f << "oShellLink.WindowStyle = 1" << endl;
                
                
                	cmd = "oShellLink.IconLocation = \"";
                	cmd += Utils::toAscii(path1.GetBuffer(0));
                	cmd += "\\";
                	cmd += const_for_exe::_shortcut_exe_name;
                	cmd += ",0";
                	cmd += "\"";
                
                	f << cmd << endl;
                
                
                
                	cmd = "oShellLink.WorkingDirectory =  \"";
                	cmd += Utils::toAscii(path1.GetBuffer(0));
                	cmd += "\"";
                
                	f << cmd << endl;
                
                
                	f << "oShellLink.Save" << endl;
                
                
                	f.flush();
                	f.close();
                
                	//system("shortcut.vbs");
                
                	Utils::system_hide_cmd("cmd /c shortcut.vbs");
                
                
                
                	Utils::DeleteFileForName("shortcut.vbs");
                
                
                }