STRPCCMD gives MS explorer error

Any IBM i topic that does not fit in another forum
Post Reply
jand66
Posts: 4
Joined: Tue Sep 19, 2023 11:50 am

STRPCCMD gives MS explorer error

Post by jand66 »

Hello,

All of a sudden we have a problem with STRPCCMD when trying to open a Word document. This forum is my last hope for a solution.

Analysis
When this code is executed the users get the error shown in attachment.

Code: Select all

01 //Start MS Word for blob
02 @cmdString = 'STRPCO';
03 callp(e) excCmd(@CmdString :%len(@CmdString));
04
05 @cmdString = 'STRPCCMD PCCMD(' + '''' +
06              'CMD /C START ' +
07              '\\' + %trim(@systeemNaam) +
08              %trim(@blob_name) +  ''''  +
09              ') PAUSE(*NO)';
10 excCmd(@CmdString :%len(@CmdString));
There are two odd things to this problem. When I change the code like this, it runs fine and no error occurs.

Code: Select all

01 //Start MS Word for blob
02 @cmdString = 'STRPCO';
03 callp(e) excCmd(@CmdString :%len(@CmdString));
04
05 sleep(10);
06
07 @cmdString = 'STRPCCMD PCCMD(' + '''' +
08              'CMD /C START ' +
09              '\\' + %trim(@systeemNaam) +
10              %trim(@blob_name) +  ''''  +
11              ') PAUSE(*NO)';
12 excCmd(@CmdString :%len(@CmdString));
So, while waiting 10 seconds some process ends like it should and then the second pc command runs without problem. Although it looks ugly because two black DOS windows popup ;) .

Another thing I tried was debugging the first block of code. I added a breakpoint at line 5, also wait a few seconds and then press F12 to execute the code. Of course, this also works fine. But when I close the Word document and the program puts the focus back on the debug I delete the breakpoint and press F12 again. The program returns to the screen of image 1. When I hit F2 again MS Word opens the document immediately and as long as I don’t close this session it works fine every time I open a document with STRPCCMD.

CONCLUSION
My assumption is that there is not really an authorization issue. When it should be authorization then the document will not open in any way.
I guess the problem must be in the direction of performance speed or maybe the commands are executed asynchronously, but honestly I am not sure.

It has always worked from the date of going into production, 5 July 2014. On the IBM iSeries nothing has been changed, I also checked this at the team responsible for system maintenance and at the external service provider responsible for machine maintenance, so I think it must be something outside of the IBM iSeries and because the error has been shown in windows explorer it looks like a MS Windows or MS Word error, but that also is a guess.

I hope someone can help.

Kind regards from the Netherlands,
Jan
Attachments
Error_Strpccmd.jpg
Error_Strpccmd.jpg (76.56 KiB) Viewed 10716 times
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: STRPCCMD gives MS explorer error

Post by Scott Klement »

I don't speak Dutch, so I ran the error text through Google Translate. I hope this is an accurate translation
You may not have the correct permissions for this network resource. To determine whether you have access permissions, contact the server administrator. The parameter is incorrect.
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: STRPCCMD gives MS explorer error

Post by Scott Klement »

As far as I can tell, Windows is having trouble opening the network resource. Perhaps it is taking a long time to open, so inserting a 10 second delay is solving the problem for you?

At any rate, this isn't a problem with your RPG code -- the problem is 100% on the windows machine.

Windows Networking (access to remove disks and drive mapping, etc) is always a bit unreliable in my experience. I would recommend setting up the HTTP server on your IBM i as a way to open the document on the PC, and then use STRPCCMD to open the URL.

I would also give some thought to the fact that you're using a command line such as "cmd /c start" to run the command -- which guarantees an ("ugly") DOS window will open (that's what "cmd" is), and also means that your command will never work on any other desktop besides Windows. Is that really acceptable to you?
msddcb
Posts: 21
Joined: Wed Jul 28, 2021 5:12 am

Re: STRPCCMD gives MS explorer error

Post by msddcb »

While I am not able to help with your problem I was interested in Scott's reply.
Firstly would you just replace the CMD with WINWORD.EXE ? (Presuming the windows path enables the program to be found)
And more interestingly if going the new http server option is this still accessing the document on the Windows server or would the documents be in the IFS. I am interested in this option and have not searched for how to as I was just reading this post but would like to read more on how to do this ?
jand66
Posts: 4
Joined: Tue Sep 19, 2023 11:50 am

