It is currently 21 April 2025, 16:46 Advanced search

Permissions for Shell() Command

Questions and answers on how to best use Instant Developer

Permissions for Shell() Command

Postby ATroyer » 30 June 2021, 16:17

I am struggling to get the proper permissions to execute a Shell() command on an app installed to a local machine. I have a batch file in my custom directory that executes fine when I compile (f5):

Screenshot 2021-06-30 120049.jpg
Screenshot 2021-06-30 120049.jpg (37.81 KiB) Viewed 3941 times

However, when I publish to my local IIS and run the app, the command fails silently, even though I have embedded the same batch file in my app and web directory:

Screenshot 2021-06-30 120422.jpg
Screenshot 2021-06-30 120422.jpg (19.83 KiB) Viewed 3941 times

Note: the commented lines in the first screen shot show my earlier attempts, where I wrapped the actual command I was after into a batch file after several failures. I say failures, but all of these worked when I compiled, but not when I published.
I know the command itself works, because I can enter the same command (C:\inetpub\wwwroot\CatformsRecords\WebApp/RunRemark345.bat) at the command prompt on my computer and it runs fine.
It seems that it has to be a permissions issue, yet I have given the folders all the permissions they need, and it makes no difference.
The backslash/forward slash variations don't seem to make a difference either.

I followed this post: viewtopic.php?f=7&t=83524&hilit=shell+command to get to where I am now.
ATroyer
 
Posts: 55
Joined: 30 October 2019, 13:30

Re: Permissions for Shell() Command

Postby ljwilson » 30 June 2021, 21:41

Since IIS is actually launching the batch file, it will run it with the rights of the IIS AppPool user.

As a test you could set the App Pool to run with the administrator account, and if that works then work backwards from that.

Also, in the past sometimes I've had to launch a .bat or .cmd file using something like c:\windows\system32\cmd.exe /c batchfilename.bat

...jack
ljwilson
 
Posts: 783
Joined: 26 November 2013, 14:15

Re: Permissions for Shell() Command

Postby ATroyer » 1 July 2021, 13:51

I tried both suggestions, with no luck, including using my user name and password instead of the ApplicationPoolIdentity pictured below.

Screenshot 2021-07-01 093541.jpg
Screenshot 2021-07-01 093541.jpg (94.06 KiB) Viewed 3921 times

I am running it with http currently, so I get the message "not secure". When I tried using a localhost certificate to run https, both Firefox and Chrome gave me rats for using a self-signed certificate, and the bat file still wouldn't run.
Do I need to pursue getting a regular certificate, or will that not likely make a difference?
ATroyer
 
Posts: 55
Joined: 30 October 2019, 13:30

Re: Permissions for Shell() Command

Postby john w » 1 July 2021, 15:00

Regards

John W
User avatar
john w
 
Posts: 834
Joined: 24 October 2012, 16:29
Location: Apple Valley, Minnesota USA

Re: Permissions for Shell() Command

Postby ATroyer » 1 July 2021, 16:47

Thanks. Using that link as reference, I went back through all my settings for the web application, the app pool it is using, and the folder the app and batch file are located in, and everything checks, but no luck...

SInce this is failing silently, is there some place where iis keeps a log of what happens? The log files in the .../WebApp/logs folder only consist of strings of dates and times from what I can see.
ATroyer
 
Posts: 55
Joined: 30 October 2019, 13:30

Re: Permissions for Shell() Command

Postby john w » 1 July 2021, 16:53

If you have access there are event logs on the server. They often trap application errors. Sadly I never remember off the top of my head where they are located. I suspect Jack knows or you can it on the internet.
Regards

John W
User avatar
john w
 
Posts: 834
Joined: 24 October 2012, 16:29
Location: Apple Valley, Minnesota USA

Re: Permissions for Shell() Command

Postby john w » 1 July 2021, 16:54

A quick thought have you tried running the .bat file outside of the shell command on the server? Does it work?
Regards

John W
User avatar
john w
 
Posts: 834
Joined: 24 October 2012, 16:29
Location: Apple Valley, Minnesota USA

Re: Permissions for Shell() Command

Postby ljwilson » 1 July 2021, 17:54

Also, what does the batch file do? Have you tried a simple batch file to make sure it works? Maybe there is a command in it that isn't happy when not in an interactive shell.
...jack
ljwilson
 
Posts: 783
Joined: 26 November 2013, 14:15

Re: Permissions for Shell() Command

Postby ATroyer » 1 July 2021, 19:13

Bat file works fine outside the shell command. I can copy directly from debug and paste into PowerShell and it works. I modified the bat file to simply echo some text, and it still does not work.
ATroyer
 
Posts: 55
Joined: 30 October 2019, 13:30

Re: Permissions for Shell() Command

Postby ATroyer » 1 July 2021, 19:19

I figured out where to find the IIS logs. Unfortunately, there are no errors listed in the log. This helped me figure out where to look: https://stackoverflow.com/questions/642 ... e-iis-logs
ATroyer
 
Posts: 55
Joined: 30 October 2019, 13:30

Next

Return to Tips & Tricks

Who is online

Users browsing this forum: No registered users and 14 guests