Click to See Complete Forum and Search --> : Windows Scripting Host 8.3 File format?


Kdev
May 21st, 2001, 09:19 AM
I am using the Windows Scripting Host to execute a VBScript file that my program makes at run-time.

I am having a problem in that the WScript program will hang if I attempt to use a path that does not conform to the old 8.3 file format.

The following Does NOT Work:
Dim wshShell, sScript as string
set wshShell = CreateObject("WScript.Shell")
sScript = "wscript C:\Program Files\Project1\tmp001.vbs"
wshShell.Run sScript, 0, true


The following Does work:
Dim wshShell, sScript as string
set wshShell = CreateObject("WScript.Shell")
sScript = "wscript C:\Progra~1\Project1\tmp001.vbs"
wshShell.Run sScript, 0, true


Is there another way I can do this? Is there a function or api call to retrieve a file path in the 8.3 format?

This is the correct path my program uses but I will not hardcode it as such I will be using app.path to validate the location so I will need a way to retrieve this path with a 8.3 format.

-K

Kdev
May 21st, 2001, 11:42 AM
Still not sure why I must use 8.3 file format when running wscript in this manner but here is a method to retrieve the short path name.

private Declare Function GetShortPathName Lib "kernel32" Alias _
"GetShortPathNameA" (byval lpszLongPath as string, _
byval lpszShortPath as string, byval cchBuffer as Long) as Long

private Sub Command1_Click()
Dim sShortPath as string*255
Dim lBufLen as long
dim sLongPath as string

sLongPath = app.path 'In this case app.path = C:\Program Files\Project1

lBufLen = 254
lBufLen = GetShortPathName(sLongPath,sShortPath,lBufLen)

MsgBox "Long Path: " & sLongPath & vbNewLine & _
"Short Path: " & left(sShortPath,lBufLen)
End Sub


-K

Cimperiali
May 22nd, 2001, 05:22 AM
Good solution.
Have I ever told you you 're smart?
:-)
Best regards,
Cesare Imperiali

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.

Lutz
May 22nd, 2001, 08:09 AM
Sure your first solution won't work, as there is a blank in the path to the file to work with. So wscript tries to execute the file "C:\Program" with additional commandlineparameter "Files\Project1\tmp001.vbs". To solve this problem just wrap long filenames in quotes (i.e. "). E.g:
sScript = "wscript " & chr$(34) & "C:\Program Files\Project1\tmp001.vbs" & Chr$(34).


This should solve your problem.