NET USE in batch files in EXEC Command
Posted by: attila (62.56.66.---)
Date: February 25, 2015 11:39AM

We have an application that uses the PHP EXEC command to spawn batch files that in turn run C-programs.
The reason for the nesting is that the batch files also do file copies, deletions, etc.

We have found that network drive mappings are sometimes not valid within these batch files, even though they are accessible outside the WAMP environment.

In the past, we have managed to get the drive mappings to work by embedding the NET USE commands within the batch files that the EXEC command runs. However, we have recently found that the NET USE command hangs when run within the batch file. (The NET USE command within the batch file has the appropriate password and user parameters.)

When we run the batch file outside of WAMP, everything works correctly. It only fails when invoked through WAMP. The machine with the problem is running Windows XP Service Pack 3.

Does anybody know what could be going wrong or how to fix it?

Options: ReplyQuote
Re: NET USE in batch files in EXEC Command
Posted by: RiggsFolly (---.as43234.net)
Date: February 25, 2015 12:20PM

Hi attila,

Remember that PHP runs as an Apache module, and Apache is started using the Local System Account.

I would say you need to find a way of getting those drives mapped for the System Account.

Here are a few suggestions I found looking around the web

[msdn.microsoft.com]

[superuser.com]

[stackoverflow.com]

[serverfault.com]

I hope some of these help, although at least one of these suggests that you shoudl not use the NET USE aproach.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: NET USE in batch files in EXEC Command
Posted by: attila (62.56.66.---)
Date: February 25, 2015 12:38PM

Many thanks for your suggestions.

I've been searching the web for similar issues with other users, and I'm coming to the same conclusion. I've also been playing around with moving commands between different batch files etc, to try to pin down exactly what is going wrong.

I haven't cracked it yet, but it "feels" like some sort of permissions problem.

As regards using NET USE, I'm afraid that we don't have much choice. The applications are accessing drives on several different servers and there are several other major applications in the mix. (The PHP stuff is really just a small add-on to a very large system.)

Thanks again..

Options: ReplyQuote
Re: NET USE in batch files in EXEC Command
Posted by: RiggsFolly (---.as43234.net)
Date: February 25, 2015 12:42PM

Have you looked at using UNC's instead of mapped drives?

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: NET USE in batch files in EXEC Command
Posted by: attila (---.demon.co.uk)
Date: February 26, 2015 12:16PM

RiggsFolly...

Thanks for the suggestion. Unfortunately, it won't solve my problem.

Once I've mapped the network drive, the system transfers to it, and then runs an application upon that drive. The application then opens/reads/creates/deletes/etc many different files on the network drive.

I still reckon that the problem is something to do with permissions, but I cannot find out how. The entire system works fine on another XP machine in the next room (using the exact same mapped drives on the exact same server). The only differences that I can find are:
1) the failing machine is a slightly different model of PC
2) the failing machine has a different user ID logged on. (The PC that does work has the same user ID as the server - i.e. the failing PC has a different user ID to the application server).

Apart from some device drivers, everything else is the same, right down to the exact same release of all the software (O/S, web-server, applications, etc.)

I can only conclude that it's something to do with having different user IDs logged onto the web server and the application server. That shouldn't matter with the user-ID and password included in the NET USE command, but somehow it does seem to matter.

That's why I reckon it's something to do with permissions, but if anybody has any better ideas, I'd be grateful to hear them.

Options: ReplyQuote
Re: NET USE in batch files in EXEC Command
Posted by: attila (---.demon.co.uk)
Date: February 26, 2015 01:19PM

I have cracked it!

The root of the problem was the "Log On As" under which WAMP was running.

To fix it, I ran services.msc and modified the WAMPAPACHE service to run under the PC's user ID instead of under "Local System Account".

Options: ReplyQuote
Re: NET USE in batch files in EXEC Command
Posted by: RiggsFolly (---.as43234.net)
Date: February 26, 2015 01:22PM

Would it not prove your theory, if you logged this problem PC into the network with that same userid/password as the PC that works?

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: NET USE in batch files in EXEC Command
Posted by: attila (62.56.66.---)
Date: February 26, 2015 02:27PM

RiggsFolly wrote "Would it not prove your theory, if you logged this problem PC into the network with that same userid/password as the PC that works?"

I tried it and it didn't work - bang goes that theory!

The solution that I posted at 13:19 is the only one that works so far.

After 3 days of pain, I'm now going to take a few days off!

Options: ReplyQuote


Sorry, only registered users may post in this forum.