OK I'm doing the funky CreateShortcut code that I posted in the source code forum....
I shell out and run the SHTCUT.JS script, life is good...
But immediately after that, I do a KILL ScriptName (The above mentioned script)...
Problem is, the KILL command happens right after the shell and the Help file states this about Shell:
Now, that's all fine and dandy but my KILL was executing before the SHELL was complete, hence the file was deleted before it could get started.....
Possibly something to do with the fact that windows has to run it and takes control of it, I don't know, just strange..
Ideas?
Here's the code, it seems to resolve itself if I put a WaitForSingleObject in place..
-------------
Scott
mailto:[email protected][email protected]</A>
I shell out and run the SHTCUT.JS script, life is good...
But immediately after that, I do a KILL ScriptName (The above mentioned script)...
Problem is, the KILL command happens right after the shell and the Help file states this about Shell:
Note The Shell statement runs other programs synchronously. That means that execution of your code is suspended until the shelled program finishes.
Possibly something to do with the fact that windows has to run it and takes control of it, I don't know, just strange..
Ideas?
Here's the code, it seems to resolve itself if I put a WaitForSingleObject in place..
Code:
'------------------------------------------------------------------------------------------ Function CreateShortCut(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 Replace "\" With "\\" In TargetEXE Replace "\" With "\\" In TargetStartDir Local dwMilliseconds As Long Local dwWaitCode As Long dwMilliseconds = 250 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 x = Shell("start " + ScriptName,0) Function = x Kill ScriptName End Function '------------------------------------------------------------------------------------------
-------------
Scott
mailto:[email protected][email protected]</A>
Comment