473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Unable to execute Shell command in ASP.NET to print using DOS

Hi,

I have an ASP.NET application using VB.NET.I am sending a DOS command to a
machine on the network to print a file.
This is achieved using xp_cmdshell
Dim str As String = "xp_cmdshell ""type " & nwkfilepath & " > " &
pPrinterName & " """

and str is executed in the MSSQL Master database which has got permissions
to do it.
Problem Statement
******************
The same functionality could not be achieved using shell or diagnostics
namespace.The user ASP.NET has
already been given admin rights(as this is the user that executes an aspx
page)

Any help would be highly appreciated as this has snowballed into a major
production issue.
Regards

Kartik Ganesan
Jul 21 '05 #1
4 9858
I believe the xp_cmdshell is using the permissions of the user that the SQL
Server itself runs under.

Also, are you getting an error??

Jeff

"Kartik" <Ka****@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
Hi,

I have an ASP.NET application using VB.NET.I am sending a DOS command to a
machine on the network to print a file.
This is achieved using xp_cmdshell
Dim str As String = "xp_cmdshell ""type " & nwkfilepath & " > " &
pPrinterName & " """

and str is executed in the MSSQL Master database which has got permissions
to do it.
Problem Statement
******************
The same functionality could not be achieved using shell or diagnostics
namespace.The user ASP.NET has
already been given admin rights(as this is the user that executes an aspx
page)

Any help would be highly appreciated as this has snowballed into a major
production issue.
Regards

Kartik Ganesan

Jul 21 '05 #2
No am not getting any error..In fact
this is the code

Dim aa As Integer
aa = Shell("C:\XYZ\ABC.bat", AppWinStyle.MaximizedFocus)

and when i run in debug mode I get a value for aa..which is the process id.

ABC.bat contains the following lines

type C:\abc\myfile.KAR > \\mynetworkmachine\zebra234

where \\mynetworkmachine\zebra234 has been provided network share..

I mean ...this works
type C:\abc\myfile.KAR > \\mynetworkmachine\zebra234

when i execute this through dos.

Thanks in Anticipation

Kartik


"Jeff Dillon" wrote:
I believe the xp_cmdshell is using the permissions of the user that the SQL
Server itself runs under.

Also, are you getting an error??

Jeff

"Kartik" <Ka****@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
Hi,

I have an ASP.NET application using VB.NET.I am sending a DOS command to a
machine on the network to print a file.
This is achieved using xp_cmdshell
Dim str As String = "xp_cmdshell ""type " & nwkfilepath & " > " &
pPrinterName & " """

and str is executed in the MSSQL Master database which has got permissions
to do it.
Problem Statement
******************
The same functionality could not be achieved using shell or diagnostics
namespace.The user ASP.NET has
already been given admin rights(as this is the user that executes an aspx
page)

Any help would be highly appreciated as this has snowballed into a major
production issue.
Regards

Kartik Ganesan


Jul 21 '05 #3
Yes, a permissions issue most likely

Jeff
"kartik" <ka****@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
No am not getting any error..In fact
this is the code

Dim aa As Integer
aa = Shell("C:\XYZ\ABC.bat", AppWinStyle.MaximizedFocus)

and when i run in debug mode I get a value for aa..which is the process id.
ABC.bat contains the following lines

type C:\abc\myfile.KAR > \\mynetworkmachine\zebra234

where \\mynetworkmachine\zebra234 has been provided network share..

I mean ...this works
type C:\abc\myfile.KAR > \\mynetworkmachine\zebra234

when i execute this through dos.

Thanks in Anticipation

Kartik


"Jeff Dillon" wrote:
I believe the xp_cmdshell is using the permissions of the user that the SQL Server itself runs under.

Also, are you getting an error??

Jeff

"Kartik" <Ka****@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
Hi,

I have an ASP.NET application using VB.NET.I am sending a DOS command to a machine on the network to print a file.
This is achieved using xp_cmdshell
Dim str As String = "xp_cmdshell ""type " & nwkfilepath & " > " & pPrinterName & " """

and str is executed in the MSSQL Master database which has got permissions to do it.
Problem Statement
******************
The same functionality could not be achieved using shell or diagnostics namespace.The user ASP.NET has
already been given admin rights(as this is the user that executes an aspx page)

Any help would be highly appreciated as this has snowballed into a major production issue.
Regards

Kartik Ganesan


Jul 21 '05 #4
Actually no.I can execute file creations commands...more likely a
network issue.The following code from
http://www.thescarms.com/dotNet/Process.asp executes perfectly
fine.But when I execute my code it fails with exitcode = -1.

Sample Code from http://www.thescarms.com/dotNet/Process.asp
*****************************