Re: STRPCCMD gives MS explorer error

Post by jand66 »

Scott Klement wrote: Tue Sep 19, 2023 5:41 pm I don't speak Dutch, so I ran the error text through Google Translate. I hope this is an accurate translation
You may not have the correct permissions for this network resource. To determine whether you have access permissions, contact the server administrator. The parameter is incorrect.
Apologies, you're right I forgot to translate. And a free tip, https://www.deepl.com/translator is far more better then google translate ;)
jand66
Posts: 4
Joined: Tue Sep 19, 2023 11:50 am

Re: STRPCCMD gives MS explorer error

Post by jand66 »

Scott Klement wrote: Tue Sep 19, 2023 5:49 pm As far as I can tell, Windows is having trouble opening the network resource. Perhaps it is taking a long time to open, so inserting a 10 second delay is solving the problem for you?

At any rate, this isn't a problem with your RPG code -- the problem is 100% on the windows machine.

Windows Networking (access to remove disks and drive mapping, etc) is always a bit unreliable in my experience. I would recommend setting up the HTTP server on your IBM i as a way to open the document on the PC, and then use STRPCCMD to open the URL.

I would also give some thought to the fact that you're using a command line such as "cmd /c start" to run the command -- which guarantees an ("ugly") DOS window will open (that's what "cmd" is), and also means that your command will never work on any other desktop besides Windows. Is that really acceptable to you?
Yes, the 10 seconds delay solves the problem.

I am hired at this customer and there are a lot of programs I would't have programmed the way they are programmed, but I have to deal with that. So the answer on your question if I find it acceptabel is NO, but at the customer the told me not to spend too much time :D . Yesterday I found this site https://code400.com/forum/forum/iseries ... g-strpccmd where you have put a link to a solution. But I can't find a solution there.

I really want to get rid of these DOS window popup. I tried some things with rundll stuff, but until now it didn't work. So I am interested in how to open a word document in a way the DOS window will NOT be shown and i am also interested in the solution you mentioned in the code400.com site for eventual future cases
jand66
Posts: 4
Joined: Tue Sep 19, 2023 11:50 am

Re: STRPCCMD gives MS explorer error

Post by jand66 »

msddcb wrote: Tue Sep 19, 2023 11:20 pm While I am not able to help with your problem I was interested in Scott's reply.
Firstly would you just replace the CMD with WINWORD.EXE ? (Presuming the windows path enables the program to be found)
And more interestingly if going the new http server option is this still accessing the document on the Windows server or would the documents be in the IFS. I am interested in this option and have not searched for how to as I was just reading this post but would like to read more on how to do this ?
Just replacing 'CMD' by 'WINWORD.EXE' doesn't solve the problem. Then I still get the DOS window popup :( and MS Word doesn't open the document.
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: STRPCCMD gives MS explorer error

Post by Scott Klement »

msddcb wrote: Tue Sep 19, 2023 11:20 pm While I am not able to help with your problem I was interested in Scott's reply.
Firstly would you just replace the CMD with WINWORD.EXE ? (Presuming the windows path enables the program to be found)
And more interestingly if going the new http server option is this still accessing the document on the Windows server or would the documents be in the IFS. I am interested in this option and have not searched for how to as I was just reading this post but would like to read more on how to do this ?
jand66 wrote: Wed Sep 20, 2023 2:17 pm Just replacing 'CMD' by 'WINWORD.EXE' doesn't solve the problem. Then I still get the DOS window popup :( and MS Word doesn't open the document.
I'm not a fan of hardcoding something like 'WINWORD.EXE', because users should be able to configure their operating system to open documents in whichever program is their favorite. For example, in Win11, we can go into Settings / Apps / Default Apps and choose what will open an email, or a URL, or just about any type of document. (There are similar features in older versions of Windows, as well as MacOS and most GUI environments for Linux, etc.) We shouldn't be hard-coding the specific program we want to run.

Plus, obviously, "WINWORD" is the windows version of word -- it's not going to work on other platforms.

This is what I've been using lately, it's a simple Windows program (written in C)

Code: Select all

#include <windows.h>

