Classic Shell/Explorer Custom Command

BXF

New member
Local time
11:45 PM
Messages
8
Hi,

I've created a Custom Command under Classic Explorer that invokes a VBS script. If the command contains E:\abcdef.vbs, it works. If, however, I change it to E:\abcdef.vbs "%3", nothing happens, even though there is no reference to the argument within the script.:confused::huh:

For what it's worth, here is the script:

Dim WshShell, objFSO, FileList, strFileName, MKLCommand, I

Set WshShell = WScript.CreateObject("WScript.Shell")

Const ForReading = 1

'FileList = WScript.Arguments(0)
FileList="F:\Global Temp\ceiA611.tmp"
WScript.Echo FileList

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(FileList, ForReading)

Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
I = InStrRev(strNextLine,"\")
strFileName = Right(strNextLine,Len(strNextLine)-I)
MKLCommand = "cmd.exe /c mklink ""E:\FPVTemp\" & strFileName & """ """ & strNextLine & """"
WshShell.Run(MKLCommand)
Loop

Any suggestions would be appreciated.

Thanks.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 7 Pro 64bit
CPU
2670QM
Motherboard
ASUS N53SN/Intel HM65
Memory
8GB
Graphics Card(s)
Nvidia GeForce GT 550m + Intel HD Graphics 3000
Hard Drives
Samsung HM500JJ
Antivirus
Comodo CIS
Browser
Pale Moon
You can use Process Monitor to see if a process is being launched and with what exact parameters.
 

My Computer

Computer Manufacturer/Model Number
Me :) I build all my PCs
OS
Windows 7 Home 64, Vista Ultimate 64
I'm not sure exactly what I should be looking for, but I did find this, while monitoring Explorer.EXE:


Operation: CreateFile

Result: NAME INVALID

Path: E:\MKLink.vbs "F:\GLOBAL~1\


My TEMP folder is F:\Global Temp.

Looks like the name being passed is truncated.

This operation is preceded by some successful operations on F:\Global Temp\ceiF6DD.tmp.

Thanks for your help.
 
Last edited:

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 7 Pro 64bit
CPU
2670QM
Motherboard
ASUS N53SN/Intel HM65
Memory
8GB
Graphics Card(s)
Nvidia GeForce GT 550m + Intel HD Graphics 3000
Hard Drives
Samsung HM500JJ
Antivirus
Comodo CIS
Browser
Pale Moon
That's probably fine. It tries a few things to figure out what part is the exe and what part is the argument. To avoid confusion use quotes around E:\MKLink.vbs.
 

My Computer

Computer Manufacturer/Model Number
Me :) I build all my PCs
OS
Windows 7 Home 64, Vista Ultimate 64
Hi Ivo,

I had already tried it with quotes before I posted. I tried again, but no change.

I'm attaching two extracts from Process Monitor (renamed to .txt for upload). The difference is quite dramatic:)

It may be useful to point out that replacing the .VBS with .BAT appears to work, even with the "%3".

Thanks.
 

Attachments

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 7 Pro 64bit
CPU
2670QM
Motherboard
ASUS N53SN/Intel HM65
Memory
8GB
Graphics Card(s)
Nvidia GeForce GT 550m + Intel HD Graphics 3000
Hard Drives
Samsung HM500JJ
Antivirus
Comodo CIS
Browser
Pale Moon
Please attach the exact VBS file you are using, and the string you use for your command.
Also, what are you trying to do?
 

My Computer

Computer Manufacturer/Model Number
Me :) I build all my PCs
OS
Windows 7 Home 64, Vista Ultimate 64
Script attached. It creates Symbolic Links for selected files, in another folder.

The command (Copy/Pasted): "E:\MKLink.vbs" "%3"

Enjoy!:)
 

Attachments

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 7 Pro 64bit
CPU
2670QM
Motherboard
ASUS N53SN/Intel HM65
Memory
8GB
Graphics Card(s)
Nvidia GeForce GT 550m + Intel HD Graphics 3000
Hard Drives
Samsung HM500JJ
Antivirus
Comodo CIS
Browser
Pale Moon
Hi Ivo,

I've solved MY problem by compiling the VBScript to an EXE, which runs fine.

I do have another question, please. The Help section says "Note to developers: When %3 or %4 is used, it is the responsibility of the command to delete the temporary file when it finishes", but the file is locked until the command terminates (in use by Explorer). What is the proper way to get around this?

Thanks.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 7 Pro 64bit
CPU
2670QM
Motherboard
ASUS N53SN/Intel HM65
Memory
8GB
Graphics Card(s)
Nvidia GeForce GT 550m + Intel HD Graphics 3000
Hard Drives
Samsung HM500JJ
Antivirus
Comodo CIS
Browser
Pale Moon
I looked at the code and it seems fine. I close the file before calling the command, so the file shouldn't be in use.
I will run some tests during the weekend.
 

My Computer

Computer Manufacturer/Model Number
Me :) I build all my PCs
OS
Windows 7 Home 64, Vista Ultimate 64
Sorry, stupid me. It is I who still has the file open:o (I'm not a Windows programmer).

My apologies.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 7 Pro 64bit
CPU
2670QM
Motherboard
ASUS N53SN/Intel HM65
Memory
8GB
Graphics Card(s)
Nvidia GeForce GT 550m + Intel HD Graphics 3000
Hard Drives
Samsung HM500JJ
Antivirus
Comodo CIS
Browser
Pale Moon
I finally had some time to investigate, and I found the problem. The thing is VBS files are not executables but documents.
You need to use the command "WScript.exe E:\MKLink.vbs"

If the command is just "MKLink.vbs", then I execute it using the ShellExecute API, which understands how to launch documents like VBS files, or TXT files, etc. However it is a fire and forget type API.

For more complex commands that use %3, %4 or %5, I need to have a direct access to the process that runs, so I can wait for it to finish. For that I need to use the API CreateProcess, which is not smart enough to know that for VBS files it needs to run WScript.exe.
 

My Computer

Computer Manufacturer/Model Number
Me :) I build all my PCs
OS
Windows 7 Home 64, Vista Ultimate 64
WScript.exe "E:\zzz.vbs" "%3" "E:\FPVTemp" works!

Thanks for the effort, and the for program, of course.

By the way, just FYI, your HELP says "Keep in mind that if the current folder is a root of a drive it will end with a backslash (like C:\)". I get a double-quote rather than a backslash: i.e. C:"

All the best.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 7 Pro 64bit
CPU
2670QM
Motherboard
ASUS N53SN/Intel HM65
Memory
8GB
Graphics Card(s)
Nvidia GeForce GT 550m + Intel HD Graphics 3000
Hard Drives
Samsung HM500JJ
Antivirus
Comodo CIS
Browser
Pale Moon
Most likely "%1" turns into "C:\", and \" is considered an escaped double quote by the command line parser. I don't think there's much I can do about it, as I have no control over the parser of WScript or whatever tool you are using.
 

My Computer

Computer Manufacturer/Model Number
Me :) I build all my PCs
OS
Windows 7 Home 64, Vista Ultimate 64
It's not a problem. If I get a 3-character "path to current folder" in the form of X:?, I just drop the third character.

Thanks again.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Asus
OS
Windows 7 Pro 64bit
CPU
2670QM
Motherboard
ASUS N53SN/Intel HM65
Memory
8GB
Graphics Card(s)
Nvidia GeForce GT 550m + Intel HD Graphics 3000
Hard Drives
Samsung HM500JJ
Antivirus
Comodo CIS
Browser
Pale Moon
Back
Top