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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permission Denied error in WshShell.Run()

Status
Not open for further replies.

pathOfNeo

Programmer
Nov 28, 2012
4
US
Hey guys,
I am new to this forum and working with VBScript and Java for last 8 months.

I am getting 'permission denied' message from WshShell.Run() while trying to execute the raw command but still I am getting return code 0. If I stored all those same instructions in a batch file and run that batch file using WshShell.Run(), my program is working fine and giving me expected output.

This left me in a confused state. Inside the batch file I'm trying to execute a Java class. If that invocation is successful then only I should get a RC 0 but why I am getting RC 0 inspite of 'permission denied' message.

My code is something like:
cmd=<contains all DLL/JAR path and executes a Java class>
rc = WshShell.Run(cmd, 0, true) ----this is giving me permission denied message

But if I changed it to:
var a = fso.CreateTextFile(GetPath() + "test.bat", true);
a.WriteLine(cmd);
a.Close();
rc = WshShell.Run(test.bat, 0, true) ----this one is running fine

My questions are:
why I am getting permission denied while executing the commands directly?
why I am getting RC 0 inspite of Java class execution failure?
is there any difference these two kind of invokes? I am running this code under domain user a/c NOT under local system a/c and that a/c has admin access to ALL resources.
 
The problem is almost certainly in the [tt]cmd[/tt] string (for that's the only part that can cause a permissions error). We cannot tell you what is wrong if you do not post the problematic code but I can say make sure the string is properly encapsulated in quotes and all special character are properly escaped.

-Geates

 
Geates,
I have double checked that. String is cool. Also if I run the whole string using command prompt it's working fine. It's throwing permission denied only while I try to execute the string from the application. I have also give that a/c admin access but no luck!
 
>String is cool

Actually, it may not be. The commandline and the .run method treat the string differently ...

For example, the .run method appears to have a limit of 2048 characters for strCommand - and this could be the root of your problem.

Note that the .exec method has fewer limitations, so you might want to investigate using that rather than .run
 
>the .run method appears to have a limit of 2048 characters for strCommand

I just wrote a quick Java code to find out the char number in my string and it is 2202. So, you are saying that could be the problem. Could you please point me to the docs which listed limitations of .run as well as .exec? That will be great.
 
>Could you please point me to the docs which listed limitations of .run as well as .exec?

Afraid not. Discovered through investigation.

You can try this little VBS script that demonstrates the point (actually slightly more than 2048, I misremembered):

Code:
[blue]Set WshShell = WScript.CreateObject("WScript.Shell")

strCMD="cmd /c echo " & string(2044,"x")
msgbox "Trying " & len(strCmd) & " characters"
wshshell.run strCmd ,0  , True
strCmd="cmd /c echo " & string(2045,"x")
msgbox "Trying " & len(strCmd) & " characters"
wshshell.run strCMD , 0 , True[/blue]
 
strongm^^^THANKS A LOT!
geates^^^no, it's not a binary string. It's the normal one with lots of JARs and individual classes. We are working to reduce this.

Another question-
When I passed the batch file name as strCmd it works fine. What is the difference between these two types of calls?



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top