473,569 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_cmdshel l ""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 9883
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****@discuss ions.microsoft. com> wrote in message
news:A0******** *************** ***********@mic rosoft.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_cmdshel l ""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\A BC.bat", AppWinStyle.Max imizedFocus)

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.K AR > \\mynetworkmach ine\zebra234

where \\mynetworkmach ine\zebra234 has been provided network share..

I mean ...this works
type C:\abc\myfile.K AR > \\mynetworkmach ine\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****@discuss ions.microsoft. com> wrote in message
news:A0******** *************** ***********@mic rosoft.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_cmdshel l ""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****@discuss ions.microsoft. com> wrote in message
news:EB******** *************** ***********@mic rosoft.com...
No am not getting any error..In fact
this is the code

Dim aa As Integer
aa = Shell("C:\XYZ\A BC.bat", AppWinStyle.Max imizedFocus)

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.K AR > \\mynetworkmach ine\zebra234

where \\mynetworkmach ine\zebra234 has been provided network share..

I mean ...this works
type C:\abc\myfile.K AR > \\mynetworkmach ine\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****@discuss ions.microsoft. com> wrote in message
news:A0******** *************** ***********@mic rosoft.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_cmdshel l ""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.Sta rtupPath & "\Output.tx t"
'
' Get the System path.
'
Dim sysFolder As String =
System.Environm ent.GetFolderPa th(Environment. SpecialFolder.S ystem)
'
' Createe the command line.
'
myProcess.Start Info.FileName = "cmd.exe"
myProcess.Start Info.Arguments = "/C cd " & sysFolder & _
" && dir *.com >> " & Chr(34) & outfile & Chr(34) & " && exit"
'
' Start the process in a hidden window.
'
myProcess.Start Info.WindowStyl e = ProcessWindowSt yle.Hidden
myProcess.Start Info.CreateNoWi ndow = True
myProcess.Start ()
'
' Kill the process if it doesn't finish in one minute.
'
myProcess.WaitF orExit(1000)
If Not myProcess.HasEx ited Then
myProcess.Kill( )
End If
'
' Show the results.
'
MessageBox.Show ("The 'dir' command window was " & _
"closed at: " & myProcess.ExitT ime & "." &
System.Environm ent.NewLine & _
"Exit Code: " & myProcess.ExitC ode)

myProcess.Close ()

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

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

Dim myProcess As Process = New Process()
Dim s As String
Dim outfile As String = "\\cafe500\zebr a234"
'
' Get the System path.
'
Dim sysFolder As String =
System.Environm ent.GetFolderPa th(Environment. SpecialFolder.S ystem)
'
' Createe the command line.
'
myProcess.Start Info.FileName = "cmd.exe"
'myProcess.Star tInfo.Arguments = "/C cd " & sysFolder & " &&
dir *.com >> " & Chr(34) & outfile & Chr(34) & " && exit"
myProcess.Start Info.Arguments = "/C type C:\\239301U2.KA R >
\\xyz\zebra234"
'
' Start the process in a hidden window.
'
myProcess.Start Info.WindowStyl e = ProcessWindowSt yle.Hidden
myProcess.Start Info.CreateNoWi ndow = True
myProcess.Start ()
'
' Kill the process if it doesn't finish in one minute.
'
myProcess.WaitF orExit(1000)
If Not myProcess.HasEx ited Then
myProcess.Kill( )
End If
'
' Show the results.
'
Response.Write( "The 'dir' command window was " & _
"closed at: " & myProcess.ExitT ime & "." &
System.Environm ent.NewLine & _
"Exit Code: " & myProcess.ExitC ode)

myProcess.Close ()

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

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

Dim aa As Integer
aa = Shell("C:\XYZ\A BC.bat", AppWinStyle.Max imizedFocus)

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.K AR > \\mynetworkmach ine\zebra234

where \\mynetworkmach ine\zebra234 has been provided network share..

I mean ...this works
type C:\abc\myfile.K AR > \\mynetworkmach ine\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****@discuss ions.microsoft. com> wrote in message
news:A0******** *************** ***********@mic rosoft.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_cmdshel l ""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
10997
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 I do os.system() then sub-shell will setup A and execute my script there leaving A in parent shell untouched. Thanks,
0
296
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 ""type " & nwkfilepath & " > " & pPrinterName & " """
4
413
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 ""type " & nwkfilepath & " > " & pPrinterName & " """
7
2976
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? Thanks!
9
78258
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 script and export the result to a file. Any code snippet on this will be helpful.
6
8146
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 server mobile ce database. Until recently I was synching everything thru a com port serial cable. The devices would connect to the computer thru...
1
3544
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 it is too expensive. I want to use only one sub shell to execute all these commands and want to get each command's output. How can I accomplish this...
7
6214
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 this shell script using the Subprocess module. Here is my code: def resultFromRunning_(command):
1
5208
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 name of the database, and redirecting the tablespaces. The system is running DB2 Express C V9.5 and RHEL5 with latest updates The restore...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7968
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.