int WINAPI WinMain(HINSTANCE i, HINSTANCE p, LPSTR cmd, int show) {

    HINSTANCE rc;

    if (strlen(cmd) < 1) {
        MessageBox(NULL, "You must pass a command as a parameter.",
                   "open", MB_OK);
        exit(1);
    }

    rc = ShellExecute(NULL, "open", cmd, NULL, NULL, SW_HIDE);

    if (rc < (HINSTANCE)32)
        MessageBox(NULL, "ShellExecute failed", "open", MB_OK);

    return 0;
}
Basically all it does is accept the command as a parameter, then pass that command to the Windows ShellExecute() function. Compile it and place it on your Windows PC, make sure its added to your PATH. Then you can run something like this:

Code: Select all

STRPCCMD PCCMD('open http://www.google.com')
The reason it's named 'open' is for compatibility with MacOS, which has an 'open' command built-in. So if you run the same command on MacOS, it will open the same URL. This way, it doesn't matter if the user is running Windows or Mac.

Naturally, you could write a similar tool for other operating systems like Linux or *BSD if you needed the same functionality there... but I found 99% of people are using either Windows or MacOS.

As I said before, I'd rather run a URL vs. a network path. So while the above command could be used to open something like \\myibmi\path\to\mydoc.docx, that again locks you into Windows (because you're using a Windows Networking syntax, and backslashes as directory separators) and it uses the somewhat unreliable Windows Networking approach to getting to the file.

So instead, what I do is send a URL like this:

Code: Select all

STRPCCMD PCCMD('open http://ibmi-system.mycompany.com/path/to/downloader.pgm?mydoc.docx')
Then I have a simple RPG program that is configured to run under the user's authority. It will open the Word doc, and download it to the user's browser, which will give them the option to save it to disk or open it with Word on their system.
softd
Posts: 2
Joined: Tue Mar 19, 2024 7:28 pm

Re: STRPCCMD gives MS explorer error

Post by softd »

msddcb wrote: Tue Sep 19, 2023 11:20 pm While I am not able to help with your problem I was interested in Scott's reply.
Firstly would you just replace the CMD with WINWORD.EXE ? (Presuming the windows path enables the program to be found)
And more interestingly if going the new http server option is this still accessing the document on the Windows server or would the documents be in the IFS. I am interested in this option and have not searched for how to as I was just reading this post but would like to read more on how to do this ?
I 've been using the IBM i web server a lot in the last years in order to share files from the IFS with the users. For instance, when a pdf doc is generated in the background, I use strpccmd to open the corresponding URL for the user. Earlier, when the command length was limited to 123 characters or so, I only passed parameters to an AD distributed dos batch file and the actual command was run there then.

If you wanted to share documents outside IFS and IBM i, let's say from windows server, you might be able to share them via QNTC... never needed or tried it, though.

I also share the web server logs as a browsable folder to the e-commerce team, so they won't always ask me about them :lol: , but this is not related to strpccmd.

Instead of using CMD or WINWORD.EXE I use another way now. Will reply to another post about this.

Regards Stefan
softd
Posts: 2
Joined: Tue Mar 19, 2024 7:28 pm

Re: STRPCCMD gives MS explorer error

Post by softd »

jand66 wrote: Wed Sep 20, 2023 2:17 pm
msddcb wrote: Tue Sep 19, 2023 11:20 pm While I am not able to help with your problem I was interested in Scott's reply.
Firstly would you just replace the CMD with WINWORD.EXE ? (Presuming the windows path enables the program to be found)
And more interestingly if going the new http server option is this still accessing the document on the Windows server or would the documents be in the IFS. I am interested in this option and have not searched for how to as I was just reading this post but would like to read more on how to do this ?
Just replacing 'CMD' by 'WINWORD.EXE' doesn't solve the problem. Then I still get the DOS window popup :( and MS Word doesn't open the document.
Instead of passing parameters to a dos batch file in the AppData-Roaming folder of the users' computers like this one:

Code: Select all

@echo off
start /max http://%~1/duns/%~2/%~3
rem start firefox -private-window "http://%~1/duns/%~2/%~3"
I recently started to use the following command

Code: Select all

strpccmd pccmd('rundll32 url,FileProtocolHandler http://my-url')

You may want to put "http://my-url" in double quotes if it could contain blanks and you haven't escaped them. This again runs the url with the default application for the protocol type, and... it works just the same with a word document

Code: Select all

strpccmd pccmd('rundll32 url,FileProtocolHandler "C:\any path\any doc.docx"')
It is obvious that this will only work on Windows, though. Unfortunately, running this on a Mac doesn't lead to a CPF message or so, otherwise I could simply monitor the message and in such case use the "open" command instead, as Scott suggested.
Post Reply