Dim myProcess As Process = New Process()
Dim s As String
Dim outfile As String = Application.StartupPath & "\Output.txt"
'
' Get the System path.
'
Dim sysFolder As String =
System.Environment.GetFolderPath(Environment.Speci alFolder.System)
'
' Createe the command line.
'
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.Arguments = "/C cd " & sysFolder & _
" && dir *.com >> " & Chr(34) & outfile & Chr(34) & " && exit"
'
' Start the process in a hidden window.
'
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo.CreateNoWindow = True
myProcess.Start()
'
' Kill the process if it doesn't finish in one minute.
'
myProcess.WaitForExit(1000)
If Not myProcess.HasExited Then
myProcess.Kill()
End If
'
' Show the results.
'
MessageBox.Show("The 'dir' command window was " & _
"closed at: " & myProcess.ExitTime & "." &
System.Environment.NewLine & _
"Exit Code: " & myProcess.ExitCode)

myProcess.Close()

****************************

My Code
************************************************** *****************************

Dim myProcess As Process = New Process()
Dim s As String
Dim outfile As String = "\\cafe500\zebra234"
'
' Get the System path.
'
Dim sysFolder As String =
System.Environment.GetFolderPath(Environment.Speci alFolder.System)
'
' Createe the command line.
'
myProcess.StartInfo.FileName = "cmd.exe"
'myProcess.StartInfo.Arguments = "/C cd " & sysFolder & " &&
dir *.com >> " & Chr(34) & outfile & Chr(34) & " && exit"
myProcess.StartInfo.Arguments = "/C type C:\\239301U2.KAR >
\\xyz\zebra234"
'
' Start the process in a hidden window.
'
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo.CreateNoWindow = True
myProcess.Start()
'
' Kill the process if it doesn't finish in one minute.
'
myProcess.WaitForExit(1000)
If Not myProcess.HasExited Then
myProcess.Kill()
End If
'
' Show the results.
'
Response.Write("The 'dir' command window was " & _
"closed at: " & myProcess.ExitTime & "." &
System.Environment.NewLine & _
"Exit Code: " & myProcess.ExitCode)

myProcess.Close()

************************************************** *****************************
I donno why it fails ..any help would be highly appreciated.
Kartik
"Jeff Dillon" <je**@removeemergencyreporting.com> wrote in message news:<uO**************@TK2MSFTNGP10.phx.gbl>...
Yes, a permissions issue most likely

Jeff
"kartik" <ka****@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
No am not getting any error..In fact
this is the code

Dim aa As Integer
aa = Shell("C:\XYZ\ABC.bat", AppWinStyle.MaximizedFocus)

and when i run in debug mode I get a value for aa..which is the process

id.

ABC.bat contains the following lines

type C:\abc\myfile.KAR > \\mynetworkmachine\zebra234

where \\mynetworkmachine\zebra234 has been provided network share..

I mean ...this works
type C:\abc\myfile.KAR > \\mynetworkmachine\zebra234

when i execute this through dos.

Thanks in Anticipation

Kartik


"Jeff Dillon" wrote:
I believe the xp_cmdshell is using the permissions of the user that the SQL Server itself runs under.

Also, are you getting an error??

Jeff

"Kartik" <Ka****@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
> Hi,
>
> I have an ASP.NET application using VB.NET.I am sending a DOS command to a > machine on the network to print a file.
> This is achieved using xp_cmdshell
>
>
> Dim str As String = "xp_cmdshell ""type " & nwkfilepath & " > " & > pPrinterName & " """
>
> and str is executed in the MSSQL Master database which has got permissions > to do it.
>
>
> Problem Statement
> ******************
> The same functionality could not be achieved using shell or diagnostics > namespace.The user ASP.NET has
> already been given admin rights(as this is the user that executes an aspx > page)
>
>
>
> Any help would be highly appreciated as this has snowballed into a major > production issue.
>
>
> Regards
>
> Kartik Ganesan

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Valentine Kouznetsov | last post by:
Hi, simple question, how to execute command in current shell, not in subshell? Example. I have environment variable A=aaa and need to invoke shell (sh) script which will do something with A. If...
0
by: Kartik | last post by:
Hi, I have an ASP.NET application using VB.NET.I am sending a DOS command to a machine on the network to print a file. This is achieved using xp_cmdshell Dim str As String = "xp_cmdshell...
4
by: Kartik | last post by:
Hi, I have an ASP.NET application using VB.NET.I am sending a DOS command to a machine on the network to print a file. This is achieved using xp_cmdshell Dim str As String = "xp_cmdshell...
7
by: spec | last post by:
Hi all, I know nothing about Python. What I need to do is to get a Python script to execute a local shell script. I do not need any output. What would be th eeasiest way to accomplish this? ...
9
by: sohan | last post by:
Hi, I want to know how to connect and execute a db2 query from inside a UNIX shell script. Details: We have a unix shell script. We need to execute multiple db2 sql queries from this shell...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
1
by: raocheng | last post by:
Please see the following code. Suppose I have many shell commands to be executed. And I don't want to fork a sub shell for each command(eg: status,output = commands.getstatusoutput(cmd)) because...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
1
by: mlaris | last post by:
Howdy, We are experiencing a bizarre problem under Linux attempting to restore a DB2 database. The backup was created on this machine, and is being restored to the same machine, but changing the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.