Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maximum number of characters in a command line parameter 2

Status
Not open for further replies.

jbradley

Programmer
Sep 7, 2001
248
0
0
US
I am working on a VB6 Sp6 program to act as a parser, passing the paths and file names of a group of files dropped on its desktop icon as a delimited string to the import utility of a document management system. When I drop a group of files on the program icon it launches the program, which takes the file paths and names as a series of command line parameters, populating the Command$ variable with them with each one surrounded by double quote characters and separated by spaces. I then use the Replace function to replace the " " character sequence with "?".

The problem I am having is that if the character count of the paths and file names of the dropped files exceeds 2,116 characters the program blows up with the message:

"Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item."

Is this a limitation of VB6? If so, is there a way around it?

Thanks in advance for any assistance.
 
>Is this a limitation of VB6? If so, is there a way around it?

No, it is a limitation of the command prompt

or, if you are using Shellexecute/Ex then it is a limit of those APIs (INTERNET_MAX_URL_LENGTH in fact, which is about 2048 characters)
 
I think it's more likely your error is what it says it is... error accessing the file. Could be a parsing error in one of the files???

I use files drag & drop routinely and have not run into this. I just tested, from Win Explorer, dropping 275 files with an average of 80 characters per file name which is over 22,000 total characters and it parses in my program fine.

What operating system (XP, Win7) are you using? What program are you using to drag the files?
 
Strongm, I think you may have hit the nail on the head.

Tom, We are dragging the files from an Explorer window on to my program's desktop icon. The OS is XP Pro (32 bit). The first line of code in my program is an 'On Error Goto Error_Handler' statement but it appears that the error is occurring even before that. The error is certainly not being trapped and there is no indication that it is a VB runtime error.

To try and get around this I built a test version of my program in a .bas module that doesn't actually do anything except echo each line of program code to a log file as the program executes and echoes the command line that it would pass to the import utility to another log file.

I'm not trying to do anything with the files being dropped, just capture the paths and names in the Command$ variable of my program, so file access rights don't enter into it, although I am an administrator on my workstation and all the files are local. With 2,116 characters (including spaces and double quotes between file specifications) everything works fine and both my log files are created. When I hit 2,117 characters it doesn't appear that my program even launches, I just get the error message.
 
Whoops... just noticed you're dropping to desktop icon instead of a VB object like list box or picture box. In this case, strongm is absolutely correct. You are limited.

I ran into a similar problem with a client who routinely needs to drop hundreds of files daily, usually photo email attachments, for processing. Ran into a couple of problems... command line length and also dropping attachments from Outlook (which has it's own anomalies).

The choices were to keep the program open and drop to, in this case, a list box. The client didn't want the main program form open. He wanted a desktop icon, opening the main processing form only when files were dropped.

Here is a solution that pleased him. What I ended up doing was to create a start-up form that consisted of nothing but a 32x32 pixel bitmap (the size of his desktop icons). When the program runs the form appears on your desktop like an icon. To the user, the appearance is the same as a desktop icon.

It can be dragged and moved on the desktop and double-clicked to open the programs main processing form... just like an actual desktop icon and you can drop files on the bitmap.

But since it's a picture box, you are not limited to command string length since you are using the drop event of the picture box.

We set this program to run at boot-up on his computers so for all intents & purposes it appears to his users as a desktop icon.

A couple of important points to make this form appear as a desktop icon if you choose to implement this method:

1. You'll need to use transparency for the start up form using SetWindowAttributes API. That way, the only thing you see is the bitmap... no form.

2. You'll also need to set the start up form to FormAlwaysAtBottom. That way when the user hits Show Desktop (minimize all programs), the picture box form doesn't minimize and doesn't disappear from the screen. The FormAlwaysAtBottom sub is only about 5 lines of code and uses the FindWindowEx and SetParent API's.

3. You'll also need to use the Release Capture API to move the picture box like a desktop icon.

It's a bit of kludge for sure, but the end result is exactly what the client was looking for. It's been running now for over a year on all his computers without incident.

If you decide this is a viable alternative for you I'd be happy to give you any information you need.

Tom






 
Sorry I took so long to acknowledge your replies. Once we realized that the problem was essentially a Windows limitation (for which I have strongm to thank) we took Tom's suggestion. My boss modified the import program to run in a desktop icon analog and launch from the Startup folder.

Stars to both of you for identifying the problem and suggesting a solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top