This works on NT, I suspect it will work on 2000 and will test it tonight.
The key was to run cscript.exe because CreateProcess *IS* looking for a .EXE to launch, so we use the script as a commandline parameter instead of assuming it is associated with Cscript.exe
Cscript.exe is in 95/NT/ and 2000 by default.
Code:
'------------------------------------------------------------------------------------------ 'CreateShortCut bypasses coding COM in PB 'Basically it writes a JScript and shells out and lets windows manage this. 'This would be for use when say, it's a one time install and you don't need the 'overhead of COM in your application etc. 'ScriptName - Name the .JS script that will be written/run 'TargetEXE - The .EXE that the shortcut points to, include path 'TargetStartDir - The "Start in" portion of the Link. Starting dir for your app. 'TargetLNKName - Name the link, do NOT add .LNK, the function will do this. 'Status: Freeware - Use at your own risk 'Scott Turchin 'Computer Creations Software 'http://www.tngbbs.com '------------------------------------------------------------------------------------------ Function CreateShortCut(ByVal ScriptName As String, _ TargetEXE As String, _ TargetStartDir As String,_ TargetLNKName As String) As Long Dim St(1 To 10) As String Local x As Long Local l_St As String Local Start As STARTUPINFO Local Proc As PROCESS_INFORMATION Start.cb = SizeOf(Start) Start.dwFlags = %STARTF_USESHOWWINDOW Start.wShowWindow = 0 Replace "\" With "\\" In TargetEXE Replace "\" With "\\" In TargetStartDir St(1) = "var WSHShell = WScript.CreateObject(""WScript.Shell"");" St(2) = "var DesktopPath = WSHShell.SpecialFolders(""Desktop"");" St(3) = "var ShortCut = WSHShell.CreateShortcut(DesktopPath + " + Chr$(34) + "\\" + TargetLNKName + ".LNK" + Chr$(34) + ");" St(4) = "ShortCut.TargetPath = WSHShell.ExpandEnvironmentStrings(" + Chr$(34) + TargetEXE + Chr$(34) + ");" St(5) = "ShortCut.WorkingDirectory = WSHShell.ExpandEnvironmentStrings(" + Chr$(34) + TargetStartDir + Chr$(34) + ");" St(6) = "ShortCut.WindowStyle = 4;" St(7) = "ShortCut.IconLocation = WSHShell.ExpandEnvironmentStrings(" + Chr$(34) + TargetExe + ", 0" + Chr$(34) + ");" '0 indicates icon # St(8) = "ShortCut.Save();" St(9) = "WScript.Quit();" For x = 1 To 9 l_St = l_St + St(x) + $CRLF Next Erase St x = FreeFile Open ScriptName For Output As #x Print #x, l_St Close x l_St = "cscript.exe " + ScriptName If CreateProcess("", _ ByVal StrPtr(l_St), _ ByVal %NULL, _ ByVal %NULL, _ 0, _ %NORMAL_PRIORITY_CLASS, _ ByVal %NULL, _ ByVal %NULL, _ Start, _ proc) Then Call WaitForInputIdle(proc.hProcess, %INFINITE) Call WaitForSingleObject(proc.hProcess, %INFINITE) Call CloseHandle(proc.hProcess) Call CloseHandle(proc.hThread) Kill ScriptName End If Function = %TRUE End Function '------------------------------------------------------------------------------------------
Scott
mailto:[email protected][email protected]</A>
Leave a comment: